From 8d4fa6883d81a0d92e98902a93ae6e6c76958690 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Fri, 27 Apr 2012 15:28:55 +0200 Subject: [PATCH] [Positioner] Point3D: add square_distance_2d() --- owlps-positioner/src/point3d.cc | 12 ++++++++++++ owlps-positioner/src/point3d.hh | 2 ++ 2 files changed, 14 insertions(+) diff --git a/owlps-positioner/src/point3d.cc b/owlps-positioner/src/point3d.cc index 256eb0e..db9110e 100644 --- a/owlps-positioner/src/point3d.cc +++ b/owlps-positioner/src/point3d.cc @@ -41,6 +41,18 @@ Point3D::Point3D(const string &source) /* *** Distance operations *** */ +/** + * The distance is not square rooted after the computation, in order + * to optimise comparisons. + */ +float Point3D::square_distance_2d(const Point3D &source) const +{ + return + (x - source.x) * (x - source.x) + + (y - source.y) * (y - source.y) ; +} + + /** * The distance is not square rooted after the computation, in order * to optimise comparisons. diff --git a/owlps-positioner/src/point3d.hh b/owlps-positioner/src/point3d.hh index a46d761..4972447 100644 --- a/owlps-positioner/src/point3d.hh +++ b/owlps-positioner/src/point3d.hh @@ -53,6 +53,8 @@ public: /** @name Distance & angles operations */ //@{ + /// Square euclidean distance to a Point3D, in 2D + float square_distance_2d(const Point3D &p) const ; /// Square euclidean distance to a Point3D float square_distance(const Point3D &p) const ; /// Euclidean distance to a Point3D