From fb40a0f78aff0d34f00def4db25d35cda2b3f548 Mon Sep 17 00:00:00 2001 From: Luigi Malomo Date: Fri, 16 Oct 2020 13:23:41 +0200 Subject: [PATCH] fixed const correctness and added point-segment distance on Segment2 --- vcg/space/segment2.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vcg/space/segment2.h b/vcg/space/segment2.h index 05e92056..4f1407ce 100644 --- a/vcg/space/segment2.h +++ b/vcg/space/segment2.h @@ -142,7 +142,7 @@ typedef Segment2 Segment2f; typedef Segment2 Segment2d; template -Point2 ClosestPoint( Segment2 s, const Point2 & p) +Point2 ClosestPoint(const Segment2 & s, const Point2 & p) { vcg::Line2 l; l.Set(s.P0(),s.P1()-s.P0()); @@ -157,6 +157,12 @@ Point2 ClosestPoint( Segment2 s, const Point2 +ScalarType Distance(const Segment2 & s, const Point2 & p) { + const Point2 c = ClosestPoint(s, p); + return (c - p).Norm(); +} + template class PointSegment2DEPFunctor { public: