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]