From ce72a2ba4b9384d7ec01d286df085d76828a6c15 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Sun, 15 Oct 2023 01:13:33 +0000 Subject: [PATCH] shape: Fix bend-seg intersection By making zero-length bends non-intersectable. --- src/math.rs | 8 +++++--- src/shape.rs | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/math.rs b/src/math.rs index 718bddb..2a5cbfe 100644 --- a/src/math.rs +++ b/src/math.rs @@ -194,10 +194,12 @@ pub fn intersect_circle_segment(circle: &Circle, segment: &Line) -> Vec { pub fn between_vectors(p: Point, from: Point, to: Point) -> bool { let cross = cross_product(from, to); - if cross >= 0. { - cross_product(from, p) >= 0. && cross_product(p, to) >= 0. + if cross > 0.0 { + cross_product(from, p) >= 0.0 && cross_product(p, to) >= 0.0 + } else if cross < 0.0 { + cross_product(from, p) >= 0.0 || cross_product(p, to) >= 0.0 } else { - cross_product(from, p) >= 0. || cross_product(p, to) >= 0. + false } } diff --git a/src/shape.rs b/src/shape.rs index 313889e..2982cdf 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -136,7 +136,7 @@ impl Shape { Shape::Dot(..) => unreachable!(), Shape::Seg(other) => seg.polygon().intersects(&other.polygon()), Shape::Bend(other) => { - /*for segment in seg.polygon().exterior().lines() { + for segment in seg.polygon().exterior().lines() { let inner_circle = other.inner_circle(); let outer_circle = other.outer_circle(); @@ -151,7 +151,7 @@ impl Shape { return true; } } - }*/ + } false }