diff --git a/crates/engine/src/cmd/path.rs b/crates/engine/src/cmd/path.rs index 7f178f9ca0..aede871fb2 100644 --- a/crates/engine/src/cmd/path.rs +++ b/crates/engine/src/cmd/path.rs @@ -380,7 +380,10 @@ fn move_interpolating_handles(path: &mut PathData, set: &BTreeSet, d: let v = h - a.p; start + Vec2::new(v.x * re - v.y * im, v.x * im + v.y * re) }; - let (h_out, h_in) = (map(a.h_out), map(b.h_in)); + // A retracted handle goes to its anchor's new place exactly: mapped, it could land a + // rounding error away, which `line_up_handles` would read as a direction. + let h_out = if a.h_out == a.p { start } else { map(a.h_out) }; + let h_in = if b.h_in == b.p { end } else { map(b.h_in) }; if h_out.is_finite() && h_in.is_finite() { placed.push((si, from, true, h_out)); placed.push((si, to, false, h_in)); diff --git a/crates/engine/src/tests/interpolate_handles.rs b/crates/engine/src/tests/interpolate_handles.rs index e332f2c8ee..158eb6a5fb 100644 --- a/crates/engine/src/tests/interpolate_handles.rs +++ b/crates/engine/src/tests/interpolate_handles.rs @@ -418,6 +418,29 @@ fn a_smooth_anchor_keeps_its_handles_in_line() { assert!((300.0 - b.h_in.x - 25.0 * 5f64.sqrt()).abs() < 1e-9, "{:?}", b.h_in); } +#[test] +fn a_moved_smooth_anchor_keeps_a_retracted_handle_exactly_retracted() { + let mut s = session(); + interpolate(&mut s, true); + let id = create( + &mut s, + json!([ + {"x": 0, "y": 100, "out": [50, 100]}, + {"x": 200, "y": 100, "in": [200, 100], "out": [250, 150], "smooth": true}, + {"x": 400, "y": 100, "in": [350, 100]}, + ]), + ); + select(&mut s, id, json!([[0, 1]])); + s.execute("object.nudge", &json!({"dx": 20, "dy": 8.1})).unwrap(); + let b = anchor(&s, id, 1); + assert_eq!(b.p, Point::new(220.0, 108.1)); + // Re-mapping the retracted handle by its segment's map would leave it a rounding error away + // from the anchor, and lining the handles up would then turn the outgoing one by that error. + assert_eq!(b.h_in, b.p, "the retracted handle stays retracted"); + // The chord to the third anchor goes from (200, 0) to (180, -8.1). + close(b.h_out, Point::new(267.025, 151.075)); +} + #[test] fn transform_again_repeats_a_move_with_the_handles_re_mapped() { let twice = |again: bool| {