mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-13 22:02:38 +00:00
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 <noreply@anthropic.com> Model-Effort: Opus 5.5 drove and fixed
This commit is contained in:
1 parent
89d8b50e9d
commit
d773ab2985
2 files changed
+7
-2
No files matched your search
@@ -139,6 +139,11 @@ fn count_at(n: &Node, q: Point) -> Option<f64> {
|
||||
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))
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in new issue
Block a user