Normalise negative zero in Measure tool angle

Found while testing crates/tools/src/xform/measure.rs:20 (shown at :66, reported at :80)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-21 15:20:12 +07:00
committed by bflatastic
co-authored by Claude Haiku 5.5
parent 781d68a971
commit 89c1448777
+18 -1
View File
@@ -17,7 +17,7 @@ pub struct MeasureTool {
/// (distance, angle in degrees counter-clockwise, dx, dy)
pub fn measure(a: Point, b: Point) -> (f64, f64, f64, f64) {
let d = b - a;
(d.hypot(), (-d.y).atan2(d.x).to_degrees(), d.x, d.y)
(d.hypot(), (-d.y).atan2(d.x).to_degrees() + 0.0, d.x, d.y)
}
impl Tool for MeasureTool {
@@ -90,6 +90,23 @@ mod tests {
use crate::testutil::*;
use vectorcraft_doc::Selection;
#[test]
fn horizontal_drag_reports_positive_zero_angle() {
let (d, _) = doc_with_rect();
let s = Selection::default();
let p = paint();
let mut cx = cx(&d, &s, &p);
cx.smart_guides = false;
let mut t = MeasureTool::default();
t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 10.0, 10.0));
t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 40.0, 10.0));
t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 40.0, 10.0));
let ang = t.options()["angle"].as_f64().unwrap();
assert!(ang == 0.0 && ang.is_sign_positive(), "angle was {ang:?}");
let ov = t.overlays(&cx);
assert!(matches!(&ov[1], Overlay::Measure { text, .. } if text.contains("Angle: 0.0°")));
}
#[test]
fn drag_reports_distance_and_angle() {
let (d, _) = doc_with_rect();