From b08fda7641af72f9c9ae2646525393eb0d61e77a Mon Sep 17 00:00:00 2001 From: cignoni Date: Mon, 2 Jul 2012 16:45:49 +0000 Subject: [PATCH] Corrected SegmentPointSquaredDistance to do not use anymore a hardcoded EPSilon value... --- vcg/space/distance3.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/vcg/space/distance3.h b/vcg/space/distance3.h index 0c9916cc..99ea2e85 100644 --- a/vcg/space/distance3.h +++ b/vcg/space/distance3.h @@ -222,22 +222,21 @@ void LineLineDistance(const vcg::Line3 &mLine0, * @param[in] sqr_dist The squared distance */ template -void SegmentPointSquaredDistance( Segment3 s, +void SegmentPointSquaredDistance( const Segment3 &s, const Point3 & p, Point3< ScalarType > &closest, ScalarType &sqr_dist) { Point3 e = s.P1()-s.P0(); - ScalarType EPS=0.00000001; - if (e.Norm()::min()) { - Point3 AvP=(s.P0()+s.P1())/2.0; - closest=AvP; - sqr_dist=(AvP-p).Norm(); + closest=s.MidPoint(); + sqr_dist=SquaredDistance(closest,p); } else { - ScalarType t = ((p-s.P0())*e)/e.SquaredNorm(); + ScalarType t = ((p-s.P0())*e)/eSquaredNorm; if(t<0) t = 0; else if(t>1) t = 1; closest = s.P0()+e*t;