diff --git a/vcg/space/segment2.h b/vcg/space/segment2.h index c16c7f61..21305ab5 100644 --- a/vcg/space/segment2.h +++ b/vcg/space/segment2.h @@ -148,26 +148,16 @@ Point2 ClosestPoint( Segment2 s, const Point2 l; l.Set(s.P0(),s.P1()-s.P0()); - l.Normalize(); - Point2 clos=vcg::ClosestPoint(l,p) ;//attention to call - vcg::Box2 b; - b.Add(s.P0()); - b.Add(s.P1()); - if (b.IsIn(clos)) - return clos; + l = l.Normalize(); + ScalarType t = l.Projection(p); + Point2 clos = l.P(t); + int lenght = s.Length(); + if (t <= 0) + return s.P0(); + else if (t >= lenght) + return s.P1(); else - { - ScalarType d0=(s.P0()-p).Norm(); - ScalarType d1=(s.P1()-p).Norm(); - if (d01) return s.P0(); - return s.P(t);*/ + return clos; } /*@}*/