From c1f3a0f2e48f4dce2e2bdd8a8fe492b89b6a5ab8 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Thu, 15 Jun 2017 03:27:58 -0600 Subject: [PATCH] mathlib: ClosestPointOnLineSegment: handle degenerate line segment --- common/mathlib.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/mathlib.cc b/common/mathlib.cc index 24d26128..d70f0a05 100644 --- a/common/mathlib.cc +++ b/common/mathlib.cc @@ -762,9 +762,9 @@ float DistToLineSegment(const qvec3f &v, const qvec3f &w, const qvec3f& p) qvec3f ClosestPointOnLineSegment(const qvec3f &v, const qvec3f &w, const qvec3f& p) { const float frac = FractionOfLine(v, w, p); - if (frac > 1) + if (frac >= 1) return w; - if (frac < 0) + if (frac <= 0) return v; return ClosestPointOnLine(v, w, p);