Bug fixed in the ClosestPoint2Box2 function
This commit is contained in:
parent
e90c417d2b
commit
e3d8489f0f
|
@ -321,31 +321,31 @@ ScalarType DistancePoint2Box2(const Point2<ScalarType> &test,
|
||||||
|
|
||||||
template <class ScalarType>
|
template <class ScalarType>
|
||||||
Point2<ScalarType> ClosestPoint2Box2(const Point2<ScalarType> &test,
|
Point2<ScalarType> ClosestPoint2Box2(const Point2<ScalarType> &test,
|
||||||
const Box2<ScalarType> &bbox)
|
const Box2<ScalarType> &bbox)
|
||||||
{
|
{
|
||||||
Segment2<ScalarType> Segs[4];
|
Segment2<ScalarType> Segs[4];
|
||||||
Segs[0].P0()=bbox.min;
|
Segs[0].P0() = bbox.min;
|
||||||
Segs[0].P1()=vcg::Point2<ScalarType>(bbox.max.X(),bbox.min.Y());
|
Segs[0].P1() = vcg::Point2<ScalarType>(bbox.max.X(), bbox.min.Y());
|
||||||
|
|
||||||
Segs[1].P0()=Segs[0].P(1);
|
Segs[1].P0() = Segs[0].P(1);
|
||||||
Segs[1].P1()=bbox.max;
|
Segs[1].P1() = bbox.max;
|
||||||
|
|
||||||
Segs[2].P0()=Segs[1].P(1);
|
Segs[2].P0() = Segs[1].P(1);
|
||||||
Segs[2].P1()=vcg::Point2<ScalarType>(bbox.min.X(),bbox.max.Y());
|
Segs[2].P1() = vcg::Point2<ScalarType>(bbox.min.X(), bbox.max.Y());
|
||||||
|
|
||||||
Segs[3].P0()=Segs[2].P(1);
|
Segs[3].P0() = Segs[2].P(1);
|
||||||
Segs[3].P1()=bbox.min;
|
Segs[3].P1() = bbox.min;
|
||||||
|
|
||||||
Point2<ScalarType> closest=ClosestPoint(Segs[0],test);
|
Point2<ScalarType> closest = ClosestPoint(Segs[0], test);
|
||||||
ScalarType minDist=(closest-test).Norm();
|
ScalarType minDist = (closest-test).Norm();
|
||||||
for (int i=0;i<4;i++)
|
for (int i = 1; i < 4; i++)
|
||||||
{
|
{
|
||||||
Point2<ScalarType> test=ClosestPoint(Segs[i],test);
|
Point2<ScalarType> point = ClosestPoint(Segs[i], test);
|
||||||
ScalarType dist=(closest-test).Norm();
|
ScalarType dist = (test - point).Norm();
|
||||||
if (dist<minDist)
|
if (dist < minDist)
|
||||||
{
|
{
|
||||||
minDist=dist;
|
minDist = dist;
|
||||||
closest=test;
|
closest = point;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return closest;
|
return closest;
|
||||||
|
|
Loading…
Reference in New Issue