diff --git a/point.cpp b/point.cpp index 5f6b0a9b..86ada6f5 100644 --- a/point.cpp +++ b/point.cpp @@ -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); } diff --git a/point.hpp b/point.hpp index f888b79c..f919c7f7 100644 --- a/point.hpp +++ b/point.hpp @@ -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);