mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 06:38:44 +00:00
Direct Selection: a re-mapped segment keeps a retracted handle exactly retracted
With Interpolate Control Points on, a retracted handle was mapped like any other and could land a rounding error away from its anchor. On a smooth anchor, lining the handles up then read that error as a direction and turned the other handle. A retracted handle now goes to its anchor's new place exactly.
This commit is contained in:
@@ -380,7 +380,10 @@ fn move_interpolating_handles(path: &mut PathData, set: &BTreeSet<AnchorRef>, 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));
|
||||
|
||||
@@ -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| {
|
||||
|
||||
Reference in New Issue
Block a user