From 44618a036aa390a7136f0cbc98f4bc9fbc21abc5 Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Thu, 20 May 2010 13:58:08 +0000 Subject: [PATCH] Added ClosestPoint2Box2 function --- vcg/space/box2.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/vcg/space/box2.h b/vcg/space/box2.h index 2c301521..6a3e94ed 100644 --- a/vcg/space/box2.h +++ b/vcg/space/box2.h @@ -55,6 +55,7 @@ Initial commit #include #include #include + namespace vcg { /** \addtogroup space */ @@ -304,6 +305,38 @@ ScalarType DistancePoint2Box2(const Point2 &test, } } +template +Point2 ClosestPoint2Box2(const Point2 &test, + const Box2 &bbox) +{ + Segment2 Segs[4]; + Segs[0].P0()=bbox.min; + Segs[0].P1()=vcg::Point2(bbox.max.X(),bbox.min.Y()); + + Segs[1].P0()=Segs[0].P(1); + Segs[1].P1()=bbox.max; + + Segs[2].P0()=Segs[1].P(1); + Segs[2].P1()=vcg::Point2(bbox.min.X(),bbox.max.Y()); + + Segs[3].P0()=Segs[2].P(1); + Segs[3].P1()=bbox.min; + + Point2 closest=ClosestPoint(Segs[0],test); + ScalarType minDist=(closest-test).Norm(); + for (int i=0;i<4;i++) + { + Point2 test=ClosestPoint(Segs[i],test); + ScalarType dist=(closest-test).Norm(); + if (dist Box2s; /// Specificazione di box of int