Match Objects: refuse restacks into locked, blend or Live Paint containers; keep turned live-effect art's reference point

A stacking match is now refused when the source's layer or group is
locked, when the Layers panel would not take a target beside the source
(among a blend's inputs, for example), or when it would move art into,
out of or within a Live Paint group.

A rotation match on an object with a live effect that moves it (a
Transform effect's offset) puts the measured reference point back where
it was after the turn, and is refused, with no undo step, when the
object cannot keep both its size and that point once pixel snapping has
run.

Builds on #10072.
This commit is contained in:
dotCooCoo committed 2026-11-29 21:32:17 -08:00
1 parent 4f95a30c98
commit c7e4a43c1a
4 files changed
+221 -3

No files matched your search

+55 -1
View File
@@ -95,7 +95,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Match Objects",
["Object", "Plug-ins", "Arrange Tools"],
None,
"{source?: \"key\" (the key object, select.key) | \"top\" (the frontmost selected object) | \"bottom\" (the backmost) (default: the key object when the selection has one, else \"top\"), size?: \"none\" | \"width\" (each target takes the source's width, its height following in proportion) | \"height\" (the source's height, the width following in proportion) | \"both\" (the source's width and height, each on its own) (\"none\"), rotate?: false (true: each target takes the source's bounding-box angle, measured counter-clockwise, turning the shorter way, at most 180°), stacking?: false (true: the targets go directly above the source in the stacking order, in its layer or group, in the order they had), reference?: 0..8 (the 9-point grid row by row from the top-left; 4, the center: the point of each target that stays put as it is sized and turned), scaleStrokes?: the Scale Strokes & Effects preference, patterns?: the Transform Pattern Tiles preference (at least one of size, rotate and stacking)} make the other selected objects (the top-level ones, at most 20000) match the source, which stays as it is, as one undo step (none when nothing changes). Sizes are measured and set as object.setBounds measures them (Use Preview Bounds), each in the object's own bounding-box frame, and a size that a target has no width or height to take is refused, as is a stacking match that would move a clipping path; to match places, use object.align {to: \"key\"} → {source, count}",
"{source?: \"key\" (the key object, select.key) | \"top\" (the frontmost selected object) | \"bottom\" (the backmost) (default: the key object when the selection has one, else \"top\"), size?: \"none\" | \"width\" (each target takes the source's width, its height following in proportion) | \"height\" (the source's height, the width following in proportion) | \"both\" (the source's width and height, each on its own) (\"none\"), rotate?: false (true: each target takes the source's bounding-box angle, measured counter-clockwise, turning the shorter way, at most 180°), stacking?: false (true: the targets go directly above the source in the stacking order, in its layer or group, in the order they had), reference?: 0..8 (the 9-point grid row by row from the top-left; 4, the center: the point of each target that stays put as it is sized and turned), scaleStrokes?: the Scale Strokes & Effects preference, patterns?: the Transform Pattern Tiles preference (at least one of size, rotate and stacking)} make the other selected objects (the top-level ones, at most 20000) match the source, which stays as it is, as one undo step (none when nothing changes). Sizes are measured and set as object.setBounds measures them (Use Preview Bounds), each in the object's own bounding-box frame, and a size that a target has no width or height to take is refused, as is a stacking match that would move a clipping path, restack into a locked layer or group, put a target where the Layers panel can't (a blend's inputs, for one) or move Live Paint art; a turned target with a live effect that moves it keeps its measured reference point in place; to match places, use object.align {to: \"key\"} → {source, count}",
has_multi,
match_objects
),
@@ -436,6 +436,8 @@ fn match_objects(s: &mut Session, p: &Value) -> Result<Value> {
};
let angle = s.doc()?.doc.bbox_angle(&[source]);
let mut xfs = Vec::with_capacity(targets.len());
// Where each turned target's reference point is before the match; it stays there.
let mut pinned: HashMap<NodeId, Point> = HashMap::new();
for &id in &targets {
let turn = if rotate { vectorcraft_geom::normalize_deg(angle - s.doc()?.doc.bbox_angle(&[id])) } else { 0.0 };
let Some(b) = s.transform_box(&[id]) else {
@@ -458,6 +460,12 @@ fn match_objects(s: &mut Session, p: &Value) -> Result<Value> {
// Rotation uses the reference point that sizing keeps in place.
let at = b.to_doc() * vectorcraft_geom::reference_point(b.rect, reference as usize);
xf = Affine::rotate_about(-turn.to_radians(), at) * xf;
if s.bounds_measure().preview && {
let d = &s.doc()?.doc;
d.node(id).is_some_and(|n| effects::preview::draws_geometry(&d.symbol_boxes(), n))
} {
pinned.insert(id, at);
}
}
if wanted.is_some() {
let sc = scaling(s, &json!({ "strokes": strokes }));
@@ -498,6 +506,19 @@ fn match_objects(s: &mut Session, p: &Value) -> Result<Value> {
return Err(bad(C, "a clipping path can't change its place in the stacking order"));
}
let parent = d.parent_of(source);
if parent.is_some_and(|p| crate::cmd::layer::locked_within(d, p)) {
return Err(bad(C, "the layer or group is locked"));
}
// Live Paint art is rebuilt from its paths when they move: Match Objects leaves it in place.
let in_live_paint =
|id: NodeId| d.ancestry(id).unwrap_or_default().iter().any(|a| d.node(*a).is_some_and(vectorcraft_tools::builder::is_live_paint));
if parent.is_some_and(in_live_paint) || targets.iter().any(|t| d.parent_of(*t).is_some_and(in_live_paint)) {
return Err(bad(C, "Live Paint art can't be restacked here: use the Layers panel"));
}
// The source's container takes each target only as the Layers panel would (not a blend's inputs).
if let Some(n) = targets.iter().filter_map(|id| d.node(*id)).find(|n| !crate::cmd::layer::accepts(d, parent, n)) {
return Err(bad(C, format!("{} can't go beside the source object", n.display_name())));
}
if let Some(what) = targets.iter().filter_map(|id| d.node(*id)).find_map(|n| crate::cmd::intertwine::refused_in(d, parent, n)) {
return Err(bad(C, format!("{what} can't be intertwined")));
}
@@ -512,11 +533,26 @@ fn match_objects(s: &mut Session, p: &Value) -> Result<Value> {
let ids: Vec<NodeId> = xfs.iter().map(|(id, _)| *id).collect();
let mut sc = scaling(s, &q);
sc.patterns = transform_patterns(s, &q, &ids)?;
let measure = s.bounds_measure();
let before = s.doc()?.doc.clone();
s.edit("Match Objects", |d, _| {
for (id, xf) in &xfs {
if let Some(n) = d.node_mut(*id) {
transform_node(n, *xf, sc, true);
}
// A live effect that moves the art in page space (a Transform effect's offset) does
// not turn with it: the measured reference point is put back where it was.
if let Some(at) = pinned.get(id)
&& let Some(b) = effects::preview::oriented_bounds_with(d, &[*id], measure)
{
let now = b.to_doc() * vectorcraft_geom::reference_point(b.rect, reference as usize);
let off = *at - now;
if off.hypot() > 1e-9
&& let Some(n) = d.node_mut(*id)
{
transform_node(n, Affine::translate(off), sc, true);
}
}
}
if restack {
let moved = d.remove_many(&targets)?;
@@ -524,6 +560,24 @@ fn match_objects(s: &mut Session, p: &Value) -> Result<Value> {
// Targets moved out of an Intertwine group leave it as ordinary art.
crate::cmd::intertwine::settle_members(d, &placed, &left)?;
}
if !pinned.is_empty() {
crate::cmd::refresh_pixel_aligned(&before, d);
for (id, _) in &xfs {
let Some(at) = pinned.get(id) else { continue };
let ob = effects::preview::oriented_bounds_with(d, &[*id], measure);
let kept = ob.is_some_and(|b| (*at - b.to_doc() * vectorcraft_geom::reference_point(b.rect, reference as usize)).hypot() <= 1e-6);
let misses = !kept
|| ob.is_none_or(|b| match size {
"none" => false,
"width" => (b.rect.width() - w).abs() > 1e-6,
"height" => (b.rect.height() - h).abs() > 1e-6,
_ => (b.rect.width() - w).abs() > 1e-6 || (b.rect.height() - h).abs() > 1e-6,
});
if misses {
return Err(bad(C, format!("object {} can't keep its size and reference point as it turns", id.0)));
}
}
}
Ok(())
})?;
Ok(count)
@@ -689,6 +689,170 @@ fn match_stacking_refuses_intertwine_nesting_beside_an_empty_group() {
assert!(*s.doc().unwrap().doc == *before);
}
#[test]
fn match_refuses_restacking_into_a_locked_container() {
for lock_ancestor in [false, true] {
let mut s = session();
let source = rect(&mut s, 0.0, 0.0, 20.0, 20.0);
select(&mut s, &[source]);
let group = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap());
select(&mut s, &[group]);
let ancestor = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap());
let target = rect(&mut s, 100.0, 0.0, 40.0, 40.0);
select(&mut s, &[source, target]);
s.execute("select.key", &json!({"id": source.0})).unwrap();
let locked = if lock_ancestor { ancestor } else { group };
std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc).node_mut(locked).unwrap().locked = true;
let before = s.doc().unwrap().doc.clone();
let n = steps(&s);
let e = s.execute("addon.arrange.match", &json!({"size": "both", "stacking": true})).unwrap_err();
assert!(e.to_string().contains("the layer or group is locked"), "{e}");
assert_eq!(steps(&s), n);
assert_eq!(s.doc().unwrap().doc.layers, before.layers);
}
}
#[test]
fn match_refuses_restacking_among_a_blends_inputs() {
let mut s = session();
let a = rect(&mut s, 0.0, 0.0, 20.0, 20.0);
let b = rect(&mut s, 100.0, 0.0, 20.0, 20.0);
select(&mut s, &[a, b]);
s.execute("object.blend.make", &json!({})).unwrap();
let target = rect(&mut s, 200.0, 0.0, 20.0, 20.0);
select(&mut s, &[a, target]);
s.execute("select.key", &json!({"id": a.0})).unwrap();
let before = s.doc().unwrap().doc.clone();
let n = steps(&s);
let e = s.execute("addon.arrange.match", &json!({"stacking": true})).unwrap_err();
assert!(e.to_string().contains("can't go beside the source object"), "{e}");
assert_eq!(steps(&s), n);
assert_eq!(s.doc().unwrap().doc.layers, before.layers);
}
#[test]
fn match_refuses_restacking_live_paint_art_but_moves_beside_a_whole_group() {
let mut s = session();
let a = rect(&mut s, 0.0, 0.0, 100.0, 100.0);
let b = rect(&mut s, 50.0, 0.0, 100.0, 100.0);
select(&mut s, &[a, b]);
let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap());
let between = rect(&mut s, 200.0, 0.0, 20.0, 20.0);
let target = rect(&mut s, 250.0, 0.0, 20.0, 20.0);
assert_eq!(layer_order(&s), [g, between, target]);
let member = s.doc().unwrap().doc.children(Some(g)).unwrap()[0].id;
select(&mut s, &[member, target]);
s.execute("select.key", &json!({"id": member.0})).unwrap();
let n = steps(&s);
let e = s.execute("addon.arrange.match", &json!({"stacking": true})).unwrap_err();
assert!(e.to_string().contains("Live Paint art"), "{e}");
assert_eq!(steps(&s), n);
select(&mut s, &[g, target]);
s.execute("select.key", &json!({"id": g.0})).unwrap();
let before = s.doc().unwrap().doc.node(g).unwrap().clone();
s.execute("addon.arrange.match", &json!({"stacking": true})).unwrap();
assert_eq!(steps(&s), n + 1, "one undo step");
assert_eq!(layer_order(&s), [g, target, between]);
assert_eq!(s.doc().unwrap().doc.node(g).unwrap(), &before);
}
#[test]
fn match_turns_art_with_a_moving_effect_about_its_measured_point() {
let mut s = session();
s.prefs.use_preview_bounds = true;
let a = rect(&mut s, 0.0, 0.0, 20.0, 40.0);
select(&mut s, &[a]);
s.execute("object.rotate", &json!({"angle": 90})).unwrap();
let b = rect(&mut s, 100.0, 100.0, 40.0, 20.0);
s.execute("effect.apply", &json!({"ids": [b.0], "effect": "distort.transform", "params": {"moveH": 30}})).unwrap();
let center = |s: &Session| {
let bx = s.transform_box(&[b]).unwrap();
bx.to_doc() * vectorcraft_geom::reference_point(bx.rect, 4)
};
let before = center(&s);
select(&mut s, &[a, b]);
s.execute("select.key", &json!({"id": a.0})).unwrap();
s.execute("addon.arrange.match", &json!({"rotate": true})).unwrap();
let after = center(&s);
assert!((after - before).hypot() < 1e-6, "{before:?} -> {after:?}");
}
#[test]
fn match_checks_a_pixel_aligned_symbols_measured_point_after_snapping() {
for size in ["none", "both"] {
for dx in [0.0, 0.25] {
let mut s = session();
s.prefs.use_preview_bounds = true;
let source = rect(&mut s, 0.0, 0.0, 40.0, 20.0);
let art = rect(&mut s, 100.0, 100.0, 40.0, 20.0);
select(&mut s, &[art]);
let target = NodeId(s.execute("symbol.new", &json!({"name": "Aligned", "alignToPixelGrid": true})).unwrap()["id"].as_u64().unwrap());
s.execute("object.rotate", &json!({"angle": 30})).unwrap();
s.execute("object.move", &json!({"dx": dx})).unwrap();
s.execute("effect.apply", &json!({"ids": [target.0], "effect": "distort.transform", "params": {"moveH": 30}})).unwrap();
let center = |s: &Session| {
let b = s.transform_box(&[target]).unwrap();
b.to_doc() * vectorcraft_geom::reference_point(b.rect, 4)
};
let at = center(&s);
select(&mut s, &[source, target]);
s.execute("select.key", &json!({"id": source.0})).unwrap();
let before = s.doc().unwrap().doc.clone();
let n = steps(&s);
let result = s.execute("addon.arrange.match", &json!({"rotate": true, "size": size}));
if dx == 0.0 {
result.unwrap();
assert!((center(&s) - at).hypot() < 1e-6, "{size}");
let b = s.transform_box(&[target]).unwrap();
assert!(b.angle.abs() < 1e-6, "{size}: {b:?}");
if size == "both" {
let wanted = s.transform_box(&[source]).unwrap();
assert!((b.rect.width() - wanted.rect.width()).abs() < 1e-6, "{size}: {b:?}");
assert!((b.rect.height() - wanted.rect.height()).abs() < 1e-6, "{size}: {b:?}");
}
assert_eq!(steps(&s), n + 1);
s.execute("edit.undo", &json!({})).unwrap();
} else {
let error = result.unwrap_err().to_string();
assert!(error.contains("can't keep its size and reference point as it turns"), "{size}: {error}");
}
assert_eq!(steps(&s), n, "{size}, dx={dx}");
assert!(*s.doc().unwrap().doc == *before, "{size}, dx={dx}");
}
}
}
#[test]
fn match_turns_art_with_a_moving_fill_effect_about_its_measured_point() {
for grouped in [false, true] {
let mut s = session();
s.prefs.use_preview_bounds = true;
let a = rect(&mut s, 0.0, 0.0, 20.0, 40.0);
select(&mut s, &[a]);
s.execute("object.rotate", &json!({"angle": 90})).unwrap();
let b = rect(&mut s, 100.0, 100.0, 40.0, 20.0);
s.execute("effect.apply", &json!({"ids": [b.0], "item": 0, "effect": "distort.transform", "params": {"moveH": 30}})).unwrap();
let b = if grouped {
select(&mut s, &[b]);
NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap())
} else {
b
};
let center = |s: &Session| {
let bx = s.transform_box(&[b]).unwrap();
bx.to_doc() * vectorcraft_geom::reference_point(bx.rect, 4)
};
let before = center(&s);
select(&mut s, &[a, b]);
s.execute("select.key", &json!({"id": a.0})).unwrap();
s.execute("addon.arrange.match", &json!({"rotate": true})).unwrap();
let after = center(&s);
assert!((after - before).hypot() < 1e-6, "grouped={grouped}: {before:?} -> {after:?}");
let d = &s.doc().unwrap().doc;
assert!((d.bbox_angle(&[b]) - d.bbox_angle(&[a])).abs() < 1e-6);
}
}
#[test]
fn match_replays_with_the_stroke_scaling_it_ran_with() {
replays_the_stroke_scaling_it_ran_with("addon.arrange.match", json!({"size": "both"}));
+1 -1
View File
@@ -17581,7 +17581,7 @@ as `object.setBounds` measures them (Use Preview Bounds), except Arrange in Grid
| `addon.arrange.swap` | `size` (false); `scaleStrokes` (the Scale Strokes & Effects preference) | Swaps the bounds centres of exactly two selected objects (off otherwise); with `size`, each also takes the other's width and height. |
| `addon.arrange.replace` | `fit`: `keep`, `bounds` (the replaced object's width and height), `proportional` (fits inside them) (`keep`); `scaleStrokes`; `keep` (false) | Puts a copy of the topmost selected object centred on each of the other selected objects, in that object's place in the stacking order; the replaced objects are deleted unless `keep` (the copy then goes right above each). Needs two objects or more; the copies are selected. → `{ids}` |
| `addon.arrange.size` | `width`, `height` pt, 0.001…1000000 (at least one); `proportional` (false: a side not given stays; true: it follows the given one in proportion); `reference` 0…8 (4, the centre); `scaleStrokes` | Gives every selected object that width and height, keeping its reference point in place (the 9-point grid row by row from the top-left). |
| `addon.arrange.match` | `source`: `key` (the key object, `select.key`), `top` (the frontmost selected object), `bottom` (the backmost) (the key object when the selection has one, else `top`); `size`: `none`, `width` (the height follows in proportion), `height` (the width follows in proportion), `both` (`none`); `rotate` (false); `stacking` (false); `reference` 0…8 (4, the center); `scaleStrokes`; `patterns` (the Transform Pattern Tiles preference); at least one of `size`, `rotate` and `stacking` | Makes the other selected objects (at most 20000) match the source, which stays as it is. `size` gives each one the source's width, height or both, measured in each object's own bounding-box frame; `rotate` turns each one to the source's bounding-box angle; both keep each object's reference point in place. `stacking` puts the others directly above the source, in its layer or group, in the order they had. `source: "key"` without a key object, and a `size` that takes a width or a height the source or a target does not have, and a `stacking` match that would move a clipping path, are refused. To match places, use `object.align {to: "key"}`. → `{source, count}` |
| `addon.arrange.match` | `source`: `key` (the key object, `select.key`), `top` (the frontmost selected object), `bottom` (the backmost) (the key object when the selection has one, else `top`); `size`: `none`, `width` (the height follows in proportion), `height` (the width follows in proportion), `both` (`none`); `rotate` (false); `stacking` (false); `reference` 0…8 (4, the center); `scaleStrokes`; `patterns` (the Transform Pattern Tiles preference); at least one of `size`, `rotate` and `stacking` | Makes the other selected objects (at most 20000) match the source, which stays as it is. `size` gives each one the source's width, height or both, measured in each object's own bounding-box frame; `rotate` turns each one to the source's bounding-box angle; both keep each object's reference point in place. `stacking` puts the others directly above the source, in its layer or group, in the order they had. `source: "key"` without a key object, and a `size` that takes a width or a height the source or a target does not have, and a `stacking` match that would move a clipping path, are refused. A `stacking` match is also refused when the source's layer or group is locked, when it would put a target where the Layers panel does not allow it (among a blend's inputs, for example), or when it would move art into, out of or within a Live Paint group. A turned object with a live effect that moves it keeps its measured reference point in place. To match places, use `object.align {to: "key"}`. → `{source, count}` |
| `addon.arrange.groupOverlapping` | none | Groups the selected objects (at most 20000) wherever their visual bounds overlap or touch, chains included: when A overlaps B and B overlaps C, all three go in one group. Only objects in the same layer or group are grouped together; objects that overlap nothing stay as they are. Each new group goes where its frontmost member was in the stacking order, and the groups and the objects left alone stay selected; with nothing overlapping it makes no step. Needs two objects or more. → `{groups: [id…], grouped}` (how many objects went into groups) |
| `addon.arrange.randomizeOpacity` | `min`, `max` % 0…100 (30, 100; `min` not more than `max`); `seed` whole number (0); `ids` (the selection) | Gives each selected object its own opacity (the object opacity the Transparency panel sets), picked at random and evenly from `min` to `max`; the same seed, objects and range give the same opacities. Groups take one opacity of their own; the objects inside keep theirs. A run that changes no opacity, such as `min` and `max` both at the opacity every object has, records no undo step. → `{count}` |
| `addon.arrange.sort` | `by`, `apply`: `width`, `height`, `area` (width × height), `x` (left edge), `y` (top edge), `opacity` (%), `stacking` (stacking order from the back) (`area`, `stacking`); `order`: `ascending` (small to large), `descending` (large to small), `random` (`ascending`); `distribute` (false); `seed` whole number (0, for `random`); `scaleStrokes`; `ids` (the selection) | Sorts the selected objects (at most 20000) by `by` and gives them the values of `apply` in that order: the first gets the smallest value. Without `distribute` the objects trade the values they have; with it the values step evenly from the smallest to the largest. A width, height or area changes about each object's centre (an area in proportion), a place moves the top-left corner. Stacking order always trades places, and only among objects in the same layer or group. Needs two objects or more. → `{count}` |
+1 -1
View File
@@ -3148,7 +3148,7 @@ dialogs, Preview and Cancel, Zoom to Selection) and `command_sweep`. Commands: `
## Arrange Tools add-on: Match Objects (2026-11-29)
A VectorCraft addition, not a feature of the reference app, so no area score moves. Object › Plug-ins › Arrange Tools › Match Objects… makes the other top-level selected objects (at most 20000) match one of them, the source: the key object, or the top or the bottom selected object. Each can take the source's width (the height following in proportion), its height (the width following), or both, measured as `object.setBounds` measures them (Use Preview Bounds) in each object's own bounding-box frame; its bounding-box angle; and its stacking place, directly above the source in its layer or group, in the order they had (a clipping path keeps its place, so such a match is refused). Sizing and turning keep each object's reference point in place, and strokes, effects and pattern tiles follow Scale Strokes & Effects and Transform Pattern Tiles. The source stays as it is, the dialog previews on the canvas, and OK is one undo step; no step when nothing changes. Places are matched with Align to Key Object (`object.align {to: "key"}`). Tests: `match_*` in `cmd::addons::arrange::tests` in `vectorcraft-engine` (each size, the key, top and bottom sources, angles about the center, stacking within and across layers, no step when matched, bad params), `real_match_keyboard_edits_preview_confirm_and_cancel` in `vectorcraft-ui-egui` and `command_sweep`. Commands: `docs/mcp.md` › Arrange Tools add-on.
A VectorCraft addition, not a feature of the reference app, so no area score moves. Object › Plug-ins › Arrange Tools › Match Objects… makes the other top-level selected objects (at most 20000) match one of them, the source: the key object, or the top or the bottom selected object. Each can take the source's width (the height following in proportion), its height (the width following), or both, measured as `object.setBounds` measures them (Use Preview Bounds) in each object's own bounding-box frame; its bounding-box angle; and its stacking place, directly above the source in its layer or group, in the order they had (a clipping path keeps its place, so such a match is refused, as is one into a locked layer or group, among a blend's inputs or into, out of or within a Live Paint group). Sizing and turning keep each object's reference point in place, and strokes, effects and pattern tiles follow Scale Strokes & Effects and Transform Pattern Tiles. The source stays as it is, the dialog previews on the canvas, and OK is one undo step; no step when nothing changes. Places are matched with Align to Key Object (`object.align {to: "key"}`). Tests: `match_*` in `cmd::addons::arrange::tests` in `vectorcraft-engine` (each size, the key, top and bottom sources, angles about the center, stacking within and across layers, no step when matched, bad params), `real_match_keyboard_edits_preview_confirm_and_cancel` in `vectorcraft-ui-egui` and `command_sweep`. Commands: `docs/mcp.md` › Arrange Tools add-on.
## Arrange Tools add-on: Group Overlapping Objects (2026-11-01)