Added a test to check in the point to face distance computation to manage the case of degenerated faces. Now correctly resort to distance point to segment.

This commit is contained in:
Paolo Cignoni 2010-03-03 00:35:20 +00:00
parent d340b8b92a
commit 5ef6d30d37
1 changed files with 21 additions and 6 deletions

View File

@ -62,6 +62,7 @@ created
#include <vcg/math/base.h>
#include <vcg/space/point3.h>
#include <vcg/space/segment3.h>
namespace vcg {
@ -310,9 +311,23 @@ namespace vcg {
#ifndef NDEBUG
static int staticCnt=0; // small piece of code that sometime check that face normals are really normalized
if((staticCnt++%100)==0)
assert(f.cN().SquaredNorm() > 0.9999 && f.cN().SquaredNorm()<1.0001); // if you get this assert you have forgot to make a UpdateNormals::PerFaceNormalized(m)
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<ScalarType>(0,0,0)) // to correctly manage the case of degenerate triangles we consider them as segments.
{
Box3<ScalarType> bb;
f.GetBBox(bb);
Segment3<ScalarType> degenTri(bb.min,bb.max);
Point3<ScalarType> closest= ClosestPoint( degenTri, q );
ScalarType d = Distance(closest, q);
if( d>dist || d<-dist ) // Risultato peggiore: niente di fatto
return false;
dist=d;
p=closest;
return true;
}
Plane3<ScalarType> fPlane;
fPlane.Init(f.cP(0),f.cN());
const ScalarType EPS = ScalarType( 0.000001);