Width Point Edit: either half finds its pair as the engine pairs it

The dialog paired the points within 1e-6 of the opened point, so with
three points each that close to the next it paired the opened point
with a different neighbor than stroke.widthPoint.set accepts, and OK
failed. It now pairs a point with the next one when they are the only
points within 1e-6 of the first one's place, as the engine does, so
either half opens the same pair.
This commit is contained in:
dotCooCoo
2026-11-17 16:33:11 -08:00
parent 70e10dd553
commit f2f33b3a32
2 changed files with 40 additions and 6 deletions
+10 -6
View File
@@ -45,14 +45,18 @@ fn point(app: &VectorcraftApp, id: u64, index: usize) -> Option<(f64, f64, f64)>
}
/// The incoming and outgoing halves of the discontinuous point that width point `index` of `id`
/// belongs to, or none when no other point shares its place (or more than one does).
/// belongs to, or none when it is a continuous point. As `stroke.widthPoint.set` pairs them, a
/// point `a` and the next one are the two halves when they are the only points within
/// [`SAME_T`] of `a`'s place, so either half finds the same pair.
fn halves(app: &VectorcraftApp, id: u64, index: usize) -> Option<(usize, usize)> {
let points = &app.session.active()?.doc.node(NodeId(id))?.appearance.stroke()?.profile.as_ref()?.points;
let t = points.get(index)?.0;
match (0..points.len()).filter(|i| (points[*i].0 - t).abs() <= SAME_T).collect::<Vec<_>>()[..] {
[a, b] => Some((a, b)),
_ => None,
}
points.get(index)?;
let pair = |a: usize| {
let t = points.get(a)?.0;
let at: Vec<usize> = (0..points.len()).filter(|i| (points[*i].0 - t).abs() <= SAME_T).collect();
(at == [a, a + 1]).then_some((a, a + 1))
};
pair(index).or_else(|| index.checked_sub(1).and_then(pair))
}
/// Open Width Point Edit for `index`, or a prospective point at fraction `t` without an index
@@ -445,6 +445,36 @@ fn either_half_of_a_discontinuous_point_shows_both_sets_of_side_widths() {
assert_eq!(shown.iter().filter(|t| *t == "Side 1:").count(), 1);
}
/// Three width points each within 1e-6 of the next, but the outer two farther apart: the halves
/// are paired as `stroke.widthPoint.set` pairs them, from the incoming half's place, whichever
/// of them is opened. The first two make one discontinuous point, and the third stays a
/// continuous point.
#[test]
fn points_in_a_chain_pair_as_the_engine_pairs_them() {
let chain = json!([[0, 1, 1], [0.5, 0.8, 0.8], [0.50000075, 0.4, 1.2], [0.5000015, 0.6, 0.6], [1, 1, 1]]);
for index in [1, 2] {
let (mut app, id) = app();
app.run("stroke.widthProfile.set", json!({"ids": [id], "points": chain})).unwrap();
app.run("ui.widthPointEdit", json!({"id": id, "index": index})).unwrap();
let d = app.ui.dialog.as_mut().unwrap();
assert_eq!((d.fields["index"].clone(), d.fields["outIndex"].clone()), (json!(1), json!(2)), "opened {index}");
d.fields.insert("outSide1".into(), json!(1));
super::super::confirm(&mut app).unwrap();
assert!(app.ui.dialog.is_none(), "opened {index}");
assert_eq!(points(&app, id)[2], (0.50000075, 0.2, 1.2), "opened {index}");
}
let (mut app, id) = app();
app.run("stroke.widthProfile.set", json!({"ids": [id], "points": chain})).unwrap();
app.run("ui.widthPointEdit", json!({"id": id, "index": 3})).unwrap();
let d = app.ui.dialog.as_mut().unwrap();
assert_eq!(d.fields["index"], json!(3));
assert!(d.fields.get("outIndex").is_none());
d.fields.insert("side1".into(), json!(1));
super::super::confirm(&mut app).unwrap();
assert!(app.ui.dialog.is_none());
assert_eq!(points(&app, id)[3], (0.5000015, 0.2, 0.6));
}
#[test]
fn ok_sets_both_halves_of_a_discontinuous_point_in_one_step() {
let (mut app, id) = pair_app();