Add distance2 for point

This commit is contained in:
Danny Robson 2012-05-03 18:12:12 +10:00
parent 2ef2554316
commit 6d879a96de
2 changed files with 10 additions and 3 deletions

View File

@ -29,9 +29,15 @@ using namespace util;
double
point::distance (const point &other) const {
return sqrt ((x - other.x) * (x - other.x) +
(y - other.y) * (y - other.y) +
(z - other.z) * (z - other.z));
return sqrt (distance2 (other));
}
double
point::distance2 (const point &other) const {
return (x - other.x) * (x - other.x) +
(y - other.y) * (y - other.y) +
(z - other.z) * (z - other.z);
}

View File

@ -30,6 +30,7 @@ namespace util {
double x, y, z;
double distance (const point &) const;
double distance2 (const point &) const;
double manhattan (const point &) const;
point& operator*= (double);