Merge pull request #10194 from dotCooCoo/fix/match-objects-guards

Arrange Tools: Match Objects refuses restacks into locked, blend and Live Paint containers
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-04 14:19:46 -08:00
commit 113edfe404
6 files changed
+384 -7

No files matched your search

+79 -3
View File
@@ -31,8 +31,8 @@ use super::super::edit::selected_roots;
use super::super::graph::{capture_series_object_opacity, series_groups_among};
use super::super::menucmds::whole_or;
use super::super::object::{
aligned_symbol_transforms, choice, keep_aligned_in_with, keep_symbol_instances_aligned, object_bounds_transform, object_bounds_transform_keeping,
refit_drawn, scaling, transform_node, transform_patterns,
aligned_symbol_transforms, aligned_symbols, choice, keep_aligned_in_with, keep_symbol_instances_aligned, object_bounds_transform,
object_bounds_transform_keeping, refit_drawn, scaling, snaps_after_edit, transform_node, transform_patterns,
};
use super::super::objects_on_path;
use super::super::typecmd::refresh_bounds_of;
@@ -102,7 +102,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, corners?: the Scale Corners 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 after it is turned, with no smallest scale. The side that follows in proportion follows the object's box before the match. Art that is aligned to the pixel grid is measured before it snaps. A size that a target has no width or height to take, or that a stroke or an effect that does not scale keeps it from reaching, 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, corners?: the Scale Corners 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 after it is turned, with no smallest scale. The side that follows in proportion follows the object's box before the match. Art that is aligned to the pixel grid is measured before it snaps. A size that a target has no width or height to take, or that a stroke or an effect that does not scale keeps it from reaching, is refused, as is a stacking match whose targets are not already directly above the source and that would move a clipping path, restack into or out of a locked layer or group, take a target out of the blend input it is in (to restack the blend itself, select the whole blend), 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, and with Use Preview Bounds, for a target the match turns that carries a visible geometry or 3D effect or a live compound shape on itself or inside it, or a visible geometry or 3D effect in a placed symbol's art, the match is refused when pixel snapping would move that target's reference point or change a dimension it was asked to match, as it is for a turned target that is pixel-aligned or holds pixel-aligned art or an instance of a pixel-aligned symbol, with or without Use Preview Bounds; to match places, use object.align {to: \"key\"} → {source, count}",
has_multi,
match_objects
),
@@ -526,6 +526,11 @@ 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();
// The turned targets whose reference point is checked after pixel snapping.
let mut checked: HashMap<NodeId, Point> = HashMap::new();
let symbols = if rotate { aligned_symbols(&s.doc()?.doc) } else { 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 {
@@ -551,6 +556,16 @@ fn match_objects(s: &mut Session, p: &Value) -> Result<Value> {
let turned = Affine::rotate_about(-turn.to_radians(), at);
if turn.abs() > 1e-9 {
xf = turned * xf;
let preview = s.bounds_measure().preview;
let d = &s.doc()?.doc;
if preview && d.node(id).is_some_and(|n| effects::preview::draws_geometry(&d.symbol_boxes(), n)) {
pinned.insert(id, at);
}
// Pixel snapping after the turn can move a pixel-aligned target: its point is checked
// too, but not put back, since that would move its aligned art off the grid.
if pinned.contains_key(&id) || d.node(id).is_some_and(|n| snaps_after_edit(n, &symbols)) {
checked.insert(id, at);
}
}
if wanted.is_some() {
let fit = Fit { at, refi: reference as usize, goal: match_goal(size, (w, h), b.rect), strokes, corners };
@@ -571,6 +586,32 @@ 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);
// Each target leaves its own container, so a target's locked container refuses too.
let locked = |p: Option<NodeId>| p.is_some_and(|p| crate::cmd::layer::locked_within(d, p));
if locked(parent) || targets.iter().any(|t| locked(d.parent_of(*t))) {
return Err(bad(C, "the layer or group is locked"));
}
// A blend's input objects, and art inside them, stay in the blend: the whole blend can still be
// restacked, and art can still move within the blend's input it is in.
let is_blend = |a: &NodeId| d.node(*a).is_some_and(|n| matches!(n.kind, NodeKind::Blend { .. }));
let destination = parent.and_then(|p| d.ancestry(p)).unwrap_or_default();
let leaves_blend = |t: &NodeId| {
let chain = d.ancestry(*t).unwrap_or_default();
chain.windows(2).filter(|w| is_blend(&w[0])).any(|w| !destination.windows(2).any(|v| v == w))
};
if targets.iter().any(leaves_blend) {
return Err(bad(C, "a blend's input objects can't leave their blend input: to restack the blend, select the whole blend"));
}
// 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")));
}
@@ -585,11 +626,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)?;
@@ -597,6 +653,26 @@ 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 !checked.is_empty() {
// Measured on a snapped copy: the edit itself snaps once, after Global Edit.
let mut snapped = d.clone();
crate::cmd::refresh_pixel_aligned(&before, &mut snapped);
for (id, _) in &xfs {
let Some(at) = checked.get(id) else { continue };
let ob = effects::preview::oriented_bounds_with(&snapped, &[*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)
@@ -525,6 +525,67 @@ fn match_size_and_rotation_measure_pixel_aligned_art_in_its_final_frame() {
}
}
#[test]
fn match_rotation_refuses_when_pixel_snapping_would_move_the_reference_point() {
for wrap in ["path", "group", "compound"] {
let mut s = session();
let target = rect(&mut s, 0.0, 0.0, 10.0, 11.0);
if wrap != "compound" {
s.execute("object.setPixelAligned", &json!({"on": true})).unwrap();
}
let target = match wrap {
"group" => NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap()),
"compound" => NodeId(s.execute("object.compoundPath.make", &json!({})).unwrap()["id"].as_u64().unwrap()),
_ => target,
};
select(&mut s, &[target]);
if wrap == "compound" {
s.execute("object.setPixelAligned", &json!({"on": true})).unwrap();
}
let source = rect(&mut s, 100.0, 0.0, 10.0, 10.0);
select(&mut s, &[source]);
s.execute("object.rotate", &json!({"angle": 90})).unwrap();
select(&mut s, &[target, source]);
s.execute("select.key", &json!({"id": source.0})).unwrap();
let before = s.doc().unwrap().doc.clone();
let n = steps(&s);
// Turned a quarter about its center (5, 5.5), the 10 x 11 path's edges land on half points,
// and snapping them back to the grid would move that center.
let e = s.execute("addon.arrange.match", &json!({"rotate": true})).unwrap_err().to_string();
assert!(e.contains("reference point"), "{wrap}: {e}");
assert_eq!(steps(&s), n, "{wrap}: no undo step");
assert!(*s.doc().unwrap().doc == *before, "{wrap}");
}
}
#[test]
fn match_rotation_keeps_a_mixed_group_in_one_piece_or_refuses() {
let mut s = session();
let aligned = rect(&mut s, 0.0, 0.0, 10.0, 11.0);
s.execute("object.setPixelAligned", &json!({"on": true})).unwrap();
let loose = rect(&mut s, 20.0, 0.0, 10.0, 11.0);
select(&mut s, &[aligned, loose]);
let target = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap());
let source = rect(&mut s, 100.0, 0.0, 10.0, 10.0);
select(&mut s, &[source]);
s.execute("object.rotate", &json!({"angle": 90})).unwrap();
select(&mut s, &[target, source]);
s.execute("select.key", &json!({"id": source.0})).unwrap();
let gap = |s: &Session| {
let (a, b) = (s.transform_box(&[aligned]).unwrap().center(), s.transform_box(&[loose]).unwrap().center());
b - a
};
let before = s.doc().unwrap().doc.clone();
match s.execute("addon.arrange.match", &json!({"rotate": true})) {
// Turned a quarter, the members' centers keep their distance and only change direction.
Ok(_) => assert!((gap(&s).hypot() - 20.0).abs() < 1e-6, "the members moved apart: {:?}", gap(&s)),
Err(e) => {
assert!(e.to_string().contains("reference point"), "{e}");
assert!(*s.doc().unwrap().doc == *before);
}
}
}
#[test]
fn match_rotation_refuses_a_target_without_bounds_when_its_angle_differs() {
for angle in [0, 30] {
@@ -811,6 +872,234 @@ 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_taking_a_target_out_of_a_locked_container() {
let mut s = session();
let target = rect(&mut s, 100.0, 0.0, 40.0, 40.0);
select(&mut s, &[target]);
let group = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap());
let source = rect(&mut s, 0.0, 0.0, 20.0, 20.0);
select(&mut s, &[source, target]);
s.execute("select.key", &json!({"id": source.0})).unwrap();
std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc).node_mut(group).unwrap().locked = true;
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("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_taking_a_target_out_of_a_blend_but_restacks_the_whole_blend() {
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]);
let blend = NodeId(s.execute("object.blend.make", &json!({})).unwrap()["id"].as_u64().unwrap());
let between = rect(&mut s, 200.0, 0.0, 20.0, 20.0);
let source = rect(&mut s, 250.0, 0.0, 20.0, 20.0);
assert_eq!(layer_order(&s), [blend, between, source]);
select(&mut s, &[a, source]);
s.execute("select.key", &json!({"id": source.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("a blend's input objects"), "{e}");
assert_eq!(steps(&s), n);
assert_eq!(s.doc().unwrap().doc.layers, before.layers);
select(&mut s, &[blend, source]);
s.execute("select.key", &json!({"id": source.0})).unwrap();
s.execute("addon.arrange.match", &json!({"stacking": true})).unwrap();
assert_eq!(steps(&s), n + 1, "one undo step");
assert_eq!(layer_order(&s), [between, source, blend]);
}
#[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_refuses_when_snapping_moves_a_pixel_aligned_symbol_instance_without_preview_bounds() {
let mut s = session();
s.prefs.use_preview_bounds = false;
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": 0.25})).unwrap();
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);
// Turned back to its natural angle, the instance snaps to whole points, which moves its center.
let error = s.execute("addon.arrange.match", &json!({"rotate": true})).unwrap_err().to_string();
assert!(error.contains("can't keep its size and reference point as it turns"), "{error}");
assert_eq!(steps(&s), n);
assert!(*s.doc().unwrap().doc == *before);
}
#[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"}));
+2 -2
View File
@@ -37,8 +37,8 @@ pub(crate) use bounds::{bounds_rewrite, object_bounds_transform, object_bounds_t
pub use commands::specs;
pub(super) use compound::{as_clipping_path, copy_transparency, make_clipping_path, release_clip};
pub(crate) use pixelgrid::{
align_new_object, aligned_symbol_transforms, can_align, keep_aligned_in, keep_aligned_in_with, keep_compound_aligned, keep_pixel_aligned,
keep_symbol_instances_aligned, refresh as refresh_pixel_aligned, resnap, snap_if_aligned, snap_symbol_art,
align_new_object, aligned_symbol_transforms, aligned_symbols, can_align, keep_aligned_in, keep_aligned_in_with, keep_compound_aligned,
keep_pixel_aligned, keep_symbol_instances_aligned, refresh as refresh_pixel_aligned, resnap, snap_if_aligned, snap_symbol_art, snaps_after_edit,
};
pub(super) use shape::recut;
pub(crate) use transform::{apply_transform, nudge_step, preview_copies, scaling, transform_node, transform_patterns, transforms_objects};
+12
View File
@@ -492,6 +492,18 @@ pub(crate) fn snap_if_aligned(n: &mut Node) {
}
}
/// Whether the pixel-grid snap after an edit ([`refresh`]) can move object `n`: `n` holds
/// pixel-aligned art ([`holds_aligned`]) or an instance of a symbol in `symbols`, the document's
/// pixel-aligned symbols ([`aligned_symbols`]).
pub(crate) fn snaps_after_edit(n: &Node, symbols: &HashMap<String, Affine>) -> bool {
holds_aligned(n) || !symbols.is_empty() && holds_instance(n, symbols)
}
/// The pixel-aligned symbols of `d`, keyed by name, for [`snaps_after_edit`].
pub(crate) fn aligned_symbols(d: &Document) -> HashMap<String, Affine> {
d.pixel_aligned_symbols().into_iter().map(|name| (name, Affine::IDENTITY)).collect()
}
/// Whether `n` or an object in it, or in the art of a linked opacity mask in it, is pixel-aligned.
/// It goes only where a transform of `n` goes: not into unlinked masks.
fn holds_aligned(n: &Node) -> bool {
+1 -1
View File
@@ -18806,7 +18806,7 @@ records the value used, and a replay of that entry scales corners the same way w
| `addon.arrange.swap` | `size` (false); `scaleStrokes` (the Scale Strokes & Effects preference); `corners` (the Scale Corners 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`; `corners` (the Scale Corners preference); `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`; `corners` (the Scale Corners preference) | 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`; `corners` (the Scale Corners preference); `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 after it is turned, with no smallest scale; the side that follows in proportion follows the object's box before the match. Art that is aligned to the pixel grid is measured before it snaps. `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, a `size` that takes a width or a height the source or a target does not have, a `size` that a stroke or an effect that does not scale keeps a target from reaching, 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`; `corners` (the Scale Corners preference); `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 after it is turned, with no smallest scale; the side that follows in proportion follows the object's box before the match. Art that is aligned to the pixel grid is measured before it snaps. `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, a `size` that takes a width or a height the source or a target does not have, a `size` that a stroke or an effect that does not scale keeps a target from reaching, and a `stacking` match that would move a clipping path, are refused. When the others are already directly above the source, a `stacking` match leaves their places as they are; otherwise it is also refused when the source's layer or group or a target's own layer or group is locked, when it would take a target out of the blend input it is in (a blend's input objects and the art inside each one stay in that input; to restack the blend itself, select the whole blend), 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. With Use Preview Bounds, for an object the match turns that carries a visible geometry or 3D effect or a live compound shape on itself or on art inside it, or a visible geometry or 3D effect in the art of a symbol it places, the match is refused when pixel snapping would move that object's reference point or change a dimension it was asked to match. The same refusal applies, with or without Use Preview Bounds, to a turned object that is pixel-aligned or holds pixel-aligned art or an instance of a pixel-aligned symbol. 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.groupRows` | `direction`: `row` (vertical extents), `column` (horizontal extents) (`row` when omitted; `null` is invalid). Parameters must be an object. | Groups the selected objects (at most 20000) into one group for each row (column): an object joins a row when its visual bounds overlap the row's extent from top to bottom (left to right). Measurement includes strokes and vector effects, measures a clipping group by its mask, and excludes raster effects such as shadows, glows, and blurs. Extents that only touch stay apart, and an object that overlaps two rows joins them into one. Only objects in the same layer or group and on the same artboard (the one holding the object's center, else the one it overlaps most) share a row. Objects outside all artboards, locked or hidden objects, clipping masks, layers, and sublayers stay in place. Every grouping candidate must have a parent that is a layer or group. The command rejects selections containing editable live blend keys, direct children of Shaper groups, live compound shapes, Objects on Path groups, or Live Paint groups, and any descendants of live graphs. Complete live groups and graphs can be grouped with other artwork. An object alone in its row stays as it is. Each new group goes where its frontmost member was in the stacking order, and the groups (top to bottom, or left to right) and the objects left alone stay selected; with no row of two objects or more 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}` |
+1 -1
View File
@@ -3182,7 +3182,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 (targets already there keep their places; otherwise a clipping path keeps its place, so a match that would move one is refused, as is one that would move a target into or out of a locked layer or group, out of the blend input it is in, 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; with Use Preview Bounds, for an object the match turns that carries a visible geometry or 3D effect or a live compound shape on itself or on art inside it, or a visible geometry or 3D effect in the art of a symbol it places, the match is refused when pixel snapping would move that object's reference point or change a dimension it was asked to match. The same refusal applies, with or without Use Preview Bounds, to a turned object that is pixel-aligned or holds pixel-aligned art or an instance of a pixel-aligned symbol. 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)