From cb7ef2ec9e7ca1c4e26959584b62818cc836617c Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 8 Nov 2024 14:38:09 +1000 Subject: [PATCH] geom/segment: make intersects test not inclusive --- cruft/util/geom/segment.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cruft/util/geom/segment.cpp b/cruft/util/geom/segment.cpp index 3e000bd1..df1c288b 100644 --- a/cruft/util/geom/segment.cpp +++ b/cruft/util/geom/segment.cpp @@ -70,6 +70,7 @@ cruft::geom::intersects (cruft::geom::segment2i seg, cruft::region2i rect) /////////////////////////////////////////////////////////////////////////////// +// Not-inclusive template <> bool cruft::geom::intersects (cruft::geom::segment2f ab, cruft::point2f p) @@ -77,7 +78,7 @@ cruft::geom::intersects (cruft::geom::segment2f ab, cruft::point2f p) auto const hi = max (ab.a, ab.b); auto const lo = min (ab.a, ab.b); - return all (p <= hi) and all (p >= lo); + return all (p < hi) and all (p > lo); } @@ -112,6 +113,7 @@ winding ( //----------------------------------------------------------------------------- +// not inclusive template <> bool cruft::geom::intersects ( @@ -123,8 +125,10 @@ cruft::geom::intersects ( auto const w2 = winding (s1.a, s1.b, s0.a); auto const w3 = winding (s1.a, s1.b, s0.b); - if (w0 != w1 and w2 != w3) - return true; + // inclusive condition. zeroes are colinear, which is fine + if (w0 and w1 and w2 and w3) + if (w0 != w1 and w2 != w3) + return true; if (w0 == 0 and intersects (s0, s1.a)) return true; if (w1 == 0 and intersects (s0, s1.b)) return true;