correct 1 error on DistancePoint3Box3 (if the point is inside the box return distance to the nearest face instead of zero)

This commit is contained in:
Nico Pietroni 2008-03-05 11:48:08 +00:00
parent 94cb8fca1d
commit 8feedff976
1 changed files with 10 additions and 2 deletions

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.18 2008/02/03 23:50:51 cignoni
Important Change. Now adding a null bbox to a bbox leave it unchanged (instead of trashing it)
Revision 1.17 2007/07/12 06:41:24 cignoni Revision 1.17 2007/07/12 06:41:24 cignoni
added a missing static to the Construct() member added a missing static to the Construct() member
@ -375,9 +378,14 @@ template <class ScalarType>
ScalarType DistancePoint3Box3(const Point3<ScalarType> &test, ScalarType DistancePoint3Box3(const Point3<ScalarType> &test,
const Box3<ScalarType> &bbox) const Box3<ScalarType> &bbox)
{ {
///if fall inside return zero ///if fall inside return distance to a face
if (bbox.IsIn(test)) if (bbox.IsIn(test))
return 0; {
ScalarType dx=std::min<ScalarType>(bbox.max.X()-test.X(),test.X()-bbox.min.X());
ScalarType dy=std::min<ScalarType>(bbox.max.Y()-test.Y(),test.Y()-bbox.min.Y());
ScalarType dz=std::min<ScalarType>(bbox.max.Z()-test.Z(),test.Z()-bbox.min.Z());
return std::min<ScalarType>(dx,std::min<ScalarType>(dy,dz));
}
///find the right quandrant ///find the right quandrant
bool XM=(test.X()>=bbox.max.X()); bool XM=(test.X()>=bbox.max.X());