From 8d10b55cc54caa2b231c7891ba3f1de6d9db7b80 Mon Sep 17 00:00:00 2001 From: Niklaus Johner <nij2003@med.cornell.edu> Date: Tue, 13 Mar 2012 13:42:19 -0400 Subject: [PATCH] Added export for geom::MinDistance and optimized its speed a little --- modules/geom/pymod/export_vecmat3_op.cc | 1 + modules/geom/src/vecmat3_op.cc | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/geom/pymod/export_vecmat3_op.cc b/modules/geom/pymod/export_vecmat3_op.cc index 048cdd170..75787dd53 100644 --- a/modules/geom/pymod/export_vecmat3_op.cc +++ b/modules/geom/pymod/export_vecmat3_op.cc @@ -64,4 +64,5 @@ void export_VecMat3_op() def("OrthogonalVector",OrthogonalVector); def("Min",Vec3Min); def("Max",Vec3Max); + def("MinDistance",MinDistance); } diff --git a/modules/geom/src/vecmat3_op.cc b/modules/geom/src/vecmat3_op.cc index 0ce26dde3..8dd8eb11b 100644 --- a/modules/geom/src/vecmat3_op.cc +++ b/modules/geom/src/vecmat3_op.cc @@ -196,15 +196,15 @@ Real MinDistance(const Vec3List& l1, const Vec3List& l2) { // returns the minimal distance between two sets of points (Vec3List) if (l1.size()==0 || l2.size()==0){throw std::runtime_error("cannot calculate minimal distance: empty Vec3List");} - Real min=Distance(*l1.begin(),*l2.begin()); + Real min=Length2(*l1.begin()-*l2.begin()); Real d; for (Vec3List::const_iterator p1=l1.begin(),e1=l1.end(); p1!=e1; p1++) { for (Vec3List::const_iterator p2=l2.begin(),e2=l2.end(); p2!=e2; p2++) { - d=Distance(*p1,*p2); + d=Length2(*p1-*p2); if (d<min) min=d; } } - return min; + return std::sqrt(min); } } // ns -- GitLab