geom/segment: make intersects test not inclusive

This commit is contained in:
Danny Robson 2024-11-08 14:38:09 +10:00
parent 16729c6f8b
commit cb7ef2ec9e

View File

@ -70,6 +70,7 @@ cruft::geom::intersects (cruft::geom::segment2i seg, cruft::region2i rect)
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Not-inclusive
template <> template <>
bool bool
cruft::geom::intersects (cruft::geom::segment2f ab, cruft::point2f p) 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 hi = max (ab.a, ab.b);
auto const lo = min (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 <> template <>
bool bool
cruft::geom::intersects ( cruft::geom::intersects (
@ -123,6 +125,8 @@ cruft::geom::intersects (
auto const w2 = winding (s1.a, s1.b, s0.a); auto const w2 = winding (s1.a, s1.b, s0.a);
auto const w3 = winding (s1.a, s1.b, s0.b); auto const w3 = winding (s1.a, s1.b, s0.b);
// inclusive condition. zeroes are colinear, which is fine
if (w0 and w1 and w2 and w3)
if (w0 != w1 and w2 != w3) if (w0 != w1 and w2 != w3)
return true; return true;