mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 18:54:31 +01:00
Merge pull request #10148 from dotCooCoo/feat/corner-marks
Arrange Tools: Mark Bounds of Each draws corner marks or a rectangle on each selected object's bounds
This commit is contained in:
15 files changed
+624
-12
No files matched your search
@@ -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: Mark Bounds of Each joins the Arrange Tools add-on (Object › Plug-ins › Arrange Tools): each selected object gets its own inward corner marks, or a rectangle, on its geometric or visual bounds, stroked in the color and weight given, stacked directly above it; clip groups are measured by their clipping path. A dialog with Preview, one undo step (`addon.arrange.markBounds`). A VectorCraft addition: headline numbers unchanged.
|
||||
- 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.
|
||||
|
||||
@@ -7,9 +7,11 @@
|
||||
//! 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
|
||||
//! (a view command) are the UI's.
|
||||
//! that order. Mark Bounds of Each ([`marks`]) draws marks on the bounds of each selected object.
|
||||
//! Its submenu (Object › Plug-ins › Arrange Tools), its dialogs and Zoom to Selection (a view
|
||||
//! command) are the UI's.
|
||||
|
||||
pub mod marks;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
@@ -127,6 +129,9 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
sort
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.chain(marks::specs())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Exactly two objects are selected (Swap Objects).
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
//! Mark Bounds of Each (`addon.arrange.markBounds`; Object › Plug-ins › Arrange Tools › Mark Bounds
|
||||
//! of Each…): corner marks, or a rectangle, on the bounds of each selected object rather than
|
||||
//! around the whole selection, stroked in a color of their own and stacked directly above the
|
||||
//! object, as one undo step.
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
use vectorcraft_doc::{Appearance, Document, Node, NodeId};
|
||||
use vectorcraft_geom::{PathData, Point, Rect, SubPath, shapes};
|
||||
use vectorcraft_render::drawn_bounds_with;
|
||||
|
||||
use super::super::super::edit::selected_roots;
|
||||
use super::super::super::object::choice;
|
||||
use super::super::super::paint::new_color;
|
||||
use super::super::super::{CommandSpec, bad, cmd, color_param, has_selection};
|
||||
use super::{LEAST, LIMIT, MAX_OBJECTS, number_in};
|
||||
use crate::{Result, Session};
|
||||
|
||||
/// The command.
|
||||
pub const COMMAND: &str = "addon.arrange.markBounds";
|
||||
/// The heaviest stroke (pt) the marks take, and the lightest.
|
||||
const MAX_WEIGHT: f64 = 1000.0;
|
||||
const MIN_WEIGHT: f64 = 0.01;
|
||||
/// A side shorter than this (pt) is no side: its marks are drawn as lines along the other one.
|
||||
const FLAT: f64 = 1e-9;
|
||||
|
||||
pub fn specs() -> Vec<CommandSpec> {
|
||||
vec![cmd!(
|
||||
"addon.arrange.markBounds",
|
||||
"Mark Bounds of Each",
|
||||
["Object", "Plug-ins", "Arrange Tools"],
|
||||
None,
|
||||
"{style?: \"corners\" (an L-shaped mark on each corner, its two legs running inward along the edges) | \"rectangle\" (a rectangle on the bounds) (\"corners\"), bounds?: \"geometric\" (strokes not counted) | \"visual\" (strokes, brush art and effects as drawn) (\"geometric\"), length?: pt 0.001..1000000 (10; corners: each leg's length, at most half the side it runs along), weight?: pt 0.01..1000 (1), color?: color (\"#ff0000\"; an RGB color takes the document's color mode)} draw marks on the bounds of each selected object (the top-level ones, at most 20000) as new art: a group of four corner marks, or one rectangle, with no fill and the stroke given, stacked directly above its object (above the outermost clip group or clipping sublayer that holds it, so the clip does not hide them). A clip group is measured by its clipping path and other groups by their members together. Guides, and objects without bounds such as empty groups, get no marks. The marks are selected; one undo step, and none when nothing gets marks (an error) → {ids: [the new marks…], count}",
|
||||
has_selection,
|
||||
mark_bounds
|
||||
)]
|
||||
}
|
||||
|
||||
/// The four corners of `r`, each with the directions its legs run in (inward), the corners that
|
||||
/// fall on an earlier one left out.
|
||||
fn corners(r: Rect) -> Vec<(Point, f64, f64)> {
|
||||
let mut out: Vec<(Point, f64, f64)> = vec![];
|
||||
for (x, y, sx, sy) in [(r.x0, r.y0, 1.0, 1.0), (r.x1, r.y0, -1.0, 1.0), (r.x1, r.y1, -1.0, -1.0), (r.x0, r.y1, 1.0, -1.0)] {
|
||||
let at = Point::new(x, y);
|
||||
if out.iter().all(|(p, _, _)| (p.x - at.x).abs() > FLAT || (p.y - at.y).abs() > FLAT) {
|
||||
out.push((at, sx, sy));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The corner marks of `r` with legs `length` long, each at most half its side: one open path per
|
||||
/// corner, a line where `r` has no width or no height.
|
||||
fn corner_paths(r: Rect, length: f64) -> Vec<PathData> {
|
||||
let (lx, ly) = (length.min(r.width() / 2.0), length.min(r.height() / 2.0));
|
||||
corners(r)
|
||||
.into_iter()
|
||||
.filter_map(|(p, sx, sy)| {
|
||||
let across = Point::new(p.x + sx * lx, p.y);
|
||||
let down = Point::new(p.x, p.y + sy * ly);
|
||||
let points = match (lx > FLAT, ly > FLAT) {
|
||||
(true, true) => vec![across, p, down],
|
||||
(true, false) => vec![across, p],
|
||||
(false, true) => vec![p, down],
|
||||
(false, false) => return None,
|
||||
};
|
||||
Some(PathData::single(SubPath::polyline(&points, false)))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Where the marks of object `id` go: directly above it, or above the outermost clip group or
|
||||
/// clipping sublayer that holds it at any depth, which would otherwise clip them. A top-level layer
|
||||
/// with a clipping mask holds its marks too, since nothing lies outside it.
|
||||
fn anchor(d: &Document, id: NodeId) -> NodeId {
|
||||
let (mut at, mut outermost) = (id, id);
|
||||
while let Some(up) = d.parent_of(at) {
|
||||
if d.node(up).is_some_and(|n| n.clips()) && d.parent_of(up).is_some() {
|
||||
outermost = up;
|
||||
}
|
||||
at = up;
|
||||
}
|
||||
outermost
|
||||
}
|
||||
|
||||
fn mark_bounds(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const C: &str = COMMAND;
|
||||
let rectangle = choice(p, C, "style", &["corners", "rectangle"])? == Some("rectangle");
|
||||
let visual = choice(p, C, "bounds", &["geometric", "visual"])? == Some("visual");
|
||||
let length = number_in(p, "length", 10.0, (LEAST, LIMIT), C)?;
|
||||
let weight = number_in(p, "weight", 1.0, (MIN_WEIGHT, MAX_WEIGHT), C)?;
|
||||
let color = new_color(s, p, color_param(p, "color", C)?.unwrap_or(Color::rgb(1.0, 0.0, 0.0)));
|
||||
let roots = selected_roots(s)?;
|
||||
if roots.len() > MAX_OBJECTS {
|
||||
return Err(bad(C, "too many objects selected (at most 20000)"));
|
||||
}
|
||||
let d = &s.doc()?.doc;
|
||||
let symbols = d.symbol_boxes();
|
||||
let mut marked: Vec<(NodeId, Rect)> = Vec::with_capacity(roots.len());
|
||||
for id in roots {
|
||||
let Some(n) = d.node(id).filter(|n| !n.is_guide()) else { continue };
|
||||
let bounds = if visual { drawn_bounds_with(&symbols, n) } else { n.geometric_bounds_with(&symbols) };
|
||||
if let Some(r) = bounds.filter(|r| r.width() > FLAT || r.height() > FLAT) {
|
||||
marked.push((anchor(d, id), r));
|
||||
}
|
||||
}
|
||||
if marked.is_empty() {
|
||||
return Err(bad(C, "nothing to mark: the selection has no bounds"));
|
||||
}
|
||||
let ap = Appearance::basic(Paint::None, Paint::solid(color), weight);
|
||||
let ids = s.edit("Mark Bounds of Each", |d, sel| {
|
||||
// Each anchor once, its objects' marks in stacking order from the back.
|
||||
let mut lists: Vec<(NodeId, Vec<Node>)> = vec![];
|
||||
let mut at: HashMap<NodeId, usize> = HashMap::new();
|
||||
let mut out = Vec::with_capacity(marked.len());
|
||||
for (anchor, r) in &marked {
|
||||
let node = if rectangle {
|
||||
let mut n = Node::path(d.alloc_id(), shapes::rectangle(*r), ap.clone());
|
||||
n.name = Some("Bounds".into());
|
||||
n
|
||||
} else {
|
||||
let children = corner_paths(*r, length).into_iter().map(|path| Arc::new(Node::path(d.alloc_id(), path, ap.clone()))).collect();
|
||||
let mut g = Node::group(d.alloc_id(), children);
|
||||
g.name = Some("Corner Marks".into());
|
||||
g
|
||||
};
|
||||
out.push(node.id);
|
||||
let k = *at.entry(*anchor).or_insert_with(|| {
|
||||
lists.push((*anchor, vec![]));
|
||||
lists.len() - 1
|
||||
});
|
||||
if let Some((_, nodes)) = lists.get_mut(k) {
|
||||
nodes.push(node);
|
||||
}
|
||||
}
|
||||
d.insert_beside(lists, false)?;
|
||||
sel.set(out.iter().copied());
|
||||
Ok(out)
|
||||
})?;
|
||||
Ok(json!({ "ids": ids.iter().map(|i| i.0).collect::<Vec<_>>(), "count": ids.len() }))
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
//! Mark Bounds of Each: the marks each object gets, where they go in the stacking order, how
|
||||
//! groups, clip groups, strokes and guides are measured, one undo step, and bad params refused.
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
use vectorcraft_doc::{Node, NodeId};
|
||||
use vectorcraft_geom::Rect;
|
||||
|
||||
use super::COMMAND;
|
||||
use crate::Session;
|
||||
|
||||
/// A new document whose new art has no stroke, so visual and geometric bounds agree.
|
||||
fn session() -> Session {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
s.execute("paint.setStroke", &json!({"none": true})).unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
fn rect(s: &mut Session, x: f64, y: f64, w: f64, h: f64) -> NodeId {
|
||||
NodeId(s.execute("shape.rectangle", &json!({"x": x, "y": y, "width": w, "height": h})).unwrap()["id"].as_u64().unwrap())
|
||||
}
|
||||
|
||||
fn select(s: &mut Session, ids: &[NodeId]) {
|
||||
s.execute("select.set", &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()})).unwrap();
|
||||
}
|
||||
|
||||
fn steps(s: &Session) -> usize {
|
||||
s.doc().unwrap().history.undo.len()
|
||||
}
|
||||
|
||||
fn node(s: &Session, id: NodeId) -> Node {
|
||||
s.doc().unwrap().doc.node(id).unwrap().clone()
|
||||
}
|
||||
|
||||
fn ids_of(v: &Value) -> Vec<NodeId> {
|
||||
v["ids"].as_array().unwrap().iter().map(|i| NodeId(i.as_u64().unwrap())).collect()
|
||||
}
|
||||
|
||||
/// The ids of the children of `parent`, in stacking order from the back.
|
||||
fn children(s: &Session, parent: NodeId) -> Vec<NodeId> {
|
||||
node(s, parent).children().unwrap().iter().map(|n| n.id).collect()
|
||||
}
|
||||
|
||||
fn parent(s: &Session, id: NodeId) -> NodeId {
|
||||
s.doc().unwrap().doc.parent_of(id).unwrap()
|
||||
}
|
||||
|
||||
/// Each path of the mark `id` (a group's members, or the path itself) as its points.
|
||||
fn lines(s: &Session, id: NodeId) -> Vec<Vec<(f64, f64)>> {
|
||||
let n = node(s, id);
|
||||
let paths: Vec<Node> = match n.children() {
|
||||
Some(c) => c.iter().map(|c| (**c).clone()).collect(),
|
||||
None => vec![n],
|
||||
};
|
||||
paths
|
||||
.iter()
|
||||
.map(|p| {
|
||||
let path = p.path_data().unwrap();
|
||||
path.subpaths[0].anchors.iter().map(|a| ((a.p.x * 1e6).round() / 1e6, (a.p.y * 1e6).round() / 1e6)).collect()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn near(a: Rect, b: (f64, f64, f64, f64)) -> bool {
|
||||
[(a.x0, b.0), (a.y0, b.1), (a.x1, b.2), (a.y1, b.3)].iter().all(|(x, y)| (x - y).abs() < 1e-6)
|
||||
}
|
||||
|
||||
fn marks_bounds(s: &Session, id: NodeId) -> Rect {
|
||||
node(s, id).geometric_bounds().unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_object_gets_inward_corner_marks_above_it_in_one_step() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 0.0, 0.0, 100.0, 50.0);
|
||||
let b = rect(&mut s, 200.0, 100.0, 40.0, 40.0);
|
||||
let layer = parent(&s, a);
|
||||
select(&mut s, &[a, b]);
|
||||
let n = steps(&s);
|
||||
let r = s.execute(COMMAND, &json!({})).unwrap();
|
||||
assert_eq!(steps(&s), n + 1, "one undo step");
|
||||
let marks = ids_of(&r);
|
||||
assert_eq!((marks.len(), r["count"].as_u64()), (2, Some(2)));
|
||||
// Directly above each object, not around the selection.
|
||||
assert_eq!(children(&s, layer), vec![a, marks[0], b, marks[1]]);
|
||||
assert_eq!(s.doc().unwrap().selection.objects.to_vec(), marks, "the marks are selected");
|
||||
assert_eq!(node(&s, marks[0]).name.as_deref(), Some("Corner Marks"));
|
||||
assert_eq!(
|
||||
lines(&s, marks[0]),
|
||||
vec![
|
||||
vec![(10.0, 0.0), (0.0, 0.0), (0.0, 10.0)],
|
||||
vec![(90.0, 0.0), (100.0, 0.0), (100.0, 10.0)],
|
||||
vec![(90.0, 50.0), (100.0, 50.0), (100.0, 40.0)],
|
||||
vec![(10.0, 50.0), (0.0, 50.0), (0.0, 40.0)],
|
||||
]
|
||||
);
|
||||
assert!(near(marks_bounds(&s, marks[1]), (200.0, 100.0, 240.0, 140.0)));
|
||||
// A red 1 pt stroke and no fill.
|
||||
let group = node(&s, marks[1]);
|
||||
let ap = &group.children().unwrap()[0].appearance;
|
||||
assert_eq!((ap.fill_paint(), ap.stroke_paint(), ap.stroke_width()), (Paint::None, Paint::solid(Color::rgb(1.0, 0.0, 0.0)), 1.0));
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(children(&s, layer), vec![a, b]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn length_weight_color_and_the_rectangle_style() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 0.0, 0.0, 30.0, 100.0);
|
||||
select(&mut s, &[a]);
|
||||
let r = s.execute(COMMAND, &json!({"length": 40, "weight": 2.5, "color": "#0000ff"})).unwrap();
|
||||
let marks = ids_of(&r);
|
||||
// A leg is never longer than half its side, so opposite marks do not overlap.
|
||||
assert_eq!(lines(&s, marks[0])[0], vec![(15.0, 0.0), (0.0, 0.0), (0.0, 40.0)]);
|
||||
let group = node(&s, marks[0]);
|
||||
let ap = &group.children().unwrap()[0].appearance;
|
||||
assert_eq!((ap.stroke_paint(), ap.stroke_width()), (Paint::solid(Color::rgb(0.0, 0.0, 1.0)), 2.5));
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
let r = s.execute(COMMAND, &json!({"style": "rectangle"})).unwrap();
|
||||
let mark = ids_of(&r)[0];
|
||||
let rect = node(&s, mark);
|
||||
assert!(rect.children().is_none() && rect.path_data().unwrap().subpaths[0].closed, "one closed path");
|
||||
assert_eq!(rect.name.as_deref(), Some("Bounds"));
|
||||
assert!(near(marks_bounds(&s, mark), (0.0, 0.0, 30.0, 100.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_leg_is_at_most_half_the_side_it_runs_along_vertically() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 0.0, 0.0, 200.0, 20.0);
|
||||
select(&mut s, &[a]);
|
||||
let r = s.execute(COMMAND, &json!({"length": 30})).unwrap();
|
||||
assert_eq!(
|
||||
lines(&s, ids_of(&r)[0]),
|
||||
vec![
|
||||
vec![(30.0, 0.0), (0.0, 0.0), (0.0, 10.0)],
|
||||
vec![(170.0, 0.0), (200.0, 0.0), (200.0, 10.0)],
|
||||
vec![(170.0, 20.0), (200.0, 20.0), (200.0, 10.0)],
|
||||
vec![(30.0, 20.0), (0.0, 20.0), (0.0, 10.0)],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn geometric_bounds_leave_strokes_out_and_visual_bounds_count_them() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 0.0, 0.0, 20.0, 20.0);
|
||||
select(&mut s, &[a]);
|
||||
s.execute("paint.setStroke", &json!({"color": "#000000"})).unwrap();
|
||||
s.execute("stroke.set", &json!({"weight": 4})).unwrap();
|
||||
let r = s.execute(COMMAND, &json!({"style": "rectangle"})).unwrap();
|
||||
assert!(near(marks_bounds(&s, ids_of(&r)[0]), (0.0, 0.0, 20.0, 20.0)), "{:?}", marks_bounds(&s, ids_of(&r)[0]));
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
let r = s.execute(COMMAND, &json!({"style": "rectangle", "bounds": "visual"})).unwrap();
|
||||
assert!(near(marks_bounds(&s, ids_of(&r)[0]), (-2.0, -2.0, 22.0, 22.0)), "{:?}", marks_bounds(&s, ids_of(&r)[0]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn visual_bounds_enclose_a_drop_shadow_and_geometric_bounds_leave_it_out() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 50.0, 50.0, 20.0, 20.0);
|
||||
select(&mut s, &[a]);
|
||||
let geometry = marks_bounds(&s, a);
|
||||
let (dx, dy) = (12.0, 8.0);
|
||||
s.execute("effect.apply", &json!({"effect": "stylize.dropShadow", "item": null, "params": {"x": dx, "y": dy, "blur": 0}})).unwrap();
|
||||
let shadow = Rect::new(geometry.x0 + dx, geometry.y0 + dy, geometry.x1 + dx, geometry.y1 + dy);
|
||||
let reach = geometry.union(shadow);
|
||||
let encloses = |r: Rect| r.x0 <= reach.x0 && r.y0 <= reach.y0 && r.x1 >= reach.x1 && r.y1 >= reach.y1;
|
||||
|
||||
let r = s.execute(COMMAND, &json!({"style": "rectangle", "bounds": "geometric"})).unwrap();
|
||||
let geometric = marks_bounds(&s, ids_of(&r)[0]);
|
||||
assert!(near(geometric, (geometry.x0, geometry.y0, geometry.x1, geometry.y1)));
|
||||
assert!(!encloses(geometric), "the geometric mark leaves the shadow outside");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
|
||||
let r = s.execute(COMMAND, &json!({"style": "rectangle", "bounds": "visual"})).unwrap();
|
||||
let visual = marks_bounds(&s, ids_of(&r)[0]);
|
||||
assert!(encloses(visual), "the visual mark encloses the artwork and its shadow: {visual:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn visual_bounds_enclose_brush_art_on_paths_and_in_groups() {
|
||||
for grouped in [false, true] {
|
||||
let mut s = session();
|
||||
let path = NodeId(s.execute("shape.line", &json!({"x1": 50, "y1": 50, "x2": 150, "y2": 50})).unwrap()["id"].as_u64().unwrap());
|
||||
select(&mut s, &[path]);
|
||||
s.execute("paint.setStroke", &json!({"color": "#000000"})).unwrap();
|
||||
s.execute("stroke.set", &json!({"weight": 1})).unwrap();
|
||||
s.execute("brush.apply", &json!({"name": "Dots"})).unwrap();
|
||||
let target = if grouped {
|
||||
s.execute("object.group", &json!({})).unwrap();
|
||||
parent(&s, path)
|
||||
} else {
|
||||
path
|
||||
};
|
||||
select(&mut s, &[target]);
|
||||
let geometry = marks_bounds(&s, path);
|
||||
let d = &s.doc().unwrap().doc;
|
||||
let source = d.node(target).unwrap();
|
||||
let painted = vectorcraft_render::painted_bounds(d, source).unwrap();
|
||||
let drawn = vectorcraft_render::drawn_bounds(d, source).unwrap();
|
||||
let base = vectorcraft_render::effect_bounds(&d.symbol_boxes(), source).unwrap();
|
||||
assert!(drawn.y0 < base.y0 && drawn.y1 > base.y1, "brush art reaches past the base stroke: {drawn:?}, {base:?}");
|
||||
let encloses = |r: Rect| r.x0 <= drawn.x0 && r.y0 <= drawn.y0 && r.x1 >= drawn.x1 && r.y1 >= drawn.y1;
|
||||
|
||||
let r = s.execute(COMMAND, &json!({"style": "rectangle", "bounds": "geometric"})).unwrap();
|
||||
let geometric = marks_bounds(&s, ids_of(&r)[0]);
|
||||
assert!(near(geometric, (geometry.x0, geometry.y0, geometry.x1, geometry.y1)));
|
||||
assert!(!encloses(geometric), "the geometric mark leaves brush art outside");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
|
||||
let r = s.execute(COMMAND, &json!({"style": "rectangle", "bounds": "visual"})).unwrap();
|
||||
let visual = marks_bounds(&s, ids_of(&r)[0]);
|
||||
assert!(near(visual, (drawn.x0, drawn.y0, drawn.x1, drawn.y1)), "the visual mark follows the drawn bounds: {visual:?}, {drawn:?}");
|
||||
assert!(encloses(visual), "the visual mark encloses the brush art: {visual:?}, {drawn:?}");
|
||||
assert!(
|
||||
visual.x0 > painted.x0 && visual.y0 > painted.y0 && visual.x1 < painted.x1 && visual.y1 < painted.y1,
|
||||
"the visual mark stays inside the culling margin: {visual:?}, {painted:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn groups_by_their_members_and_clip_groups_by_the_clipping_path() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 0.0, 0.0, 10.0, 10.0);
|
||||
let b = rect(&mut s, 50.0, 30.0, 10.0, 10.0);
|
||||
select(&mut s, &[a, b]);
|
||||
s.execute("object.group", &json!({})).unwrap();
|
||||
let group = parent(&s, a);
|
||||
let art = rect(&mut s, 100.0, 100.0, 200.0, 150.0);
|
||||
let clip = rect(&mut s, 150.0, 120.0, 50.0, 40.0);
|
||||
select(&mut s, &[art, clip]);
|
||||
s.execute("object.clippingMask.make", &json!({})).unwrap();
|
||||
let clip_group = parent(&s, art);
|
||||
let layer = parent(&s, group);
|
||||
select(&mut s, &[group, clip_group]);
|
||||
let r = s.execute(COMMAND, &json!({"style": "rectangle"})).unwrap();
|
||||
let marks = ids_of(&r);
|
||||
assert!(near(marks_bounds(&s, marks[0]), (0.0, 0.0, 60.0, 40.0)), "the members together");
|
||||
assert!(near(marks_bounds(&s, marks[1]), (150.0, 120.0, 200.0, 160.0)), "the clipping path");
|
||||
assert_eq!(children(&s, layer), vec![group, marks[0], clip_group, marks[1]]);
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
// An object inside the clip group: its marks go above the clip group, where it does not hide them.
|
||||
select(&mut s, &[art]);
|
||||
let r = s.execute(COMMAND, &json!({})).unwrap();
|
||||
let mark = ids_of(&r)[0];
|
||||
assert_eq!(children(&s, layer), vec![group, clip_group, mark]);
|
||||
assert!(near(marks_bounds(&s, mark), (100.0, 100.0, 300.0, 250.0)), "the object's own bounds");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
// And when a plain group lies between the object and the clip group.
|
||||
select(&mut s, &[art]);
|
||||
s.execute("object.group", &json!({})).unwrap();
|
||||
let inner = parent(&s, art);
|
||||
let clip_group = parent(&s, clip);
|
||||
assert_eq!(parent(&s, inner), clip_group);
|
||||
select(&mut s, &[art]);
|
||||
let r = s.execute(COMMAND, &json!({})).unwrap();
|
||||
assert_eq!(children(&s, layer), vec![group, clip_group, ids_of(&r)[0]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marks_go_outside_a_clipping_sublayer_but_stay_in_a_clipping_top_layer() {
|
||||
let mut s = session();
|
||||
let top = s.doc().unwrap().current_layer().unwrap();
|
||||
let sub = NodeId(s.execute("layer.newSublayer", &json!({"parent": top.0})).unwrap()["id"].as_u64().unwrap());
|
||||
s.execute("layer.setCurrent", &json!({"id": sub.0})).unwrap();
|
||||
let art = rect(&mut s, 0.0, 0.0, 100.0, 100.0);
|
||||
rect(&mut s, 20.0, 20.0, 10.0, 10.0);
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
assert!(s.execute("layer.clippingMask.toggle", &json!({"id": sub.0})).unwrap()["clip"].as_bool().unwrap());
|
||||
select(&mut s, &[art]);
|
||||
let r = s.execute(COMMAND, &json!({})).unwrap();
|
||||
assert_eq!(children(&s, top), vec![sub, ids_of(&r)[0]], "above the clipping sublayer");
|
||||
|
||||
// A clipping top-level layer has nothing outside it to hold them: they go above the object.
|
||||
let mut s = session();
|
||||
let top = s.doc().unwrap().current_layer().unwrap();
|
||||
let art = rect(&mut s, 0.0, 0.0, 100.0, 100.0);
|
||||
rect(&mut s, 20.0, 20.0, 10.0, 10.0);
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
assert!(s.execute("layer.clippingMask.toggle", &json!({"id": top.0})).unwrap()["clip"].as_bool().unwrap());
|
||||
select(&mut s, &[art]);
|
||||
let r = s.execute(COMMAND, &json!({})).unwrap();
|
||||
let mark = ids_of(&r)[0];
|
||||
let stack = children(&s, top);
|
||||
assert_eq!(stack.iter().position(|id| *id == mark), stack.iter().position(|id| *id == art).map(|i| i + 1), "{stack:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flat_objects_get_lines_and_guides_and_empty_groups_none() {
|
||||
let mut s = session();
|
||||
let line = NodeId(s.execute("shape.line", &json!({"x1": 0, "y1": 50, "x2": 100, "y2": 50})).unwrap()["id"].as_u64().unwrap());
|
||||
select(&mut s, &[line]);
|
||||
let r = s.execute(COMMAND, &json!({})).unwrap();
|
||||
// No height: one mark at each end, along the line.
|
||||
assert_eq!(lines(&s, ids_of(&r)[0]), vec![vec![(10.0, 50.0), (0.0, 50.0)], vec![(90.0, 50.0), (100.0, 50.0)]]);
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
|
||||
let guide = rect(&mut s, 0.0, 0.0, 20.0, 20.0);
|
||||
select(&mut s, &[guide]);
|
||||
s.execute("view.guides.make", &json!({})).unwrap();
|
||||
select(&mut s, &[guide]);
|
||||
let layer = s.doc().unwrap().target_parent().unwrap();
|
||||
let empty = s
|
||||
.edit("test", |d, _| {
|
||||
let g = Node::group(d.alloc_id(), vec![]);
|
||||
let id = g.id;
|
||||
d.insert(layer, usize::MAX, g)?;
|
||||
Ok(id)
|
||||
})
|
||||
.unwrap();
|
||||
select(&mut s, &[guide, empty]);
|
||||
let (before, n) = (s.doc().unwrap().doc.clone(), steps(&s));
|
||||
let refused = s.execute(COMMAND, &json!({})).unwrap_err().to_string();
|
||||
assert!(refused.contains("nothing to mark"), "{refused}");
|
||||
assert_eq!(steps(&s), n, "no undo step");
|
||||
assert!(*s.doc().unwrap().doc == *before);
|
||||
// With a real object as well, only it gets marks.
|
||||
let a = rect(&mut s, 100.0, 100.0, 20.0, 20.0);
|
||||
select(&mut s, &[guide, empty, a]);
|
||||
let r = s.execute(COMMAND, &json!({})).unwrap();
|
||||
assert_eq!(r["count"], 1);
|
||||
assert!(near(marks_bounds(&s, ids_of(&r)[0]), (100.0, 100.0, 120.0, 120.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bad_params_are_refused_and_it_is_off_without_a_selection() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 0.0, 0.0, 20.0, 10.0);
|
||||
select(&mut s, &[a]);
|
||||
let (before, n) = (s.doc().unwrap().doc.clone(), steps(&s));
|
||||
for p in [
|
||||
json!({"style": "cross"}),
|
||||
json!({"bounds": "preview"}),
|
||||
json!({"length": 0}),
|
||||
json!({"length": 1e7}),
|
||||
json!({"length": "10"}),
|
||||
json!({"weight": 0}),
|
||||
json!({"weight": 1001}),
|
||||
json!({"color": "not a color"}),
|
||||
json!({"color": "#ff000080"}),
|
||||
json!({"color": 3}),
|
||||
] {
|
||||
assert!(s.execute(COMMAND, &p).is_err(), "{p}");
|
||||
}
|
||||
assert_eq!(steps(&s), n);
|
||||
assert!(*s.doc().unwrap().doc == *before);
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
assert!(!s.commands().into_iter().find(|c| c.id == COMMAND).unwrap().enabled);
|
||||
assert!(s.execute(COMMAND, &json!({})).is_err());
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
pub(super) const ALLOWED: &[&str] = &[
|
||||
"addon.arrange.grid",
|
||||
"addon.arrange.groupOverlapping",
|
||||
"addon.arrange.markBounds",
|
||||
"addon.arrange.match",
|
||||
"addon.arrange.offset",
|
||||
"addon.arrange.randomizeOpacity",
|
||||
|
||||
@@ -1042,6 +1042,10 @@ fn structured_junk() {
|
||||
("addon.arrange.sort", json!({"by": "opacity", "apply": "y", "order": "descending", "ids": [u64::MAX]})),
|
||||
("addon.arrange.sort", json!({"by": "x", "apply": "opacity", "distribute": true, "seed": 1e308, "ids": []})),
|
||||
("addon.arrange.sort", json!({"by": "nope", "apply": null, "order": 3, "distribute": "x"})),
|
||||
("addon.arrange.markBounds", json!({"style": "rectangle", "bounds": "visual", "weight": 1000, "color": "cmyk 0 100 100 0"})),
|
||||
("addon.arrange.markBounds", json!({"length": 1e6, "weight": 0.01, "color": [0, 0, 1]})),
|
||||
("addon.arrange.markBounds", json!({"length": f64::MAX, "weight": -1, "color": "#ff000080", "style": 3})),
|
||||
("addon.arrange.markBounds", json!({"length": 1e-308, "bounds": "nope", "color": {"swatch": 1}})),
|
||||
("addon.pathtools.divideDashes", json!({"dash": 1e-308, "gap": -1e308, "fit": "x"})),
|
||||
("addon.pathtools.divideDashes", json!({"dash": 0.01, "gap": 1e6, "fit": true, "removeGaps": false})),
|
||||
("addon.pathtools.divideDashes", json!({"dash": f64::MAX, "gap": [0], "removeGaps": null})),
|
||||
|
||||
@@ -1531,7 +1531,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.menuDialog",
|
||||
"Menu Dialog",
|
||||
"",
|
||||
"{command: object.move|object.rotate|object.scale|object.reflect|object.shear|object.transformEach|path.average|path.averageJoin|object.path.offsetPath|object.path.simplify|object.path.smooth|object.path.splitIntoGrid|object.vectorHalftone|object.stepAndRepeat|artboard.rearrange|artboard.rename|object.envelope.makeWithWarp|object.envelope.resetWithWarp|object.envelope.makeWithMesh|object.envelope.resetWithMesh|object.envelope.options|addon.arrange.grid|addon.arrange.offset|addon.arrange.replace|addon.arrange.size|addon.arrange.match|addon.packaging.setFoldAngle|addon.pathtools.cornerSet|addon.pathtools.divideDashes|addon.pathtools.bridge|addon.pathtools.tangentCircle|addon.type.textTweaker|addon.color.swatchLegend|addon.arrange.randomizeOpacity|addon.arrange.sort|addon.color.applyNearestSwatch|addon.select.byArtboards|addon.select.editPointsOnly|type.smartPunctuation|variable.define|variable.rename|variable.bind|dataset.new|dataset.set|dataset.rename|dataset.select} open the dialog that command's menu item opens (its `key` in ui.inspect is the command id, except `transformEach` for object.transformEach, `envelopeWarp` for object.envelope.makeWithWarp and object.envelope.resetWithWarp, `envelopeMesh` for object.envelope.makeWithMesh and object.envelope.resetWithMesh, `variables` for variable.define and variable.rename and variable.bind and dataset.new and dataset.set and dataset.rename and dataset.select, `envelopeOptions` for object.envelope.options, `smoothSlider` for object.path.smooth, and `simplifySlider` for object.path.simplify; the dialogs of addon.color.applyNearestSwatch and addon.select.byArtboards have no `key`; smoothSlider and simplifySlider are the sliders over the canvas, with field `level`, and object.path.simplify opens its dialog `object.path.simplify` instead once OK in that dialog keeps the settings (`retain`); Set Fold Angle's `angle` is the selected fold lines' angle, and it is refused while the selection has no fold line it can change; Scale and Transform Each have `corners` and `strokes`, from the preferences, which OK updates; Transform Each opens on the values it was last confirmed with (not `copy`), and its Copy button confirms with `copy: true`; the envelope dialogs start from the selected envelope, Make opens as Reset (`reset: true`) while one is selected; variable.rename opens only while the document has a variable, and dataset.set and dataset.rename only while it has a data set, and otherwise the status bar says why; ui.dialog.set, ui.dialog.confirm and ui.dialog.cancel take the dialog's `id` from ui.inspect, or `top`, not its `key`)",
|
||||
"{command: object.move|object.rotate|object.scale|object.reflect|object.shear|object.transformEach|path.average|path.averageJoin|object.path.offsetPath|object.path.simplify|object.path.smooth|object.path.splitIntoGrid|object.vectorHalftone|object.stepAndRepeat|artboard.rearrange|artboard.rename|object.envelope.makeWithWarp|object.envelope.resetWithWarp|object.envelope.makeWithMesh|object.envelope.resetWithMesh|object.envelope.options|addon.arrange.grid|addon.arrange.offset|addon.arrange.replace|addon.arrange.size|addon.arrange.match|addon.packaging.setFoldAngle|addon.pathtools.cornerSet|addon.pathtools.divideDashes|addon.pathtools.bridge|addon.pathtools.tangentCircle|addon.type.textTweaker|addon.color.swatchLegend|addon.arrange.randomizeOpacity|addon.arrange.sort|addon.arrange.markBounds|addon.color.applyNearestSwatch|addon.select.byArtboards|addon.select.editPointsOnly|type.smartPunctuation|variable.define|variable.rename|variable.bind|dataset.new|dataset.set|dataset.rename|dataset.select} open the dialog that command's menu item opens (its `key` in ui.inspect is the command id, except `transformEach` for object.transformEach, `envelopeWarp` for object.envelope.makeWithWarp and object.envelope.resetWithWarp, `envelopeMesh` for object.envelope.makeWithMesh and object.envelope.resetWithMesh, `variables` for variable.define and variable.rename and variable.bind and dataset.new and dataset.set and dataset.rename and dataset.select, `envelopeOptions` for object.envelope.options, `smoothSlider` for object.path.smooth, and `simplifySlider` for object.path.simplify; the dialogs of addon.color.applyNearestSwatch and addon.select.byArtboards have no `key`; smoothSlider and simplifySlider are the sliders over the canvas, with field `level`, and object.path.simplify opens its dialog `object.path.simplify` instead once OK in that dialog keeps the settings (`retain`); Set Fold Angle's `angle` is the selected fold lines' angle, and it is refused while the selection has no fold line it can change; Scale and Transform Each have `corners` and `strokes`, from the preferences, which OK updates; Transform Each opens on the values it was last confirmed with (not `copy`), and its Copy button confirms with `copy: true`; the envelope dialogs start from the selected envelope, Make opens as Reset (`reset: true`) while one is selected; variable.rename opens only while the document has a variable, and dataset.set and dataset.rename only while it has a data set, and otherwise the status bar says why; ui.dialog.set, ui.dialog.confirm and ui.dialog.cancel take the dialog's `id` from ui.inspect, or `top`, not its `key`)",
|
||||
),
|
||||
(
|
||||
"ui.widthPointEdit",
|
||||
|
||||
@@ -61,7 +61,13 @@ pub(crate) fn effect_bounds_with(
|
||||
/// reach of its own and its members' raster effects, measured as [`Node::visual_bounds_with`]
|
||||
/// measures art without effects: what Object › Rasterize makes its image over.
|
||||
pub fn drawn_bounds(doc: &Document, n: &Node) -> Option<Rect> {
|
||||
fx::painted_reach(&doc.symbol_boxes(), n)
|
||||
drawn_bounds_with(&doc.symbol_boxes(), n)
|
||||
}
|
||||
|
||||
/// [`drawn_bounds`] with symbol instances measured by their art in `symbols` (made with
|
||||
/// [`Document::symbol_boxes`]).
|
||||
pub fn drawn_bounds_with(symbols: &SymbolBoxes, n: &Node) -> Option<Rect> {
|
||||
fx::painted_reach(symbols, n)
|
||||
}
|
||||
|
||||
/// For a path or compound path whose own Rasterize effect is followed by Transform effects that
|
||||
|
||||
@@ -294,7 +294,9 @@ mod renderer;
|
||||
mod text_geom;
|
||||
mod threads;
|
||||
|
||||
pub use bounds::{drawn_bounds, drawn_outline, drawn_outlines, effect_bounds, painted_bounds, painted_bounds_with, rasterize_stage};
|
||||
pub use bounds::{
|
||||
drawn_bounds, drawn_bounds_with, drawn_outline, drawn_outlines, effect_bounds, painted_bounds, painted_bounds_with, rasterize_stage,
|
||||
};
|
||||
pub use frame::FrameStats;
|
||||
use frame::{
|
||||
ClipEntry, ClipPaintEntry, Frame, FxArtEntry, GeomEntry, PlacedEntry, PlacedKey, PtrHasher, PtrMap, SliceEntry, StrokeEntry, StrokeKey,
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
//! 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, 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.
|
||||
//! Arrange in Grid, Offset Objects, Replace with Top Object, Set Size of Each, Match Objects, Randomize Opacity,
|
||||
//! Sort Objects and Mark Bounds of Each, 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.
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
@@ -29,8 +28,9 @@ const SIZE: &str = "addon.arrange.size";
|
||||
const MATCH: &str = "addon.arrange.match";
|
||||
const OPACITY: &str = "addon.arrange.randomizeOpacity";
|
||||
const SORT: &str = "addon.arrange.sort";
|
||||
const MARKS: &str = "addon.arrange.markBounds";
|
||||
/// Each dialog's command and heading.
|
||||
const DIALOGS: [(&str, &str); 7] = [
|
||||
const DIALOGS: [(&str, &str); 8] = [
|
||||
(GRID, "Arrange in Grid"),
|
||||
(OFFSET, "Offset Objects"),
|
||||
(REPLACE, "Replace with Top Object"),
|
||||
@@ -38,7 +38,11 @@ const DIALOGS: [(&str, &str); 7] = [
|
||||
(MATCH, "Match Objects"),
|
||||
(OPACITY, "Randomize Opacity"),
|
||||
(SORT, "Sort Objects"),
|
||||
(MARKS, "Mark Bounds of Each"),
|
||||
];
|
||||
/// The mark lengths (pt) Mark Bounds of Each takes, and its stroke weights.
|
||||
const MARK_LENGTHS: std::ops::RangeInclusive<f64> = 0.001..=1e6;
|
||||
const WEIGHTS: std::ops::RangeInclusive<f64> = 0.01..=1000.0;
|
||||
/// The widths and heights Set Size of Each takes (pt), and the gaps Arrange in Grid and Offset Objects take.
|
||||
const SIZES: std::ops::RangeInclusive<f64> = 0.001..=1e6;
|
||||
const GAPS: std::ops::RangeInclusive<f64> = -1e6..=1e6;
|
||||
@@ -70,6 +74,7 @@ pub fn menu() -> Vec<Node> {
|
||||
cp("Group Overlapping Objects", "addon.arrange.groupOverlapping", json!({})),
|
||||
c("Randomize Opacity…", OPACITY),
|
||||
c("Sort Objects…", SORT),
|
||||
c("Mark Bounds of Each…", MARKS),
|
||||
Sep,
|
||||
cp("Zoom to Selection", ZOOM, json!({})),
|
||||
]
|
||||
@@ -82,6 +87,7 @@ 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 };
|
||||
static MARKS_SPEC: Spec = Spec { command: MARKS, params: marks_params, found: None };
|
||||
|
||||
/// The dialog over `rows`, titled by the heading of `command`.
|
||||
fn dialog<'a>(command: &str, rows: Vec<Param>) -> ParamDialog<'a> {
|
||||
@@ -186,6 +192,22 @@ fn sort_rows() -> Vec<Param> {
|
||||
]
|
||||
}
|
||||
|
||||
fn marks_rows(lengths: LengthUnits) -> Vec<Param> {
|
||||
let styles = [("corners", "Corner Marks"), ("rectangle", "Rectangle")];
|
||||
let bounds = [("geometric", "Geometric Bounds"), ("visual", "Visual Bounds")];
|
||||
vec![
|
||||
choice("style", "Draw:", &styles, "corners"),
|
||||
choice("bounds", "Bounds:", &bounds, "geometric"),
|
||||
length("length", "Length:", 10.0, MARK_LENGTHS, lengths).enabled_when("style", "corners"),
|
||||
Param::number("weight", tl!("Weight:"), 1.0, 0.25, 2).bounds(Some(*WEIGHTS.start()), Some(*WEIGHTS.end())).unit(UnitKind::Points),
|
||||
Param::new("color", tl!("Color:"), ParamKind::color(Some([1.0, 0.0, 0.0]))),
|
||||
]
|
||||
}
|
||||
|
||||
fn marks_params(fields: &DialogFields) -> Value {
|
||||
Value::Object(form::json_of(&marks_rows(POINTS), fields))
|
||||
}
|
||||
|
||||
fn grid_params(fields: &DialogFields) -> Value {
|
||||
Value::Object(form::json_of(&grid_rows(POINTS), fields))
|
||||
}
|
||||
@@ -259,6 +281,7 @@ pub(crate) fn open(app: &mut VectorcraftApp, id: &str) -> Option<Result<Value, S
|
||||
"by": "area", "apply": "stacking", "order": "ascending", "distribute": false, "seed": st.revision % SEEDS, "scaleStrokes": strokes,
|
||||
}),
|
||||
),
|
||||
MARKS => (marks_rows(lengths), json!({ "style": "corners", "bounds": "geometric", "length": 10, "weight": 1, "color": "#ff0000" })),
|
||||
// The first selected object's size, as the command measures it (a side it lacks: the least).
|
||||
_ => {
|
||||
let (w, h) = st.selection.objects.first().and_then(|id| app.session.transform_box(&[*id])).map_or((100.0, 100.0), |b| {
|
||||
@@ -290,6 +313,7 @@ pub(crate) fn open(app: &mut VectorcraftApp, id: &str) -> Option<Result<Value, S
|
||||
dialog(OPACITY, opacity_rows()).ok_enabled(min <= max).values(Bind::bound(fields))
|
||||
}),
|
||||
SORT => super::dialogs::open(app, &SORT_SPEC, fields, |fields| dialog(SORT, sort_rows()).values(Bind::bound(fields))),
|
||||
MARKS => super::dialogs::open(app, &MARKS_SPEC, fields, move |fields| dialog(MARKS, marks_rows(lengths)).values(Bind::bound(fields))),
|
||||
_ => super::dialogs::open(app, &SIZE_SPEC, fields, move |fields| {
|
||||
let either = fields.bool("widthOn").unwrap_or(true) || fields.bool("heightOn").unwrap_or(true);
|
||||
dialog(SIZE, size_rows(lengths)).ok_enabled(either).ok_reason(tl!("Tick Width or Height.").into()).values(Bind::bound(fields))
|
||||
|
||||
@@ -322,3 +322,65 @@ fn zoom_to_selection_fits_the_selection_in_the_view() {
|
||||
assert!(!menus::enabled(&app, ZOOM));
|
||||
assert!(app.run(ZOOM, json!({})).is_err());
|
||||
}
|
||||
|
||||
/// The objects of the first layer, from the back.
|
||||
fn layer(app: &VectorcraftApp) -> Vec<NodeId> {
|
||||
app.session.doc().unwrap().doc.layers[0].children().unwrap().iter().map(|n| n.id).collect()
|
||||
}
|
||||
|
||||
/// The points of the first corner mark in the marks group `id`.
|
||||
fn first_mark(app: &VectorcraftApp, id: NodeId) -> Vec<(f64, f64)> {
|
||||
let doc = &app.session.doc().unwrap().doc;
|
||||
let mark = &doc.node(id).unwrap().children().unwrap()[0];
|
||||
mark.path_data().unwrap().subpaths[0].anchors.iter().map(|a| (a.p.x, a.p.y)).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn real_mark_bounds_edits_reach_the_preview_ok_keeps_them_and_cancel_drops_them() {
|
||||
let (app, a, b) = app();
|
||||
let mut panel = Harness::new(app, crate::tests::picks::dialogs);
|
||||
let before = steps(&panel.app());
|
||||
click(&mut panel.app(), "Mark Bounds of Each…");
|
||||
type_number(&mut panel, "Length", "4");
|
||||
let id = host::dialog_id(&panel.app());
|
||||
assert_eq!(host::read(&panel.app(), id, |f| f.number("length")), Some(4.0));
|
||||
// The preview: corner marks directly above each rectangle, their legs 4 pt long.
|
||||
let preview = layer(&panel.app());
|
||||
assert_eq!((preview.len(), preview[0], preview[2]), (4, a, b), "{preview:?}");
|
||||
assert_eq!(first_mark(&panel.app(), preview[1]), vec![(4.0, 0.0), (0.0, 0.0), (0.0, 4.0)]);
|
||||
panel.click("OK");
|
||||
panel.frame();
|
||||
{
|
||||
let app = panel.app();
|
||||
assert!(!app.any_dialog_open());
|
||||
assert_eq!(layer(&app), preview);
|
||||
assert_eq!(steps(&app), before + 1, "one undo step");
|
||||
}
|
||||
panel.app().run("select.set", json!({"ids": [a.0]})).unwrap();
|
||||
click(&mut panel.app(), "Mark Bounds of Each…");
|
||||
type_number(&mut panel, "Length", "2");
|
||||
assert_eq!(layer(&panel.app()).len(), 5, "the preview adds marks above a");
|
||||
panel.click("Cancel");
|
||||
panel.frame();
|
||||
let app = panel.app();
|
||||
assert_eq!(layer(&app), preview, "Cancel takes the preview away");
|
||||
assert_eq!(steps(&app), before + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mark_bounds_sends_the_dialog_values_to_its_command() {
|
||||
let (mut app, a, _) = app();
|
||||
click(&mut app, "Mark Bounds of Each…");
|
||||
let id = host::dialog_id(&app);
|
||||
let opened = host::read(&app, id, |f| (f.text("style").map(str::to_owned), f.text("bounds").map(str::to_owned), f.number("weight")));
|
||||
assert_eq!(opened, (Some("corners".to_owned()), Some("geometric".to_owned()), Some(1.0)));
|
||||
host::set(&app, id, "style", json!("rectangle"));
|
||||
host::set(&app, id, "weight", json!(3));
|
||||
assert!(host::confirm(&app, id));
|
||||
host::frame(&mut app);
|
||||
let marks = layer(&app);
|
||||
let doc = &app.session.doc().unwrap().doc;
|
||||
let rect = doc.node(marks[1]).unwrap();
|
||||
assert_eq!((marks[0], rect.name.as_deref(), rect.appearance.stroke_width()), (a, Some("Bounds"), 3.0));
|
||||
assert_eq!(rect.geometric_bounds().unwrap(), vectorcraft_geom::Rect::new(0.0, 0.0, 20.0, 10.0));
|
||||
}
|
||||
@@ -1532,7 +1532,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.menuDialog",
|
||||
"Menu Dialog",
|
||||
"",
|
||||
"{command: object.move|object.rotate|object.scale|object.reflect|object.shear|object.transformEach|path.average|path.averageJoin|object.path.offsetPath|object.path.simplify|object.path.smooth|object.path.splitIntoGrid|object.vectorHalftone|object.stepAndRepeat|artboard.rearrange|artboard.rename|object.envelope.makeWithWarp|object.envelope.resetWithWarp|object.envelope.makeWithMesh|object.envelope.resetWithMesh|object.envelope.options|addon.arrange.grid|addon.arrange.offset|addon.arrange.replace|addon.arrange.size|addon.arrange.match|addon.packaging.setFoldAngle|addon.pathtools.cornerSet|addon.pathtools.divideDashes|addon.pathtools.bridge|addon.pathtools.tangentCircle|addon.type.textTweaker|addon.color.swatchLegend|addon.arrange.randomizeOpacity|addon.arrange.sort|addon.color.applyNearestSwatch|addon.select.byArtboards|addon.select.editPointsOnly|type.smartPunctuation|variable.define|variable.rename|variable.bind|dataset.new|dataset.set|dataset.rename|dataset.select} open the dialog that command's menu item opens (its `key` in ui.inspect is the command id, except `transformEach` for object.transformEach, `envelopeWarp` for object.envelope.makeWithWarp and object.envelope.resetWithWarp, `envelopeMesh` for object.envelope.makeWithMesh and object.envelope.resetWithMesh, `variables` for variable.define and variable.rename and variable.bind and dataset.new and dataset.set and dataset.rename and dataset.select, `envelopeOptions` for object.envelope.options, `smoothSlider` for object.path.smooth, and `simplifySlider` for object.path.simplify; the dialogs of addon.color.applyNearestSwatch and addon.select.byArtboards have no `key`; smoothSlider and simplifySlider are the sliders over the canvas, with field `level`, and object.path.simplify opens its dialog `object.path.simplify` instead once OK in that dialog keeps the settings (`retain`); Set Fold Angle's `angle` is the selected fold lines' angle, and it is refused while the selection has no fold line it can change; Scale and Transform Each have `corners` and `strokes`, from the preferences, which OK updates; Transform Each opens on the values it was last confirmed with (not `copy`), and its Copy button confirms with `copy: true`; the envelope dialogs start from the selected envelope, Make opens as Reset (`reset: true`) while one is selected; variable.rename opens only while the document has a variable, and dataset.set and dataset.rename only while it has a data set, and otherwise the status bar says why; ui.dialog.set, ui.dialog.confirm and ui.dialog.cancel take the dialog's `id` from ui.inspect, or `top`, not its `key`)",
|
||||
"{command: object.move|object.rotate|object.scale|object.reflect|object.shear|object.transformEach|path.average|path.averageJoin|object.path.offsetPath|object.path.simplify|object.path.smooth|object.path.splitIntoGrid|object.vectorHalftone|object.stepAndRepeat|artboard.rearrange|artboard.rename|object.envelope.makeWithWarp|object.envelope.resetWithWarp|object.envelope.makeWithMesh|object.envelope.resetWithMesh|object.envelope.options|addon.arrange.grid|addon.arrange.offset|addon.arrange.replace|addon.arrange.size|addon.arrange.match|addon.packaging.setFoldAngle|addon.pathtools.cornerSet|addon.pathtools.divideDashes|addon.pathtools.bridge|addon.pathtools.tangentCircle|addon.type.textTweaker|addon.color.swatchLegend|addon.arrange.randomizeOpacity|addon.arrange.sort|addon.arrange.markBounds|addon.color.applyNearestSwatch|addon.select.byArtboards|addon.select.editPointsOnly|type.smartPunctuation|variable.define|variable.rename|variable.bind|dataset.new|dataset.set|dataset.rename|dataset.select} open the dialog that command's menu item opens (its `key` in ui.inspect is the command id, except `transformEach` for object.transformEach, `envelopeWarp` for object.envelope.makeWithWarp and object.envelope.resetWithWarp, `envelopeMesh` for object.envelope.makeWithMesh and object.envelope.resetWithMesh, `variables` for variable.define and variable.rename and variable.bind and dataset.new and dataset.set and dataset.rename and dataset.select, `envelopeOptions` for object.envelope.options, `smoothSlider` for object.path.smooth, and `simplifySlider` for object.path.simplify; the dialogs of addon.color.applyNearestSwatch and addon.select.byArtboards have no `key`; smoothSlider and simplifySlider are the sliders over the canvas, with field `level`, and object.path.simplify opens its dialog `object.path.simplify` instead once OK in that dialog keeps the settings (`retain`); Set Fold Angle's `angle` is the selected fold lines' angle, and it is refused while the selection has no fold line it can change; Scale and Transform Each have `corners` and `strokes`, from the preferences, which OK updates; Transform Each opens on the values it was last confirmed with (not `copy`), and its Copy button confirms with `copy: true`; the envelope dialogs start from the selected envelope, Make opens as Reset (`reset: true`) while one is selected; variable.rename opens only while the document has a variable, and dataset.set and dataset.rename only while it has a data set, and otherwise the status bar says why; ui.dialog.set, ui.dialog.confirm and ui.dialog.cancel take the dialog's `id` from ui.inspect, or `top`, not its `key`)",
|
||||
),
|
||||
(
|
||||
"ui.widthPointEdit",
|
||||
|
||||
+3
-1
@@ -17748,6 +17748,7 @@ as `object.setBounds` measures them (Use Preview Bounds), except Arrange in Grid
|
||||
| `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}` |
|
||||
| `addon.arrange.markBounds` | `style`: `corners`, `rectangle` (`corners`); `bounds`: `geometric` (strokes not counted), `visual` (strokes, brush art and effects as drawn) (`geometric`); `length` pt 0.001…1000000 (10, for `corners`); `weight` pt 0.01…1000 (1); `color` (`#ff0000`; an RGB color takes the document's color mode) | Draws marks on the bounds of each selected object (at most 20000), not around the whole selection: a group named Corner Marks of four L-shaped marks, one on each corner with its two legs running inward along the edges (each leg at most half the side it runs along), or a rectangle named Bounds. The marks have no fill and the stroke given, and go directly above their object, or above the outermost clip group or clipping sublayer that holds it. A clip group is measured by its clipping path and other groups by their members together. Guides and objects without bounds, such as empty groups, get no marks, and a selection with nothing to mark is an error that makes no step. The marks are selected. → `{ids, count}` |
|
||||
|
||||
Zoom to Selection is the UI command `addon.arrange.zoomSelection {}` (remote mode only): it zooms and centres the
|
||||
active view so the selection's visual bounds fill the window with a margin, as `view.fitArtboard` fits the artboard,
|
||||
@@ -17758,7 +17759,8 @@ Match Objects… opens a dialog of its own in the same way, keyed by its command
|
||||
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.
|
||||
and Reverse Order. Mark Bounds of Each… opens a dialog of the command's parameters with Preview; Length is off unless
|
||||
Draw is Corner Marks.
|
||||
|
||||
```json
|
||||
{"name":"run_command","arguments":{"command":"addon.arrange.grid","params":{"columns":4,"gapX":12,"gapY":12}}}
|
||||
|
||||
@@ -3163,6 +3163,10 @@ A VectorCraft addition, not a feature of the reference app, so no area score mov
|
||||
|
||||
A VectorCraft addition, so no area score moves. Object › Plug-ins › Arrange Tools › Offset Objects… chains the top-level selected objects one after another in a row (left to right) or a column (top to bottom) with a gap of −1000000 to 1000000 pt (10 by default; a negative gap overlaps them). The order is the stacking order from the back, or the position (left edges in a row, top edges in a column), and Reverse Order runs it the other way. The first object stays where it is; each later one moves only along the row or column so that it starts the gap past the end of the one before it, and keeps its place across it. Objects are measured by their visual bounds, a clipping group by its mask. One undo step; no step when nothing moves. Tests: `offset_*` in `cmd::addons::arrange::tests` in `vectorcraft-engine` (row and column, both orders and reversed, a negative gap, strokes and clipping groups, no step, locked objects left out, bad params), `real_offset_*` in `vectorcraft-ui-egui` and `command_sweep`. Commands: `docs/mcp.md` › Arrange Tools add-on.
|
||||
|
||||
## Arrange Tools add-on: Mark Bounds of Each (2026-11-29)
|
||||
|
||||
A VectorCraft addition, so no area score moves. Object › Plug-ins › Arrange Tools › Mark Bounds of Each… draws marks on each top-level selected object's bounds (at most 20000 objects), rather than around the whole selection. Draw is Corner Marks by default (four inward L-shaped marks in a group named Corner Marks), or Rectangle (one closed path named Bounds). Bounds is Geometric Bounds by default (strokes not counted), or Visual Bounds (strokes, brush art and effects as drawn). Length is 0.001 to 1000000 pt (10 by default), with each corner leg capped at half the side it runs along; Length is off in the dialog for Rectangle. Weight is 0.01 to 1000 pt (1 by default), and Color defaults to red (`#ff0000`); an RGB color takes the document's color mode. The marks have no fill and the stroke given. Each goes directly above its object, or above the outermost clip group or clipping sublayer that holds it; a clipping top-level layer keeps the marks inside it. Clip groups are measured by their clipping path, other groups by their members together. For flat objects, corner marks become lines along their nonzero side. Guides and objects without bounds, such as empty groups, are skipped; nothing to mark is an error with no undo step. The new marks become selected, in one undo step. The dialog has Preview; OK keeps the marks and Cancel removes the preview. Tests: `each_object_gets_inward_corner_marks_above_it_in_one_step`, `length_weight_color_and_the_rectangle_style`, `a_leg_is_at_most_half_the_side_it_runs_along_vertically`, `geometric_bounds_leave_strokes_out_and_visual_bounds_count_them`, `visual_bounds_enclose_a_drop_shadow_and_geometric_bounds_leave_it_out`, `visual_bounds_enclose_brush_art_on_paths_and_in_groups`, `groups_by_their_members_and_clip_groups_by_the_clipping_path`, `marks_go_outside_a_clipping_sublayer_but_stay_in_a_clipping_top_layer`, `flat_objects_get_lines_and_guides_and_empty_groups_none` and `bad_params_are_refused_and_it_is_off_without_a_selection` in `cmd::addons::arrange::marks::tests` in `vectorcraft-engine`; `real_mark_bounds_edits_reach_the_preview_ok_keeps_them_and_cancel_drops_them` and `mark_bounds_sends_the_dialog_values_to_its_command` in `crates/ui-egui/src/addons/arrange/tests.rs` in `vectorcraft-ui-egui`; and `command_sweep`. Commands: `docs/mcp.md` › Arrange Tools add-on.
|
||||
|
||||
## Type Tools add-on: Text Tweaker (2026-11-03)
|
||||
|
||||
A VectorCraft addition, not a feature of the reference app, so no area score moves. Object › Plug-ins › Type Tools › Text Tweaker… gives one character attribute (size, baseline shift, character rotation, horizontal or vertical scale, tracking, leading or stroke weight) to the selected characters letter by letter, from a start value to an end value along a straight ramp, an ease in and out, a bow, a spike or at random with a seed, while the text stays live and editable (#4924). With Block enabled, a leading ramp sets Line Gap from the first changed character instead of varying leading across the text. Values are set as the Character panel sets them, in its units and ranges, so scaled type takes the sizes shown; spaces and line breaks are skipped unless asked for, each type object gets its own ramp, the range is the Type tool's selection or all the text of the selected type objects, and the run is one undo step from a dialog with Preview. Tests: `cmd::addons::typetools::tests` in `vectorcraft-engine` (each shape, each attribute, skipped spaces, ranges, one ramp per object, seeded random values, scaled type, one undo step, bad params refused), `addons::typetools::tests` in `vectorcraft-ui-egui` (the submenu, the dialog, Preview and Cancel, OK) and `command_sweep`. Commands: `docs/mcp.md` › Type Tools add-on.
|
||||
|
||||
@@ -575,6 +575,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po
|
||||
| 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 |
|
||||
| Arrange Tools add-on (VectorCraft addition): Object › Plug-ins › Arrange Tools › Offset Objects… chains the selected objects one after another in a Direction (Row (Left to Right) or Column (Top to Bottom)) with a Gap (negative overlaps), in an Order (Stacking Order or Position) with Reverse Order; the first stays in place and the others move only along the row or column; Preview; one undo step | done | `addon.arrange.offset`, `crates/engine/src/cmd/addons/arrange.rs`, `crates/ui-egui/src/addons/arrange.rs` and their tests; a VectorCraft addition, so it is not scored |
|
||||
| Arrange Tools add-on (VectorCraft addition): Object › Plug-ins › Arrange Tools › Mark Bounds of Each… draws inward Corner Marks or a Rectangle on each selected object's Geometric Bounds or Visual Bounds, with Length, Weight, Color and Preview; marks go above the object or its outermost clip group or clipping sublayer and become selected; one undo step | done | `addon.arrange.markBounds`, `crates/engine/src/cmd/addons/arrange/marks.rs`, `crates/ui-egui/src/addons/arrange.rs` and their tests; a VectorCraft addition, so it is not scored |
|
||||
| Document Tools add-on (VectorCraft addition): Object › Plug-ins › Document Tools › Save a Timestamped Copy writes `<name>_YYYY-MM-DD_HH-MM.<ext>` next to the document (a folder picked for one never saved), which keeps its path, title and modified state; off on the web | done | #4926; `addon.document.saveTimestampedCopy`, `crates/engine/src/cmd/addons/document.rs`, `crates/ui-egui/src/addons/document.rs` and their tests; not a feature of the reference app, so it is not scored |
|
||||
| Document Tools add-on (VectorCraft addition): Export All Open Documents as PDF / as SVG (#4920) | done | asks for a folder, writes a copy of every open document named after it (taken names numbered, nothing replaced), documents and active tab unchanged; failures named in the status bar |
|
||||
| Document Tools add-on (VectorCraft addition): Object › Plug-ins › Document Tools › Batch Trace Folder asks for a folder of images, then a destination folder, traces each image with a preset (optionally expanded) and saves it there as `.vectorcraft`, `.svg`, `.pdf`, `.ai` or `.eps` under its own name (taken names numbered, nothing replaced), closing each image again; the status bar counts the images traced and those that couldn't be; off on the web | done | #4921; `addon.document.batchTraceFolder`, `crates/engine/src/cmd/addons/document/batch_trace.rs`, `crates/ui-egui/src/addons/document.rs` and their tests; not a feature of the reference app |
|
||||
|
||||
Reference in new issue
Block a user