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 <>
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;