From a7d6086994fda76f6fb5bf6e6a9552277b4ee9e5 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Wed, 24 Jun 2015 19:42:51 +0200 Subject: [PATCH] [MaL] Inline sqrDist(double*,...). This improves GeoLib::SearchNearestPoints() by factor >1.4. --- MathLib/MathTools.cpp | 6 ------ MathLib/MathTools.h | 7 ++++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/MathLib/MathTools.cpp b/MathLib/MathTools.cpp index 236ceea0810..51ff3bb9fde 100644 --- a/MathLib/MathTools.cpp +++ b/MathLib/MathTools.cpp @@ -42,12 +42,6 @@ double calcProjPntToLineAndDists(const double p[3], const double a[3], return sqrt (sqrDist (p, proj_pnt)); } -double sqrDist(const double* p0, const double* p1) -{ - const double v[3] = {p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]}; - return scalarProduct<double,3>(v,v); -} - double getAngle (const double p0[3], const double p1[3], const double p2[3]) { const double v0[3] = {p0[0]-p1[0], p0[1]-p1[1], p0[2]-p1[2]}; diff --git a/MathLib/MathTools.h b/MathLib/MathTools.h index 424745dacb0..f037e46526a 100644 --- a/MathLib/MathTools.h +++ b/MathLib/MathTools.h @@ -122,7 +122,12 @@ bool operator==(TemplatePoint<T,DIM> const& a, TemplatePoint<T,DIM> const& b) } /** squared dist between double arrays p0 and p1 (size of arrays is 3) */ -double sqrDist(const double* p0, const double* p1); +inline +double sqrDist(const double* p0, const double* p1) +{ + const double v[3] = {p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]}; + return scalarProduct<double,3>(v,v); +} /** Distance between points p0 and p1 in the maximum norm. */ template <typename T> -- GitLab