diff --git a/ROADMAP.md b/ROADMAP.md index d40c33e9e1..fbd5c54036 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -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-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. - 2026-11-22: Add Inscribed Circle joins the Path Precision Tools add-on (Object › Plug-ins › Path Precision Tools): the largest live circle inside each selected closed path or compound path, in the area it fills under its fill rule, with the current paint and one undo step (`addon.pathtools.inscribedCircle`, #6966). A VectorCraft addition: headline numbers unchanged. diff --git a/crates/engine/src/cmd/addons/arrange.rs b/crates/engine/src/cmd/addons/arrange.rs index f81d7a599a..1588ec1162 100644 --- a/crates/engine/src/cmd/addons/arrange.rs +++ b/crates/engine/src/cmd/addons/arrange.rs @@ -2,7 +2,8 @@ //! out in rows and columns, a row or a column; 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 @@ -79,6 +80,15 @@ pub fn specs() -> Vec { 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), 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; to match places, use object.align {to: \"key\"} → {source, count}", + has_multi, + match_objects + ), cmd!( "addon.arrange.groupOverlapping", "Group Overlapping Objects", @@ -313,6 +323,106 @@ fn size(s: &mut Session, p: &Value) -> Result { 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 { + 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 { + 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 = switch_or(p, "scaleStrokes", s.prefs.scale_strokes, 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 = roots.iter().copied().filter(|id| *id != source).collect(); + if targets.is_empty() { + return Err(bad(C, "select at least two objects")); + } + let sb = box_of(s, source)?; + let (w, h) = (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 Some(b) = s.transform_box(&[id]) else { 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 rotate { + // Turned about the reference point, which the sizing keeps in place; angles are + // counter-clockwise and y is down. + let turn = vectorcraft_geom::normalize_deg(angle - s.doc()?.doc.bbox_angle(&[id])); + if turn.abs() > 1e-9 { + let at = b.to_doc() * vectorcraft_geom::reference_point(b.rect, reference as usize); + xf = Affine::rotate_about(-turn.to_radians(), at) * xf; + } + } + 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 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 = 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)?; + } + 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. diff --git a/crates/engine/src/cmd/addons/arrange/tests.rs b/crates/engine/src/cmd/addons/arrange/tests.rs index 759f6f321e..7cf91abfb7 100644 --- a/crates/engine/src/cmd/addons/arrange/tests.rs +++ b/crates/engine/src/cmd/addons/arrange/tests.rs @@ -215,6 +215,186 @@ 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_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)); +} + +#[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(); @@ -261,6 +441,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", diff --git a/crates/engine/src/cmd/plugin_call/reviewed.rs b/crates/engine/src/cmd/plugin_call/reviewed.rs index c2699f219c..4cf43ae92c 100644 --- a/crates/engine/src/cmd/plugin_call/reviewed.rs +++ b/crates/engine/src/cmd/plugin_call/reviewed.rs @@ -6,6 +6,7 @@ pub(super) const ALLOWED: &[&str] = &[ "addon.arrange.grid", "addon.arrange.groupOverlapping", + "addon.arrange.match", "addon.arrange.randomizeOpacity", "addon.arrange.replace", "addon.arrange.size", diff --git a/crates/engine/tests/command_sweep.rs b/crates/engine/tests/command_sweep.rs index 462641b953..93a444a1d9 100644 --- a/crates/engine/tests/command_sweep.rs +++ b/crates/engine/tests/command_sweep.rs @@ -1000,6 +1000,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]})), diff --git a/crates/ui-egui/src/addons/arrange.rs b/crates/ui-egui/src/addons/arrange.rs index a26f5f7a28..6ef3c8e3c1 100644 --- a/crates/ui-egui/src/addons/arrange.rs +++ b/crates/ui-egui/src/addons/arrange.rs @@ -1,5 +1,5 @@ //! Arrange Tools in the interface: its submenu (Object › Plug-ins › Arrange Tools); the dialogs of -//! Arrange in Grid, Replace with Top Object, Set Size of Each, Randomize Opacity and Sort Objects, +//! Arrange in Grid, 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. @@ -24,13 +24,15 @@ pub const ZOOM: &str = "addon.arrange.zoomSelection"; const GRID: &str = "addon.arrange.grid"; 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); 5] = [ +const DIALOGS: [(&str, &str); 6] = [ (GRID, "Arrange in Grid"), (REPLACE, "Replace with Top Object"), (SIZE, "Set Size of Each"), + (MATCH, "Match Objects"), (OPACITY, "Randomize Opacity"), (SORT, "Sort Objects"), ]; @@ -60,6 +62,7 @@ pub fn menu() -> Vec { 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), @@ -71,6 +74,7 @@ pub fn menu() -> Vec { static GRID_SPEC: Spec = Spec { command: GRID, params: grid_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 }; @@ -134,6 +138,20 @@ fn size_rows(lengths: LengthUnits) -> Vec { ] } +fn match_rows() -> Vec { + 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 { vec![percent("min", "Minimum:", 30.0), percent("max", "Maximum:", 100.0), seed()] } @@ -173,6 +191,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)) } @@ -186,6 +208,7 @@ pub(crate) fn open(app: &mut VectorcraftApp, id: &str) -> Option Option (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 @@ -224,6 +255,14 @@ pub(crate) fn open(app: &mut VectorcraftApp, id: &str) -> Option super::dialogs::open(app, &GRID_SPEC, fields, move |fields| dialog(GRID, grid_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)) diff --git a/crates/ui-egui/src/addons/arrange/tests.rs b/crates/ui-egui/src/addons/arrange/tests.rs index 420bfdb01d..da066784f1 100644 --- a/crates/ui-egui/src/addons/arrange/tests.rs +++ b/crates/ui-egui/src/addons/arrange/tests.rs @@ -124,6 +124,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 { + 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(); diff --git a/docs/mcp.md b/docs/mcp.md index d698534089..ae4203a3ce 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -17438,6 +17438,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 does not have, 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}` | @@ -17447,11 +17448,15 @@ 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. ```json {"name":"run_command","arguments":{"command":"addon.arrange.grid","params":{"columns":4,"gapX":12,"gapY":12}}} {"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 diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 032041c2a1..445a68aeeb 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -3144,6 +3144,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. 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. diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 453bda832d..0e7750475b 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -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 |