Merge pull request #10072 from dotCooCoo/feat/match-objects-to-key

Arrange Tools: Match Objects gives the others the key object's size, angle and stacking place
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-29 16:30:42 -08:00
commit cdc14eb007
10 files changed
+675 -7

No files matched your search

+1
View File
@@ -163,6 +163,7 @@ Ranked; detail in [docs/roadmap.md](docs/roadmap.md) and [docs/gaps.md](docs/gap
- 2026-11-01: Expand Dashes into Paths joins the Path Precision Tools add-on (Object › Plug-ins › Path Precision Tools): each selected path's dashed stroke becomes separate open paths, one per dash, laid out exactly as the stroke draws them (pattern, offset, Align Dashes to Corners and Path Ends), each keeping the stroke with the dashes off, so the gaps are real gaps for cutters and plotters, as one undo step (`addon.pathtools.expandDashes`, #4922).
- 2026-11-01: Randomize Opacity joins the Arrange Tools add-on (Object › Plug-ins › Arrange Tools): each selected object gets its own opacity at random between a minimum and a maximum percent, with a seed that repeats the result, as one undo step (`addon.arrange.randomizeOpacity`, #4925).
- 2026-11-01: Sort Objects joins the Arrange Tools add-on (Object › Plug-ins › Arrange Tools): the selected objects are sorted by width, height, area, position, opacity or stacking order (small to large, large to small or at random) and take another of those in that order, trading their values or stepping them evenly, as one undo step (`addon.arrange.sort`, #4917).
- 2026-11-29: Match Objects joins the Arrange Tools add-on (Object › Plug-ins › Arrange Tools): the other selected objects take the width, the height or both, the bounding-box angle and the stacking place of the key object, or of the top or the bottom selected object, about a reference point, with Preview, as one undo step (`addon.arrange.match`). A VectorCraft addition: headline numbers unchanged.
- 2026-11-29: Offset Objects joins the Arrange Tools add-on (Object › Plug-ins › Arrange Tools): the selected objects are chained one after another in a row or a column with a set gap (negative to overlap them), in stacking order or by position, either way; the first stays in place and the others move only along the row or column, as one undo step (`addon.arrange.offset`). A VectorCraft addition: headline numbers unchanged.
- 2026-11-15: Tangent Circle joins the Path Precision Tools add-on (Object › Plug-ins › Path Precision Tools): the circles that touch two selected paths or compound paths at a set radius, or three of them (up to eight for three circles), touching each outline without crossing it; circles, rotated ellipses and other paths alike. A dialog that previews every circle or one picked by number, the current paint, one undo step (`addon.pathtools.tangentCircle`). A VectorCraft addition: headline numbers unchanged.
- 2026-11-17: Add Bounding Rectangle and Add Bounding Circle join the Path Precision Tools add-on (Object › Plug-ins › Path Precision Tools): a live rectangle on the selection's geometric bounding box, or the smallest live circle that holds its outlines, around the whole selection or around each object, with the current paint and one undo step; the menu items open a dialog with Offset, One per Object and Preview (`addon.pathtools.boundingRectangle`, `addon.pathtools.boundingCircle`, #6966). A VectorCraft addition: headline numbers unchanged.
+175 -5
View File
@@ -3,7 +3,8 @@
//! row or a column with a set gap, the first staying in place; Swap Objects swaps the places (and sizes) of two;
//! Replace with Top Object puts a copy of the topmost selected object in place of each of the
//! others; and Set Size of Each gives every selected object an exact width and height. Places and
//! sizes are measured and set as `object.setBounds` does. Group Overlapping Objects groups the
//! sizes are measured and set as `object.setBounds` does. Match Objects gives the other selected
//! objects the size, bounding-box angle and stacking place of one of them. Group Overlapping Objects groups the
//! objects whose visual bounds overlap, Randomize Opacity gives each selected object a random
//! opacity, and Sort Objects sorts the selected objects by one attribute and gives them another in
//! that order. Its submenu (Object › Plug-ins › Arrange Tools), its dialogs and Zoom to Selection
@@ -89,6 +90,15 @@ pub fn specs() -> Vec<CommandSpec> {
has_selection,
size
),
cmd!(
"addon.arrange.match",
"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}",
has_multi,
match_objects
),
cmd!(
"addon.arrange.groupOverlapping",
"Group Overlapping Objects",
@@ -177,6 +187,14 @@ fn transform_each(s: &mut Session, label: &str, strokes: bool, xfs: &[(NodeId, A
})
}
/// The `scaleStrokes` param, else the Scale Strokes & Effects preference. The value joins the
/// command's journal entry, so replaying it scales the same way whatever the preference is then.
fn scale_strokes(s: &mut Session, p: &Value, cmd: &str) -> Result<bool> {
let on = switch_or(p, "scaleStrokes", s.prefs.scale_strokes, cmd)?;
s.note_journal("scaleStrokes", json!(on));
Ok(on)
}
/// The box of object `id` as `object.setBounds` measures it.
fn box_of(s: &Session, id: NodeId) -> Result<OrientedBox> {
s.transform_box(&[id]).ok_or_else(|| EngineError::Other("no bounds".into()))
@@ -277,7 +295,7 @@ fn offset(s: &mut Session, p: &Value) -> Result<Value> {
fn swap(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "addon.arrange.swap";
let size = switch_or(p, "size", false, C)?;
let strokes = switch_or(p, "scaleStrokes", s.prefs.scale_strokes, C)?;
let strokes = scale_strokes(s, p, C)?;
let roots = selected_roots(s)?;
let &[a, b] = roots.as_slice() else { return Err(bad(C, "select exactly two objects")) };
let (ba, bb) = (box_of(s, a)?, box_of(s, b)?);
@@ -290,7 +308,7 @@ fn swap(s: &mut Session, p: &Value) -> Result<Value> {
fn replace(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "addon.arrange.replace";
let fit = choice(p, C, "fit", &["keep", "bounds", "proportional"])?.unwrap_or("keep");
let strokes = switch_or(p, "scaleStrokes", s.prefs.scale_strokes, C)?;
let strokes = scale_strokes(s, p, C)?;
let keep = switch_or(p, "keep", false, C)?;
let roots = selected_roots(s)?;
let Some((&top, others)) = roots.split_last().filter(|(_, others)| !others.is_empty()) else {
@@ -341,7 +359,7 @@ fn size(s: &mut Session, p: &Value) -> Result<Value> {
}
let proportional = switch_or(p, "proportional", false, C)?;
let reference = whole_in(p, "reference", (0, 8), C)?.unwrap_or(4);
let strokes = switch_or(p, "scaleStrokes", s.prefs.scale_strokes, C)?;
let strokes = scale_strokes(s, p, C)?;
let mut q = json!({ "reference": reference, "strokes": strokes, "proportional": proportional && (width.is_none() || height.is_none()) });
if let Some(w) = width {
q["width"] = json!(w);
@@ -359,6 +377,158 @@ fn size(s: &mut Session, p: &Value) -> Result<Value> {
Ok(json!({ "count": xfs.len() }))
}
/// The source Match Objects matches `roots` (the selected roots, in stacking order) to, from its
/// `source` param: the selected root that is the key object or holds it, the frontmost or the backmost.
fn match_source(s: &Session, p: &Value, roots: &[NodeId], cmd: &str) -> Result<NodeId> {
let st = s.doc()?;
let key = st.selection.key.and_then(|k| st.doc.ancestry(k)).and_then(|up| roots.iter().copied().find(|id| up.contains(id)));
let picked = match choice(p, cmd, "source", &["key", "top", "bottom"])? {
Some("key") => Some(key.ok_or_else(|| bad(cmd, "no key object: set one with select.key"))?),
Some("bottom") => roots.first().copied(),
Some(_) => roots.last().copied(),
None => key.or_else(|| roots.last().copied()),
};
picked.ok_or_else(|| bad(cmd, "select at least two objects"))
}
/// Whether `targets` (in stacking order) are directly above `source` in its layer or group, in that order.
fn stacked_above(d: &vectorcraft_doc::Document, source: NodeId, targets: &[NodeId]) -> bool {
let paths = d.index_paths(targets.iter().copied().chain([source]));
let Some((&at, up)) = paths.get(&source).and_then(|p| p.split_last()) else { return false };
targets.iter().enumerate().all(|(i, id)| paths.get(id).and_then(|p| p.split_last()) == Some((&(at + 1 + i), up)))
}
fn match_objects(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "addon.arrange.match";
let size = choice(p, C, "size", &["none", "width", "height", "both"])?.unwrap_or("none");
let rotate = switch_or(p, "rotate", false, C)?;
let stacking = switch_or(p, "stacking", false, C)?;
let reference = whole_in(p, "reference", (0, 8), C)?.unwrap_or(4);
let strokes = scale_strokes(s, p, C)?;
let patterns = switch_or(p, "patterns", s.prefs.transform_pattern_tiles, C)?;
if size == "none" && !rotate && !stacking {
return Err(bad(C, "give `size`, `rotate` or `stacking`"));
}
let roots = selected_roots(s)?;
if roots.len() > MAX_OBJECTS {
return Err(bad(C, "too many objects selected (at most 20000)"));
}
let source = match_source(s, p, &roots, C)?;
let targets: Vec<NodeId> = roots.iter().copied().filter(|id| *id != source).collect();
if targets.is_empty() {
return Err(bad(C, "select at least two objects"));
}
// Only sizing measures the source; a stacking or rotate match doesn't need its bounds.
let (w, h) = if size == "none" {
(0.0, 0.0)
} else {
let sb = box_of(s, source)?;
(sb.rect.width(), sb.rect.height())
};
let wanted = match size {
"width" if w < LEAST => return Err(bad(C, "the source object has no width")),
"height" if h < LEAST => return Err(bad(C, "the source object has no height")),
"both" if w < LEAST || h < LEAST => return Err(bad(C, "the source object has no width or no height")),
"width" => Some(json!({ "width": w, "proportional": true })),
"height" => Some(json!({ "height": h, "proportional": true })),
"both" => Some(json!({ "width": w, "height": h })),
_ => None,
};
let angle = s.doc()?.doc.bbox_angle(&[source]);
let mut xfs = Vec::with_capacity(targets.len());
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 {
if wanted.is_some() {
return Err(bad(C, format!("object {} has no bounds to size", id.0)));
}
if turn.abs() > 1e-9 {
return Err(bad(C, format!("object {} has no bounds to rotate", id.0)));
}
continue;
};
let mut xf = Affine::IDENTITY;
if let Some(q) = &wanted {
let mut q = q.clone();
q["reference"] = json!(reference);
q["strokes"] = json!(strokes);
xf = object_bounds_transform(s, &q, id)?;
}
if turn.abs() > 1e-9 {
// 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 wanted.is_some() {
let sc = scaling(s, &json!({ "strokes": strokes }));
let d = &s.doc()?.doc;
let symbols = d.symbol_boxes();
let measure = |xf| {
d.node(id).and_then(|n| {
let mut n = n.clone();
transform_node(&mut n, xf, sc, true);
let frame = OrientedBox { angle: n.bbox_angle, rect: Rect::ZERO };
effects::preview::bounds_in_with(&symbols, &n, frame.to_doc().inverse(), s.bounds_measure())
})
};
let misses = |measured: Option<Rect>| {
measured.is_none_or(|r| match size {
"width" => (r.width() - w).abs() > 1e-6,
"height" => (r.height() - h).abs() > 1e-6,
_ => (r.width() - w).abs() > 1e-6 || (r.height() - h).abs() > 1e-6,
})
};
// The sized and turned object, measured in its final frame, must have the size asked for.
if misses(measure(xf)) {
return Err(bad(C, format!("object {} can't take the requested size", id.0)));
}
}
xfs.push((id, xf));
}
let still = |xf: &Affine| xf.as_coeffs().iter().zip(Affine::IDENTITY.as_coeffs()).all(|(a, b)| (a - b).abs() <= 1e-9);
xfs.retain(|(_, xf)| !still(xf));
let restack = stacking && !stacked_above(&s.doc()?.doc, source, &targets);
let (mut placed, mut left) = (vec![], vec![]);
if restack {
let d = &s.doc()?.doc;
// In a clip group or a clipping layer the bottom child is the clipping path: it stays there.
let is_clip =
|id: &NodeId| d.position(*id).is_some_and(|(_, idx, _)| idx == 0) && d.parent_of(*id).and_then(|p| d.node(p)).is_some_and(Node::clips);
if targets.iter().any(is_clip) {
return Err(bad(C, "a clipping path can't change its place in the stacking order"));
}
let parent = d.parent_of(source);
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")));
}
placed = targets.iter().map(|i| (*i, d.parent_of(*i))).collect::<Vec<(NodeId, Option<NodeId>)>>();
left = crate::cmd::intertwine::groups_of(d, &targets);
}
let count = json!({ "source": source.0, "count": targets.len() });
if xfs.is_empty() && !restack {
return Ok(count);
}
let q = json!({ "strokes": strokes, "patterns": patterns });
let ids: Vec<NodeId> = xfs.iter().map(|(id, _)| *id).collect();
let mut sc = scaling(s, &q);
sc.patterns = transform_patterns(s, &q, &ids)?;
s.edit("Match Objects", |d, _| {
for (id, xf) in &xfs {
if let Some(n) = d.node_mut(*id) {
transform_node(n, *xf, sc, true);
}
}
if restack {
let moved = d.remove_many(&targets)?;
d.insert_beside(vec![(source, moved.into_iter().map(Arc::unwrap_or_clone).collect())], false)?;
// Targets moved out of an Intertwine group leave it as ordinary art.
crate::cmd::intertwine::settle_members(d, &placed, &left)?;
}
Ok(())
})?;
Ok(count)
}
/// The sets of two or more of `items` (each in the order given) whose rects overlap or touch,
/// chains included, among items of the same key (parent). A sweep along x: only the rects still
/// open where each one starts are compared with it.
@@ -505,7 +675,7 @@ fn sort(s: &mut Session, p: &Value) -> Result<Value> {
let order = choice(p, C, "order", &["ascending", "descending", "random"])?.unwrap_or("ascending");
let distribute = switch_or(p, "distribute", false, C)?;
let mut rng = Rng::new(whole_or(p, "seed", 0, C)?);
let strokes = switch_or(p, "scaleStrokes", s.prefs.scale_strokes, C)?;
let strokes = scale_strokes(s, p, C)?;
let ids = checked_ids_or_selection(s, p, C)?;
if ids.len() > MAX_OBJECTS {
return Err(bad(C, "too many objects selected (at most 20000)"));
@@ -343,6 +343,394 @@ fn size_gives_each_object_a_width_and_height() {
assert!(near(bounds(&s, a), (30.0, 8.0, 10.0, 12.0)), "both given: both set, {:?}", bounds(&s, a));
}
/// Three rectangles from the back, all selected: `a` 20 × 10 at the origin, `b` 40 × 40 at
/// (100, 100) and `c` 10 × 30 at (200, 0).
fn three(s: &mut Session) -> (NodeId, NodeId, NodeId) {
let a = rect(s, 0.0, 0.0, 20.0, 10.0);
let b = rect(s, 100.0, 100.0, 40.0, 40.0);
let c = rect(s, 200.0, 0.0, 10.0, 30.0);
select(s, &[a, b, c]);
(a, b, c)
}
#[test]
fn match_gives_the_others_the_key_objects_size() {
let mut s = session();
let (a, b, c) = three(&mut s);
s.execute("select.key", &json!({"id": b.0})).unwrap();
let n = steps(&s);
let r = s.execute("addon.arrange.match", &json!({"size": "both"})).unwrap();
assert_eq!(r, json!({"source": b.0, "count": 2}));
assert_eq!(steps(&s), n + 1, "one undo step");
// About each center; the key object stays.
assert!(near(bounds(&s, a), (-10.0, -15.0, 40.0, 40.0)), "{:?}", bounds(&s, a));
assert!(near(bounds(&s, c), (185.0, -5.0, 40.0, 40.0)), "{:?}", bounds(&s, c));
assert!(near(bounds(&s, b), (100.0, 100.0, 40.0, 40.0)), "{:?}", bounds(&s, b));
s.execute("edit.undo", &json!({})).unwrap();
assert!(near(bounds(&s, a), (0.0, 0.0, 20.0, 10.0)));
// The width, with the height in proportion, about the top-left corner.
s.execute("addon.arrange.match", &json!({"size": "width", "reference": 0})).unwrap();
assert!(near(bounds(&s, a), (0.0, 0.0, 40.0, 20.0)), "{:?}", bounds(&s, a));
assert!(near(bounds(&s, c), (200.0, 0.0, 40.0, 120.0)), "{:?}", bounds(&s, c));
s.execute("edit.undo", &json!({})).unwrap();
s.execute("addon.arrange.match", &json!({"size": "height", "reference": 8})).unwrap();
assert!(near(bounds(&s, a), (-60.0, -30.0, 80.0, 40.0)), "{:?}", bounds(&s, a));
assert!(near(bounds(&s, c), (196.6666666666667, -10.0, 13.333333333333334, 40.0)), "{:?}", bounds(&s, c));
}
#[test]
fn match_takes_the_top_or_the_bottom_object_without_a_key() {
let mut s = session();
let (a, b, c) = three(&mut s);
// No key object: the frontmost, c.
let r = s.execute("addon.arrange.match", &json!({"size": "both"})).unwrap();
assert_eq!(r["source"], json!(c.0));
assert!(near(bounds(&s, a), (5.0, -10.0, 10.0, 30.0)), "{:?}", bounds(&s, a));
assert!(near(bounds(&s, b), (115.0, 105.0, 10.0, 30.0)), "{:?}", bounds(&s, b));
s.execute("edit.undo", &json!({})).unwrap();
let r = s.execute("addon.arrange.match", &json!({"source": "bottom", "size": "both"})).unwrap();
assert_eq!(r["source"], json!(a.0));
assert!(near(bounds(&s, b), (110.0, 115.0, 20.0, 10.0)), "{:?}", bounds(&s, b));
assert!(near(bounds(&s, c), (195.0, 10.0, 20.0, 10.0)), "{:?}", bounds(&s, c));
s.execute("edit.undo", &json!({})).unwrap();
// "top" names the frontmost even while a key object is set.
s.execute("select.key", &json!({"id": a.0})).unwrap();
let r = s.execute("addon.arrange.match", &json!({"source": "top", "size": "both"})).unwrap();
assert_eq!(r["source"], json!(c.0));
}
#[test]
fn match_turns_the_others_to_the_sources_angle() {
let mut s = session();
let (a, b, c) = three(&mut s);
select(&mut s, &[b]);
s.execute("object.rotate", &json!({"angle": 30})).unwrap();
select(&mut s, &[a, b, c]);
s.execute("select.key", &json!({"id": b.0})).unwrap();
let n = steps(&s);
s.execute("addon.arrange.match", &json!({"rotate": true, "size": "both"})).unwrap();
assert_eq!(steps(&s), n + 1, "one undo step");
for (id, center) in [(a, (10.0, 5.0)), (c, (205.0, 15.0))] {
let o = s.transform_box(&[id]).unwrap();
assert!((o.angle - 30.0).abs() < 1e-6, "{id:?} turned to {}", o.angle);
assert!((o.rect.width() - 40.0).abs() < 1e-6 && (o.rect.height() - 40.0).abs() < 1e-6, "{id:?} sized {:?}", o.rect);
let at = o.center();
assert!((at.x - center.0).abs() < 1e-6 && (at.y - center.1).abs() < 1e-6, "{id:?} turned about its center: {at:?}");
}
// Turned back to the angle of an unturned source.
let d = rect(&mut s, 300.0, 0.0, 10.0, 10.0);
select(&mut s, &[a, d]);
s.execute("addon.arrange.match", &json!({"rotate": true, "source": "top"})).unwrap();
assert!(s.transform_box(&[a]).unwrap().angle.abs() < 1e-6);
}
#[test]
fn match_size_and_rotation_measure_pixel_aligned_art_in_its_final_frame() {
for size in ["width", "height", "both"] {
let mut s = session();
let target = rect(&mut s, 0.0, 0.0, 10.0, 10.0);
select(&mut s, &[target]);
s.execute("object.setPixelAligned", &json!({"on": true})).unwrap();
let source = rect(&mut s, 100.0, 0.0, 10.5, 10.5);
select(&mut s, &[source]);
s.execute("object.rotate", &json!({"angle": 30})).unwrap();
let wanted = s.transform_box(&[source]).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);
let r = s.execute("addon.arrange.match", &json!({"size": size, "rotate": true})).unwrap();
assert_eq!(r, json!({"source": source.0, "count": 1}));
let measured = s.transform_box(&[target]).unwrap();
assert!((measured.angle - wanted.angle).abs() < 1e-6, "{size}: {measured:?}");
assert!((measured.rect.width() - wanted.rect.width()).abs() < 1e-6, "{size}: {measured:?}");
assert!((measured.rect.height() - wanted.rect.height()).abs() < 1e-6, "{size}: {measured:?}");
assert_eq!(steps(&s), n + 1);
s.execute("edit.undo", &json!({})).unwrap();
assert!(*s.doc().unwrap().doc == *before);
}
}
#[test]
fn match_rotation_refuses_a_target_without_bounds_when_its_angle_differs() {
for angle in [0, 30] {
let mut s = session();
let a = rect(&mut s, 0.0, 0.0, 10.0, 10.0);
let target = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap());
select(&mut s, &[a]);
s.execute("edit.clear", &json!({})).unwrap();
let b = rect(&mut s, 100.0, 0.0, 10.0, 10.0);
let source = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap());
s.execute("object.rotate", &json!({"angle": angle})).unwrap();
select(&mut s, &[b]);
s.execute("edit.clear", &json!({})).unwrap();
assert!(s.transform_box(&[target]).is_none());
assert!(s.transform_box(&[source]).is_none());
assert!((s.doc().unwrap().doc.bbox_angle(&[source]) - f64::from(angle)).abs() < 1e-6);
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);
let result = s.execute("addon.arrange.match", &json!({"rotate": true}));
if angle == 0 {
assert_eq!(result.unwrap(), json!({"source": source.0, "count": 1}));
} else {
let error = result.unwrap_err().to_string();
assert!(error.contains(&format!("object {} has no bounds to rotate", target.0)), "{error}");
}
assert_eq!(steps(&s), n);
assert!(*s.doc().unwrap().doc == *before);
}
}
#[test]
fn match_puts_the_others_directly_above_the_source() {
let mut s = session();
let (a, b, c) = three(&mut s);
let d = rect(&mut s, 300.0, 0.0, 10.0, 10.0);
select(&mut s, &[d, a, c]);
s.execute("select.key", &json!({"id": a.0})).unwrap();
let n = steps(&s);
s.execute("addon.arrange.match", &json!({"stacking": true})).unwrap();
assert_eq!(steps(&s), n + 1, "one undo step");
assert_eq!(layer_order(&s), [a, c, d, b], "in the order they had, above the key object");
assert!(near(bounds(&s, c), (200.0, 0.0, 10.0, 30.0)), "nothing else changes");
s.execute("addon.arrange.match", &json!({"stacking": true})).unwrap();
assert_eq!(steps(&s), n + 1, "already above it: no step");
// An object in another layer goes into the source's.
s.execute("layer.new", &json!({})).unwrap();
let e = rect(&mut s, 0.0, 200.0, 10.0, 10.0);
select(&mut s, &[b, e]);
s.execute("select.key", &json!({"id": b.0})).unwrap();
s.execute("addon.arrange.match", &json!({"stacking": true})).unwrap();
assert_eq!(layer_order(&s), [a, c, d, b, e]);
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(layer_order(&s), [a, c, d, b]);
}
#[test]
fn match_makes_no_step_when_everything_matches() {
let mut s = session();
let a = rect(&mut s, 0.0, 0.0, 20.0, 10.0);
let b = rect(&mut s, 100.0, 100.0, 20.0, 10.0);
select(&mut s, &[a, b]);
let n = steps(&s);
let r = s.execute("addon.arrange.match", &json!({"size": "both", "rotate": true})).unwrap();
assert_eq!(r["count"], json!(1));
assert_eq!(steps(&s), n, "the same size and angle: no step");
}
#[test]
fn match_turns_the_others_about_their_reference_point() {
let mut s = session();
let (a, b, c) = three(&mut s);
select(&mut s, &[b]);
s.execute("object.rotate", &json!({"angle": 30})).unwrap();
select(&mut s, &[a, b, c]);
s.execute("select.key", &json!({"id": b.0})).unwrap();
s.execute("addon.arrange.match", &json!({"rotate": true, "reference": 0})).unwrap();
// Each top-left corner stays where it was.
for (id, corner) in [(a, (0.0, 0.0)), (c, (200.0, 0.0))] {
let o = s.transform_box(&[id]).unwrap();
assert!((o.angle - 30.0).abs() < 1e-6, "{id:?} turned to {}", o.angle);
let at = o.to_doc() * vectorcraft_geom::reference_point(o.rect, 0);
assert!((at.x - corner.0).abs() < 1e-6 && (at.y - corner.1).abs() < 1e-6, "{id:?} turned about its top-left corner: {at:?}");
}
}
#[test]
fn match_scales_strokes_as_asked() {
let mut s = session();
let a = rect(&mut s, 0.0, 0.0, 10.0, 10.0);
let b = rect(&mut s, 100.0, 0.0, 20.0, 20.0);
select(&mut s, &[a, b]);
s.execute("paint.setStroke", &json!({"color": "#000000"})).unwrap();
s.execute("stroke.set", &json!({"weight": 2})).unwrap();
let weight = |s: &Session, id| s.doc().unwrap().doc.node(id).unwrap().appearance.stroke_width();
s.execute("addon.arrange.match", &json!({"size": "both"})).unwrap();
assert_eq!(weight(&s, a), 2.0, "off by default (the preference)");
s.execute("edit.undo", &json!({})).unwrap();
s.execute("addon.arrange.match", &json!({"size": "both", "scaleStrokes": true})).unwrap();
assert!((weight(&s, a) - 4.0).abs() < 1e-9, "{}", weight(&s, a));
assert!(near(bounds(&s, a), (-5.0, -5.0, 20.0, 20.0)), "{:?}", bounds(&s, a));
}
/// Running `cmd` with Scale Strokes & Effects on doubles the 2 pt stroke of a 10 pt square, and
/// replaying its journal entry after the preference is turned off scales the stroke the same way.
fn replays_the_stroke_scaling_it_ran_with(cmd: &str, p: Value) {
let mut s = session();
let a = rect(&mut s, 0.0, 0.0, 10.0, 10.0);
let b = rect(&mut s, 100.0, 0.0, 20.0, 20.0);
select(&mut s, &[a, b]);
s.execute("paint.setStroke", &json!({"color": "#000000"})).unwrap();
s.execute("stroke.set", &json!({"weight": 2})).unwrap();
let weight = |s: &Session| s.doc().unwrap().doc.node(a).unwrap().appearance.stroke_width();
s.execute("prefs.set", &json!({"key": "scaleStrokes", "value": true})).unwrap();
s.execute(cmd, &p).unwrap();
assert!((weight(&s) - 4.0).abs() < 1e-9, "{cmd}: {}", weight(&s));
let (id, q) = s.journal.last().unwrap().clone();
assert_eq!(id, cmd);
s.execute("edit.undo", &json!({})).unwrap();
s.execute("prefs.set", &json!({"key": "scaleStrokes", "value": false})).unwrap();
select(&mut s, &[a, b]);
s.replay(&id, &q).unwrap();
assert!((weight(&s) - 4.0).abs() < 1e-9, "{cmd} replayed: {}", weight(&s));
}
#[test]
fn match_stacking_leaves_a_clipping_path_in_place() {
let mut s = session();
let art = rect(&mut s, 0.0, 0.0, 40.0, 40.0);
let mask = rect(&mut s, 10.0, 10.0, 10.0, 10.0);
select(&mut s, &[art, mask]);
s.execute("object.clippingMask.make", &json!({})).unwrap();
let x = rect(&mut s, 200.0, 0.0, 10.0, 10.0);
select(&mut s, &[mask, x]);
s.execute("select.key", &json!({"id": x.0})).unwrap();
refuses(&mut s, "addon.arrange.match", &[json!({"stacking": true})]);
}
#[test]
fn match_size_refuses_a_target_with_no_width() {
let mut s = session();
let line = NodeId(s.execute("shape.line", &json!({"x1": 0, "y1": 0, "x2": 0, "y2": 50})).unwrap()["id"].as_u64().unwrap());
let b = rect(&mut s, 100.0, 0.0, 20.0, 20.0);
select(&mut s, &[line, b]);
s.execute("select.key", &json!({"id": b.0})).unwrap();
refuses(&mut s, "addon.arrange.match", &[json!({"size": "width"}), json!({"size": "both"})]);
// Its height can still take the source's.
s.execute("addon.arrange.match", &json!({"size": "height"})).unwrap();
assert!((bounds(&s, line).height() - 20.0).abs() < 1e-6, "{:?}", bounds(&s, line));
}
#[test]
fn match_size_uses_preview_bounds_for_a_target_with_no_geometric_width() {
let mut s = session();
s.execute("prefs.set", &json!({"key": "usePreviewBounds", "value": true})).unwrap();
let line = NodeId(s.execute("shape.line", &json!({"x1": 0, "y1": 0, "x2": 0, "y2": 50})).unwrap()["id"].as_u64().unwrap());
select(&mut s, &[line]);
s.execute("paint.setStroke", &json!({"color": "#000000"})).unwrap();
s.execute("stroke.set", &json!({"weight": 2, "cap": "butt"})).unwrap();
let b = rect(&mut s, 100.0, 0.0, 2.0, 100.0);
select(&mut s, &[b]);
s.execute("paint.setStroke", &json!({"none": true})).unwrap();
select(&mut s, &[line, b]);
s.execute("select.key", &json!({"id": b.0})).unwrap();
s.execute("addon.arrange.match", &json!({"size": "both", "scaleStrokes": false})).unwrap();
let measured = s.transform_box(&[line]).unwrap().rect;
let wanted = s.transform_box(&[b]).unwrap().rect;
assert!((measured.width() - wanted.width()).abs() < 1e-6, "{measured:?}");
assert!((measured.height() - wanted.height()).abs() < 1e-6, "{measured:?}");
select(&mut s, &[b]);
s.execute("object.setBounds", &json!({"width": 4})).unwrap();
select(&mut s, &[line, b]);
s.execute("select.key", &json!({"id": b.0})).unwrap();
refuses(&mut s, "addon.arrange.match", &[json!({"size": "both", "scaleStrokes": false})]);
}
#[test]
fn match_stacking_takes_a_member_out_of_its_intertwine_group() {
let mut s = session();
let a = rect(&mut s, 0.0, 0.0, 40.0, 40.0);
let b = rect(&mut s, 20.0, 20.0, 40.0, 40.0);
select(&mut s, &[a, b]);
let g = NodeId(s.execute("object.intertwine.make", &json!({})).unwrap()["id"].as_u64().unwrap());
s.execute("object.intertwine.arrange", &json!({"at": [30, 30], "order": "front", "member": a.0})).unwrap();
assert!(s.doc().unwrap().doc.node(a).unwrap().extras().intertwine.is_some(), "a is drawn over b in their overlap");
let c = rect(&mut s, 200.0, 0.0, 10.0, 10.0);
select(&mut s, &[a, c]);
s.execute("select.key", &json!({"id": c.0})).unwrap();
s.execute("addon.arrange.match", &json!({"stacking": true})).unwrap();
let d = &s.doc().unwrap().doc;
assert_ne!(d.parent_of(a), Some(g), "a left the Intertwine group");
let e = d.node(a).unwrap().extras();
assert!(e.intertwine.is_none() && e.intertwine_tiers.is_empty(), "a keeps no Intertwine areas");
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(s.doc().unwrap().doc.parent_of(a), Some(g), "undo puts a back in its group");
}
#[test]
fn match_stacking_needs_no_bounds_on_the_source() {
let mut s = session();
let b = rect(&mut s, 100.0, 0.0, 20.0, 20.0);
let a = rect(&mut s, 0.0, 0.0, 10.0, 10.0);
let g = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap());
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
s.execute("edit.clear", &json!({})).unwrap();
select(&mut s, &[b, g]);
s.execute("select.key", &json!({"id": g.0})).unwrap();
s.execute("addon.arrange.match", &json!({"stacking": true})).unwrap();
assert_eq!(layer_order(&s), [g, b], "b goes directly above the empty group");
}
#[test]
fn match_stacking_refuses_intertwine_nesting_beside_an_empty_group() {
let mut s = session();
let a = rect(&mut s, 0.0, 0.0, 40.0, 40.0);
let source = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap());
let b = rect(&mut s, 20.0, 20.0, 40.0, 40.0);
select(&mut s, &[source, b]);
let parent = NodeId(s.execute("object.intertwine.make", &json!({})).unwrap()["id"].as_u64().unwrap());
select(&mut s, &[a]);
s.execute("edit.clear", &json!({})).unwrap();
assert!(s.transform_box(&[source]).is_none());
assert_eq!(s.doc().unwrap().doc.parent_of(source), Some(parent));
let c = rect(&mut s, 100.0, 0.0, 40.0, 40.0);
let d = rect(&mut s, 120.0, 20.0, 40.0, 40.0);
select(&mut s, &[c, d]);
let target = NodeId(s.execute("object.intertwine.make", &json!({})).unwrap()["id"].as_u64().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);
let error = s.execute("addon.arrange.match", &json!({"stacking": true})).unwrap_err().to_string();
assert!(error.contains("can't be intertwined"), "{error}");
assert_eq!(steps(&s), n);
assert!(*s.doc().unwrap().doc == *before);
}
#[test]
fn match_replays_with_the_stroke_scaling_it_ran_with() {
replays_the_stroke_scaling_it_ran_with("addon.arrange.match", json!({"size": "both"}));
}
#[test]
fn set_size_of_each_replays_with_the_stroke_scaling_it_ran_with() {
replays_the_stroke_scaling_it_ran_with("addon.arrange.size", json!({"width": 20, "height": 20}));
}
#[test]
fn swap_replays_with_the_stroke_scaling_it_ran_with() {
replays_the_stroke_scaling_it_ran_with("addon.arrange.swap", json!({"size": true}));
}
#[test]
fn match_refuses_bad_params() {
let mut s = session();
let (a, _, _) = three(&mut s);
refuses(
&mut s,
"addon.arrange.match",
&[
json!({}),
json!({"size": "none"}),
json!({"size": "area"}),
json!({"size": 1}),
json!({"rotate": 1}),
json!({"stacking": "yes"}),
json!({"size": "both", "reference": 9}),
json!({"size": "both", "reference": 1.5}),
json!({"size": "both", "source": "left"}),
json!({"size": "both", "scaleStrokes": "no"}),
json!({"size": "both", "patterns": 0}),
],
);
let e = s.execute("addon.arrange.match", &json!({"source": "key", "rotate": true})).unwrap_err().to_string();
assert!(e.contains("no key object"), "{e}");
select(&mut s, &[a]);
assert!(!enabled(&s, "addon.arrange.match"), "one object selected");
}
#[test]
fn bad_params_are_refused() {
let mut s = session();
@@ -389,6 +777,7 @@ fn off_without_a_selection() {
"addon.arrange.swap",
"addon.arrange.replace",
"addon.arrange.size",
"addon.arrange.match",
"addon.arrange.groupOverlapping",
"addon.arrange.randomizeOpacity",
"addon.arrange.sort",
@@ -6,6 +6,7 @@
pub(super) const ALLOWED: &[&str] = &[
"addon.arrange.grid",
"addon.arrange.groupOverlapping",
"addon.arrange.match",
"addon.arrange.offset",
"addon.arrange.randomizeOpacity",
"addon.arrange.replace",
+4
View File
@@ -1002,6 +1002,10 @@ fn structured_junk() {
("addon.arrange.replace", json!({"fit": "bounds", "scaleStrokes": true})),
("addon.arrange.size", json!({"width": 1e6, "height": 0.001, "reference": 8, "scaleStrokes": true})),
("addon.arrange.size", json!({"width": 0.001, "proportional": true, "reference": u64::MAX})),
("addon.arrange.match", json!({"size": "both", "rotate": true, "stacking": true, "reference": 8, "scaleStrokes": true})),
("addon.arrange.match", json!({"source": "bottom", "size": "width", "patterns": true})),
("addon.arrange.match", json!({"source": "key", "rotate": true})),
("addon.arrange.match", json!({"source": "nope", "size": 3, "rotate": "x", "reference": u64::MAX})),
("addon.arrange.groupOverlapping", json!({"ids": "x", "junk": f64::MAX})),
("addon.arrange.randomizeOpacity", json!({"min": 0, "max": 100, "seed": u64::MAX})),
("addon.arrange.randomizeOpacity", json!({"min": f64::MAX, "max": -1e308, "seed": -1, "ids": [u64::MAX]})),
+42 -2
View File
@@ -1,5 +1,6 @@
//! Arrange Tools in the interface: its submenu (Object › Plug-ins › Arrange Tools); the dialogs of
//! Arrange in Grid, Offset Objects, Replace with Top Object, Set Size of Each, Randomize Opacity and Sort Objects,
//! Arrange in Grid, Offset Objects, Replace with Top Object, Set Size of Each, Match Objects, Randomize Opacity and
//! Sort Objects,
//! which preview on the canvas and run their `addon.arrange.*` command on OK; Group Overlapping
//! Objects; and Zoom to Selection ([`ZOOM`]), which fits the active view to the selection.
@@ -25,14 +26,16 @@ const GRID: &str = "addon.arrange.grid";
const OFFSET: &str = "addon.arrange.offset";
const REPLACE: &str = "addon.arrange.replace";
const SIZE: &str = "addon.arrange.size";
const MATCH: &str = "addon.arrange.match";
const OPACITY: &str = "addon.arrange.randomizeOpacity";
const SORT: &str = "addon.arrange.sort";
/// Each dialog's command and heading.
const DIALOGS: [(&str, &str); 6] = [
const DIALOGS: [(&str, &str); 7] = [
(GRID, "Arrange in Grid"),
(OFFSET, "Offset Objects"),
(REPLACE, "Replace with Top Object"),
(SIZE, "Set Size of Each"),
(MATCH, "Match Objects"),
(OPACITY, "Randomize Opacity"),
(SORT, "Sort Objects"),
];
@@ -63,6 +66,7 @@ pub fn menu() -> Vec<Node> {
cp("Swap Objects and Sizes", "addon.arrange.swap", json!({ "size": true })),
c("Replace with Top Object…", REPLACE),
c("Set Size of Each…", SIZE),
c("Match Objects…", MATCH),
cp("Group Overlapping Objects", "addon.arrange.groupOverlapping", json!({})),
c("Randomize Opacity…", OPACITY),
c("Sort Objects…", SORT),
@@ -75,6 +79,7 @@ static GRID_SPEC: Spec = Spec { command: GRID, params: grid_params, found: None
static OFFSET_SPEC: Spec = Spec { command: OFFSET, params: offset_params, found: None };
static REPLACE_SPEC: Spec = Spec { command: REPLACE, params: replace_params, found: None };
static SIZE_SPEC: Spec = Spec { command: SIZE, params: size_params, found: None };
static MATCH_SPEC: Spec = Spec { command: MATCH, params: match_params, found: None };
static OPACITY_SPEC: Spec = Spec { command: OPACITY, params: opacity_params, found: None };
static SORT_SPEC: Spec = Spec { command: SORT, params: sort_params, found: None };
@@ -149,6 +154,20 @@ fn size_rows(lengths: LengthUnits) -> Vec<Param> {
]
}
fn match_rows() -> Vec<Param> {
let sources = [("key", "Key Object"), ("top", "Top Object"), ("bottom", "Bottom Object")];
let sizes = [("none", "None"), ("width", "Width"), ("height", "Height"), ("both", "Width and Height")];
vec![
choice("source", "Match To:", &sources, "key"),
choice("size", "Size:", &sizes, "both"),
check("rotate", "Rotation", false),
check("stacking", "Stacking Order", false),
reference_param("reference", tl!("Reference Point")),
scale_strokes().enabled_when_in("size", ["width", "height", "both"]),
check("patterns", "Transform Patterns", false),
]
}
fn opacity_rows() -> Vec<Param> {
vec![percent("min", "Minimum:", 30.0), percent("max", "Maximum:", 100.0), seed()]
}
@@ -192,6 +211,10 @@ fn size_params(fields: &DialogFields) -> Value {
Value::Object(params)
}
fn match_params(fields: &DialogFields) -> Value {
Value::Object(form::json_of(&match_rows(), fields))
}
fn opacity_params(fields: &DialogFields) -> Value {
Value::Object(form::json_of(&opacity_rows(), fields))
}
@@ -205,6 +228,7 @@ pub(crate) fn open(app: &mut VectorcraftApp, id: &str) -> Option<Result<Value, S
let &(command, _) = DIALOGS.iter().find(|(command, _)| *command == id)?;
let st = app.session.active()?;
let strokes = app.session.prefs.scale_strokes;
let key = st.selection.key.is_some();
let lengths = general_lengths(app);
let (rows, opening) = match command {
// A square grid to start with: as many columns as the square root of the count.
@@ -217,6 +241,14 @@ pub(crate) fn open(app: &mut VectorcraftApp, id: &str) -> Option<Result<Value, S
),
OFFSET => (offset_rows(lengths), json!({ "direction": "row", "gap": 10, "order": "stacking", "reverse": false })),
REPLACE => (replace_rows(), json!({ "fit": "keep", "keep": false, "scaleStrokes": strokes })),
// The key object while the selection has one, else the top object.
MATCH => (
match_rows(),
json!({
"source": if key { "key" } else { "top" }, "size": "both", "rotate": false, "stacking": false,
"reference": 4, "scaleStrokes": strokes, "patterns": app.session.prefs.transform_pattern_tiles,
}),
),
// A new seed each time the document has changed, so running it again varies the result.
OPACITY => (opacity_rows(), json!({ "min": 30, "max": 100, "seed": st.revision % SEEDS })),
// The random order's seed (not shown): new whenever the document has changed, so each run
@@ -245,6 +277,14 @@ pub(crate) fn open(app: &mut VectorcraftApp, id: &str) -> Option<Result<Value, S
GRID => super::dialogs::open(app, &GRID_SPEC, fields, move |fields| dialog(GRID, grid_rows(lengths)).values(Bind::bound(fields))),
OFFSET => super::dialogs::open(app, &OFFSET_SPEC, fields, move |fields| dialog(OFFSET, offset_rows(lengths)).values(Bind::bound(fields))),
REPLACE => super::dialogs::open(app, &REPLACE_SPEC, fields, |fields| dialog(REPLACE, replace_rows()).values(Bind::bound(fields))),
MATCH => super::dialogs::open(app, &MATCH_SPEC, fields, move |fields| {
let chosen = fields.text("size").is_some_and(|size| size != "none")
|| fields.bool("rotate") == Some(true)
|| fields.bool("stacking") == Some(true);
let source = key || fields.text("source") != Some("key");
let reason = if source { tl!("Choose Size, Rotation or Stacking Order.") } else { tl!("The selection has no key object.") };
dialog(MATCH, match_rows()).ok_enabled(chosen && source).ok_reason(reason.into()).values(Bind::bound(fields))
}),
OPACITY => super::dialogs::open(app, &OPACITY_SPEC, fields, |fields| {
let (min, max) = (fields.number("min").unwrap_or(0.0), fields.number("max").unwrap_or(100.0));
dialog(OPACITY, opacity_rows()).ok_enabled(min <= max).values(Bind::bound(fields))
@@ -231,6 +231,59 @@ fn set_size_of_each_sets_the_sides_ticked() {
assert_eq!((bounds(&app, b).width(), bounds(&app, b).height()), (30.0, 40.0));
}
fn layer_order(app: &VectorcraftApp) -> Vec<NodeId> {
app.session.doc().unwrap().doc.layers[0].children().unwrap().iter().map(|n| n.id).collect()
}
#[test]
fn real_match_keyboard_edits_preview_confirm_and_cancel() {
let (app, a, b) = app();
let steps = |app: &VectorcraftApp| app.session.doc().unwrap().history.undo.len();
let before = steps(&app);
let mut panel = Harness::new(app, crate::tests::picks::dialogs);
click(&mut panel.app(), "Match Objects…");
panel.frame();
let id = host::dialog_id(&panel.app());
// No key object: it opens on the top object, b, and previews its size on a.
assert_eq!(
host::read(&panel.app(), id, |f| (f.text("source").map(str::to_owned), f.text("size").map(str::to_owned))),
(Some("top".into()), Some("both".into()))
);
assert_eq!(bounds(&panel.app(), a), vectorcraft_geom::Rect::new(-10.0, -15.0, 30.0, 25.0));
panel.focus("Stacking Order");
panel.key(egui::Key::Space, egui::Modifiers::NONE);
panel.frame();
assert_eq!(host::read(&panel.app(), id, |f| f.bool("stacking")), Some(true));
assert_eq!(layer_order(&panel.app()), [b, a], "the preview puts a above b");
panel.click("Cancel");
panel.frame();
{
let app = panel.app();
assert_eq!((bounds(&app, a), layer_order(&app), steps(&app)), (vectorcraft_geom::Rect::new(0.0, 0.0, 20.0, 10.0), vec![a, b], before));
}
click(&mut panel.app(), "Match Objects…");
panel.frame();
let id = host::dialog_id(&panel.app());
host::set(&panel.app(), id, "size", json!("none"));
panel.frame();
assert!(!panel.enabled("OK"), "nothing to match");
host::set(&panel.app(), id, "size", json!("width"));
host::set(&panel.app(), id, "source", json!("key"));
panel.frame();
assert!(!panel.enabled("OK"), "the selection has no key object");
host::set(&panel.app(), id, "source", json!("bottom"));
panel.frame();
assert!(panel.enabled("OK"));
panel.click("OK");
panel.frame();
let app = panel.app();
assert!(!app.any_dialog_open());
// b takes a's width, its height in proportion, as one undo step.
assert_eq!(bounds(&app, b), vectorcraft_geom::Rect::new(110.0, 110.0, 130.0, 130.0));
assert_eq!(bounds(&app, a), vectorcraft_geom::Rect::new(0.0, 0.0, 20.0, 10.0));
assert_eq!(steps(&app), before + 1);
}
#[test]
fn replace_opens_with_the_scale_strokes_preference_and_swap_runs_directly() {
let (mut app, a, b) = app();
+5
View File
@@ -17581,6 +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.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}` |
@@ -17590,6 +17591,9 @@ active view so the selection's visual bounds fill the window with a margin, as `
and fails with nothing selected. Arrange in Grid…, Replace with Top Object…, Set Size of Each…, Randomize Opacity… and Sort Objects… open dialogs
(`ui.menuDialog {command}`, dialog kinds `arrangeGrid`, `arrangeReplace`, `arrangeSize`, `arrangeOpacity` and `arrangeSort`) whose
fields are the command's parameters, with Preview (Randomize Opacity's seed, and Sort Objects' `seed`, which is not shown, start new whenever the document has changed); Set Size of Each's `__width` and `__height` say which sizes OK applies.
Match Objects… opens a dialog of its own in the same way, keyed by its command, whose fields are the command's
parameters, with Preview; it opens on the key object when the selection has one, else on the top object, and OK is
off while nothing is chosen to match or the source is the key object and there is none.
Offset Objects… opens one the same way (`ui.menuDialog {command: "addon.arrange.offset"}`), with Direction, Gap, Order
and Reverse Order.
@@ -17598,6 +17602,7 @@ and Reverse Order.
{"name":"run_command","arguments":{"command":"addon.arrange.offset","params":{"direction":"column","gap":6,"order":"position"}}}
{"name":"run_command","arguments":{"command":"addon.arrange.replace","params":{"fit":"proportional"}}}
{"name":"run_command","arguments":{"command":"addon.arrange.size","params":{"width":72,"proportional":true}}}
{"name":"run_command","arguments":{"command":"addon.arrange.match","params":{"source":"key","size":"both","rotate":true}}}
```
## Document Tools add-on
+4
View File
@@ -3146,6 +3146,10 @@ scaling, replace with each fit and kept originals in stacking order, size with p
undo step, off states, bad params refused), `addons::arrange::tests` in `vectorcraft-ui-egui` (the submenu, the
dialogs, Preview and Cancel, Zoom to Selection) and `command_sweep`. Commands: `docs/mcp.md` › Arrange Tools add-on.
## 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.
## Arrange Tools add-on: Group Overlapping Objects (2026-11-01)
A VectorCraft addition, not a feature of the reference app, so no area score moves. Object › Plug-ins › Arrange Tools › Group Overlapping Objects groups the top-level selected objects wherever their visual bounds overlap or touch, chains included (A overlapping B and B overlapping C makes one group of three), only among objects of the same layer or group; objects that overlap nothing stay as they are, each new group takes its frontmost member's place in the stacking order, and the groups and the loose objects stay selected. One undo step; at most 20000 objects, compared by a sweep along x with union-find. Tests: `group_overlapping_*` in `cmd::addons::arrange::tests` in `vectorcraft-engine` (chains, loners, stacking order, layers kept apart, visual bounds, no step when nothing overlaps, many objects), `group_overlapping_objects_runs_directly` in `vectorcraft-ui-egui` and `command_sweep`. Commands: `docs/mcp.md` › Arrange Tools add-on.
+1
View File
@@ -564,6 +564,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po
| Outline view: a click selects by the outlines drawn, so it reaches a path behind an image (picked on its frame, unless Show Images in Outline Mode draws its pixels) or a gradient mesh (picked on its mesh lines) | done | #6437; in Outline mode the path is selected directly ([Object selection methods and preferences](https://helpx.adobe.com/illustrator/desktop/manage-objects/select-objects/object-selection-methods-and-preferences.html), Object Selection by Path Only). Type, symbol instances, blends, envelopes and placed documents are still picked within their bounds. Tests `outline_mode_picks_paths_through_images_and_meshes`, `outline_view_click_through_an_image_selects_the_path_behind` |
| Outline view draws a linked image or placed document as its box with an X inside, unless Show Images in Outline Mode is on | done | A linked file draws in Outline mode as a box with an X in it, and its contents show only after the Document Setup option Show Images in Outline Mode is turned on ([View artwork](https://helpx.adobe.com/illustrator/using/viewing-artwork.html)). The rest are VectorCraft's own rules. A linked image's frame is crossed from corner to corner, following the corners of a turned or distorted image. An embedded image, and each piece that an envelope cuts an image into, shows its frame alone. A click selects a linked image on its frame, as before, and not on the lines. A placed document shows its box crossed and none of its art, also with raster effects such as a drop shadow and with color adjustments. Effects that change geometry, its own or its group's, reshape the crossed box instead of the file's art, and an envelope holding a placed document distorts its crossed box. Each step of a blend of placed documents is crossed too. With the option on, images show their pixels in gray and placed documents show their art in outline, uncrossed, and the art inside a placed document follows the option of the document it is placed in. Output draws them as before, and so does Preview mode, except in a layer that is not a template and whose Preview is off, which draws them by these rules. In Outline mode, a template layer draws them as Preview mode does. Tests `outline_mode_crosses_a_linked_images_frame_unless_the_setup_shows_images`, `outline_mode_crosses_a_linked_image_with_a_color_mask`, `outline_mode_does_not_cross_the_pieces_of_an_enveloped_linked_image`, `outline_mode_crosses_a_linked_image_moved_into_a_warp_piece`, `outline_mode_crosses_a_turned_or_distorted_linked_image_through_its_corners`, `outline_mode_draws_a_placed_document_as_its_box_crossed_unless_the_setup_shows_images`, `outline_mode_reshapes_the_crossed_box_of_a_placed_document_by_its_groups_effects`, `outline_mode_draws_the_crossed_box_its_effects_move_into_view_after_a_preview_frame`, `outline_mode_warps_an_enveloped_placed_documents_crossed_box`, `outline_mode_draws_each_step_of_a_blend_of_placed_documents_crossed` |
| Arrange Tools add-on (VectorCraft addition): Object › Plug-ins › Arrange Tools runs Arrange in Grid… (grid by row, one row or one column; columns, H and V spacing, Center on Artboard; Preview), Swap Objects, Swap Objects and Sizes, Replace with Top Object… (Actual Size, Bounds or Bounds (Fit Proportionally); Keep Original; Scale Strokes & Effects; Preview), Set Size of Each… (Width and Height each ticked on or off, Constrain Width and Height Proportions with one side, the reference point, Scale Strokes & Effects; Preview) and Zoom to Selection, each one undo step | done | `addon.arrange.*`, `crates/engine/src/cmd/addons/arrange.rs`, `crates/ui-egui/src/addons/arrange.rs` and their tests; not a feature of the reference app, so it is not scored |
| Arrange Tools add-on (VectorCraft addition): Object › Plug-ins › Arrange Tools › Match Objects… gives the other selected objects the size (Width, Height or Width and Height), the bounding-box angle (Rotation) and the stacking place (Stacking Order) of the source, chosen in Match To (Key Object, Top Object, Bottom Object); the reference point, Scale Strokes & Effects, Transform Patterns; Preview; one undo step | done | `addon.arrange.match`, `crates/engine/src/cmd/addons/arrange.rs`, `crates/ui-egui/src/addons/arrange.rs` and their tests; not a feature of the reference app, so it is not scored |
| Arrange Tools add-on (VectorCraft addition): Object › Plug-ins › Arrange Tools › Group Overlapping Objects groups the selected objects whose visual bounds overlap or touch (chains included, within one layer or group), each group at its frontmost member's stacking place, one undo step | done | #4928; `addon.arrange.groupOverlapping`, `crates/engine/src/cmd/addons/arrange.rs` and its tests; not a feature of the reference app, so it is not scored |
| Arrange Tools add-on (VectorCraft addition): Object › Plug-ins › Arrange Tools › Randomize Opacity… gives each selected object its own opacity at random between Minimum and Maximum (%), with a Seed that repeats it and Preview, one undo step | done | #4925; `addon.arrange.randomizeOpacity`, `crates/engine/src/cmd/addons/arrange.rs`, `crates/ui-egui/src/addons/arrange.rs` and their tests; not a feature of the reference app, so it is not scored |
| Arrange Tools add-on (VectorCraft addition): Object › Plug-ins › Arrange Tools › Sort Objects… sorts the selected objects by Sort By (width, height, area, X or Y position, opacity, stacking order) in an Order (Small to Large, Large to Small, Random) and gives them Apply To in that order, trading the values or with Distribute Evenly; Scale Strokes & Effects; Preview; one undo step | done | #4917; `addon.arrange.sort`, `crates/engine/src/cmd/addons/arrange.rs`, `crates/ui-egui/src/addons/arrange.rs` and their tests; not a feature of the reference app, so it is not scored |