From 9cbf2c1c3cc0e0a5cbb7b09a8df48e414510cf9d Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Mon, 8 Jan 2007 09:26:33 +0000 Subject: [PATCH] - added easpilon test on convex function. - renamed Intersection function with IsInsideTrianglePoint and optimized using bouding boxes --- vcg/space/intersection2.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/vcg/space/intersection2.h b/vcg/space/intersection2.h index 62103087..c741fbed 100644 --- a/vcg/space/intersection2.h +++ b/vcg/space/intersection2.h @@ -49,7 +49,8 @@ namespace vcg { template inline bool Convex(const Point2 & p0,const Point2 & p1,const Point2 & p2) { - return (((p0-p1)^(p2-p1))<=0); + const SCALAR_TYPE EPSILON= SCALAR_TYPE(1e-8); + return (((p0-p1)^(p2-p1))<=EPSILON); } ///return if exist the intersection point @@ -113,11 +114,21 @@ inline bool LineSegmentIntersection(const vcg::Line2 & line, /// interseciton between point and triangle template - inline bool Intersection( const Triangle2 & t,const Point2 & p) + inline bool IsInsideTrianglePoint( const Triangle2 & t,const Point2 & p) { Point2 p0=t.P0(0); Point2 p1=t.P0(1); Point2 p2=t.P0(2); + + ///first test with bounding box + vcg::Box2 b2d; + b2d.Add(p0); + b2d.Add(p1); + b2d.Add(p2); + if (!b2d.IsIn(p)) + return false; + + ///then text convex if (!Convex(p0,p1,p2)) std::swap >(p1,p2); return((Convex(p,p0,p1))&&(Convex(p,p1,p2))&&(Convex(p,p2,p0)));