From f58551601a7835746ba40bfdbac0b6cf91f528cc Mon Sep 17 00:00:00 2001 From: cignoni Date: Wed, 14 Mar 2012 15:59:42 +0000 Subject: [PATCH] CHANGE to the VERY USED PointDistanceBase, the basic functor used to find the closest point to a face in all the grids. It has a bug that could return a nan in some degnerate case where an almost null face has different vertices but the squared distance between them could be zero. Now it should handle also these cases. --- vcg/simplex/face/distance.h | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/vcg/simplex/face/distance.h b/vcg/simplex/face/distance.h index e49cac8b..a3480580 100644 --- a/vcg/simplex/face/distance.h +++ b/vcg/simplex/face/distance.h @@ -319,22 +319,26 @@ namespace vcg { assert((f.cN().SquaredNorm() ==0) || (f.cN().SquaredNorm() > 0.9999 && f.cN().SquaredNorm()<1.0001)); // if you get this assert you have forgot to make a UpdateNormals::PerFaceNormalized(m) #endif - if(f.cN()==Point3(0,0,0)) // to correctly manage the case of degenerate triangles we consider them as segments. - { - Box3 bb; - f.GetBBox(bb); - Segment3 degenTri(bb.min,bb.max); - //Point3 closest= ClosestPoint( degenTri, q ); - //ScalarType d = Distance(closest, q); - Point3 closest; - ScalarType d; - vcg::SegmentPointDistance(degenTri,q,closest,d); - if( d>dist || d<-dist ) // Risultato peggiore: niente di fatto - return false; - dist=d; - p=closest; - return true; - } + if(f.cN()==Point3(0,0,0)) // to correctly manage the case of degenerate triangles we consider them as segments. + { + Box3 bb; + f.GetBBox(bb); + Segment3 degenTri(bb.min,bb.max); + Point3 closest; + ScalarType d; + if(bb.Diag()>0) + vcg::SegmentPointDistance(degenTri,q,closest,d); + else // very degenerate triangle (just a point) + { + closest = bb.min; + d=Distance(q,closest); + } + if( d>dist) return false; + dist=d; + p=closest; + assert(!math::IsNAN(dist)); + return true; + } Plane3 fPlane; fPlane.Init(f.cP(0),f.cN());