fixed const correctness and added point-segment distance on Segment2

This commit is contained in:
Luigi Malomo 2020-10-16 13:23:41 +02:00
parent dd8c26474d
commit fb40a0f78a
1 changed files with 7 additions and 1 deletions

View File

@ -142,7 +142,7 @@ typedef Segment2<float> Segment2f;
typedef Segment2<double> Segment2d;
template <class ScalarType>
Point2<ScalarType> ClosestPoint( Segment2<ScalarType> s, const Point2<ScalarType> & p)
Point2<ScalarType> ClosestPoint(const Segment2<ScalarType> & s, const Point2<ScalarType> & p)
{
vcg::Line2<ScalarType, true> l;
l.Set(s.P0(),s.P1()-s.P0());
@ -157,6 +157,12 @@ Point2<ScalarType> ClosestPoint( Segment2<ScalarType> s, const Point2<ScalarType
return clos;
}
template <class ScalarType>
ScalarType Distance(const Segment2<ScalarType> & s, const Point2<ScalarType> & p) {
const Point2<ScalarType> c = ClosestPoint(s, p);
return (c - p).Norm();
}
template <class S>
class PointSegment2DEPFunctor {
public: