From 6d879a96de5ea32e0f5608e476d578f8cd3f32c7 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 3 May 2012 18:12:12 +1000 Subject: [PATCH] Add distance2 for point --- point.cpp | 12 +++++++++--- point.hpp | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) 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);