From d773ab2985f1d98ff797494a9fcf7412b1210bc4 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Thu, 12 Nov 2026 11:42:22 -0500 Subject: [PATCH] M8: a pointer on the shape's centre gives the most points atan2 of two zeros reads as 180 degrees, so the centre gave 3; it now gives 60, and the test asserts that exactly. Co-Authored-By: Claude Opus 5.5 Model-Effort: Opus 5.5 drove and fixed --- crates/engine/src/canvas/shape_handles.rs | 5 +++++ crates/engine/src/shape_handles_tests.rs | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/canvas/shape_handles.rs b/crates/engine/src/canvas/shape_handles.rs index 726f7d011..b286010ba 100644 --- a/crates/engine/src/canvas/shape_handles.rs +++ b/crates/engine/src/canvas/shape_handles.rs @@ -139,6 +139,11 @@ fn count_at(n: &Node, q: Point) -> Option { return None; } let (x, y) = (q.x / rx - 1.0, q.y / ry - 1.0); + // On the centre there is no direction (atan2 of two zeros would read as 180 degrees): treat it + // as no angle, the most points. + if x.hypot(y) < 1e-9 { + return Some(COUNT_MAX); + } let angle = x.atan2(-y).rem_euclid(std::f64::consts::TAU).to_degrees(); let count = (360.0 / angle.max(1e-9)).round(); count.is_finite().then(|| count.clamp(COUNT_MIN, COUNT_MAX)) diff --git a/crates/engine/src/shape_handles_tests.rs b/crates/engine/src/shape_handles_tests.rs index 65220d7a7..0e3a2f211 100644 --- a/crates/engine/src/shape_handles_tests.rs +++ b/crates/engine/src/shape_handles_tests.rs @@ -160,10 +160,10 @@ fn dragging_the_count_handle_sets_the_count_by_the_angle_about_the_centre() { // The readout is the count. let doc = s.doc().unwrap(); assert_eq!(crate::shape_handles::value(doc, poly, ShapeHandle::Count), Some(4.0)); - // The finite guard: a pointer on the centre gives a finite count. + // A pointer on the centre has no direction: it gives the most points. let h = count_handle(&s, poly); drag(&mut s, (h[0], h[1]), (100.0, 100.0), false); - assert!((3..=60).contains(&count_of(&s, poly))); + assert_eq!(count_of(&s, poly), 60, "a pointer on the centre"); } #[test]