Merge pull request #8067 from dotCooCoo/feat/align-3d-preview-bounds-1302

Use Preview Bounds: Extrude & Bevel, Revolve, Inflate and Rotate are measured by their 3D art
This commit is contained in:
BFlat
2026-11-17 08:19:29 +07:00
committed by GitHub
5 changed files with 350 additions and 30 deletions
+61 -23
View File
@@ -1,4 +1,4 @@
//! Use Preview Bounds: objects measured as they are drawn, with their geometry effects.
//! Use Preview Bounds: objects measured as they are drawn, with geometry and projected 3D effects.
//!
//! [`drawn_art`] gives an object whose geometry effects change what it draws as plain art. A path
//! or compound path is given as its effected geometry, and a fill or stroke with geometry effects
@@ -11,12 +11,15 @@
//! ([`expanded_live_group`]), with each of those objects given as its own art. A clip group or
//! layer whose clipping path has strokes with geometry effects is given as that path's geometry
//! before its effects, which the renderer clips by, and those strokes as drawn. Fills and
//! strokes that paint nothing (hidden, or painted None) are left out. [`bounds_of`],
//! strokes that paint nothing (hidden, or painted None) are left out. Extrude & Bevel, Revolve,
//! Inflate and Rotate are measured by the same projected vector art the renderer draws, with
//! any geometry effects after projection applied to that art; [`drawn_art`], which clicks and
//! marquees use, leaves 3D effects unprojected. [`bounds_of`],
//! [`oriented_bounds`] and [`anchor_bounds`] measure the visual bounds of that art, strokes
//! included, where [`Document::bounds_of`], [`Document::oriented_bounds`] and
//! [`Selection::anchor_bounds`] measure the objects themselves. Raster effects (shadows, glows,
//! blurs) are not measured. In one object, the art of at most 4,096 symbol instances is measured
//! with its geometry effects, and the other instances in it are measured without them.
//! with its geometry and 3D effects, and the other instances in it are measured without them.
//! [`bounds_of_with`], [`oriented_bounds_with`] and [`anchor_bounds_with`] measure as these do and,
//! with [`Measure::glyphs`], take point type by the ink of its glyphs (Measure Type by Glyph Bounds).
@@ -31,12 +34,12 @@ use vectorcraft_geom::{Affine, PathData, Rect, Shape, union_opt};
use crate::group::has_own_paint;
use crate::reshape::{geometry_effects, leaf_geometry};
use crate::{
GeomContext, apply_geometry_with, evaluate_container, expanded_live_group, has_geometry, has_item_geometry, has_pathfinder, has_transform_art,
needs_outline, outline_art, paints, reshape,
GeomContext, apply_geometry_with, evaluate_container, expanded_live_group, has_geometry, has_item_geometry, has_pathfinder, has_revolve,
has_solid, has_transform_art, needs_outline, outline_art, paints, reshape, revolve_art_in, solid_art_in,
};
/// Most symbol instances in one object whose art [`Drawn`] measures with its geometry effects:
/// past it, the other instances in the object are measured without geometry effects.
/// Most symbol instances in one object whose art [`Drawn`] measures with geometry or 3D effects:
/// past it, the other instances in the object are measured without those effects.
const MAX_INSTANCES: usize = 4096;
/// The bounds of `ids`: with `preview`, their visual bounds as drawn ([`visual_bounds`]), else
@@ -191,8 +194,8 @@ pub fn laid_out_ink(layout: &vectorcraft_text::TextLayout, t: &vectorcraft_doc::
.fold(layout.ink_bounds(), |acc, (_, bar)| union_opt(acc, Some(bar.bounding_box())))
}
/// The visual bounds of `n` as drawn: those of its [`drawn_art`], else
/// [`Node::visual_bounds_with`].
/// The visual bounds of `n` as drawn: those of its [`drawn_art`] with its 3D effects projected,
/// else [`Node::visual_bounds_with`].
pub fn visual_bounds(symbols: &SymbolBoxes, n: &Node) -> Option<Rect> {
Drawn::new(symbols).visual_bounds(n)
}
@@ -204,31 +207,45 @@ pub fn bounds_in(symbols: &SymbolBoxes, n: &Node, a: Affine) -> Option<Rect> {
}
/// `n` as plain art with the geometry effects in it applied, at every depth, symbol instances
/// measured by `symbols`. Raster effects stay on the art. A group, layer or intertwine without a
/// clip is rebuilt with the drawn art of each member that has one. A clip group or layer becomes a
/// group of its clipping path without strokes and the drawn art of the path's strokes, when they
/// have one. `None` when no geometry effect in `n` changes what it draws.
/// measured by `symbols`, for clicks and marquees. Raster effects stay on the art. A group, layer or
/// intertwine without a clip is rebuilt with the drawn art of each member that has one. A clip group
/// or layer becomes a group of its clipping path without strokes and the drawn art of the path's
/// strokes, when they have one. 3D effects stay on the art unprojected, so each object in it keeps
/// its own id. `None` when no geometry effect in `n` changes what it draws.
pub fn drawn_art(symbols: &SymbolBoxes, n: &Node) -> Option<Node> {
Drawn::new(symbols).drawn_art(n)
Drawn::without_3d(symbols).drawn_art(n)
}
/// Whether [`drawn_art`] gives `n` art of its own, or would give one to an object in it. A symbol
/// instance in `n` counts when its symbol's art has a geometry effect.
/// Whether `n` is measured by art of its own with Use Preview Bounds, or an object in it is: a
/// geometry or 3D effect in it changes what it draws. A symbol instance in `n` counts when its
/// symbol's art has geometry or 3D effects.
pub fn draws_geometry(symbols: &SymbolBoxes, n: &Node) -> bool {
Drawn::new(symbols).draws_geometry(n)
}
/// One measurement: whether the art of each symbol checked so far draws geometry, by symbol name,
/// and how many more instances' art it measures with its geometry effects in the current object ([`MAX_INSTANCES`]).
/// One measurement: whether each symbol checked so far draws geometry or 3D art, by symbol name,
/// and how many more instances it measures with those effects in the current object ([`MAX_INSTANCES`]).
/// With `three_d` false, 3D effects are left on the art unprojected ([`drawn_art`]).
struct Drawn<'s, 'd> {
symbols: &'s SymbolBoxes<'d>,
draws: RefCell<HashMap<String, bool>>,
left: Cell<usize>,
three_d: bool,
}
impl<'s, 'd> Drawn<'s, 'd> {
fn new(symbols: &'s SymbolBoxes<'d>) -> Self {
Drawn { symbols, draws: RefCell::default(), left: Cell::new(MAX_INSTANCES) }
Drawn { symbols, draws: RefCell::default(), left: Cell::new(MAX_INSTANCES), three_d: true }
}
/// A measurement that projects no 3D effect, for clicks and marquees ([`drawn_art`]).
fn without_3d(symbols: &'s SymbolBoxes<'d>) -> Self {
Drawn { three_d: false, ..Self::new(symbols) }
}
/// Whether `n` has a 3D effect of its own that this measurement projects.
fn projects(&self, n: &Node) -> bool {
self.three_d && (has_revolve(n) || has_solid(n))
}
/// Sets the count of instances left back to [`MAX_INSTANCES`], for the next object.
@@ -273,6 +290,7 @@ impl<'s, 'd> Drawn<'s, 'd> {
let mut found = false;
n.walk(&mut |c| {
found = found
|| self.projects(c)
|| match &c.kind {
NodeKind::SymbolInstance { symbol, .. } => !geometry_effects(c).is_empty() || self.symbol_draws(symbol),
_ => reshapes(c),
@@ -292,14 +310,29 @@ impl<'s, 'd> Drawn<'s, 'd> {
d
}
/// The art the geometry effects of `n` itself give it, or that a symbol instance gets from the
/// geometry effects in its symbol's art. A group or layer with fills or strokes of its own that
/// The art the geometry or 3D effects of `n` itself give it, or that a symbol instance gets from
/// those effects in its symbol's art, with the instance's appearance overrides applied.
/// A group or layer with fills or strokes of its own that
/// paint, around members with geometry effects, is evaluated too: its fills and strokes paint
/// the members' geometry before their effects. A blend, envelope or repeat whose objects have
/// geometry effects is evaluated as the renderer evaluates it ([`expanded_live_group`]), and
/// the objects in its evaluated art keep their geometry effects. `None` when it has none, and
/// for a symbol instance past [`MAX_INSTANCES`].
fn own_art(&self, n: &Node) -> Option<Node> {
let doc = Some(self.symbols.document());
// A symbol instance with a 3D effect of its own counts toward MAX_INSTANCES before its art is built.
let counted = matches!(n.kind, NodeKind::SymbolInstance { .. }) && self.projects(n);
if counted {
let left = self.left.get().checked_sub(1)?;
self.left.set(left);
}
if self.three_d
&& let Some(art) = revolve_art_in(doc, n).or_else(|| solid_art_in(doc, n))
{
// The builders retain later geometry on the projected group. Measure it after that
// geometry too; item-level effects are handled by the ordinary member traversal.
return Some(self.own_art(&art).unwrap_or(art));
}
let inner = || n.children().is_some_and(|ch| ch.iter().any(|c| self.draws_geometry(c)));
let painted = || has_own_paint(n) && inner();
match &n.kind {
@@ -312,9 +345,14 @@ impl<'s, 'd> Drawn<'s, 'd> {
if geometry_effects(n).is_empty() && !self.symbol_draws(symbol) {
return None;
}
let left = self.left.get().checked_sub(1)?;
self.left.set(left);
if !counted {
let left = self.left.get().checked_sub(1)?;
self.left.set(left);
}
let art = self.symbols.measure_art(symbol, Arc::clone)?;
// Paint overrides can remove a projected surface or change its stroke outline.
let art =
if n.extras().symbol_overrides.is_empty() { art } else { Arc::new(vectorcraft_doc::symbol_overrides::dynamic_art(&art, n)) };
// An instance in perspective is projected by `reshape`.
let doc = Some(self.symbols.document());
reshape(doc, n, Some(&*art)).or_else(|| outline_art(doc, n, Some(&*art)))
+3 -3
View File
@@ -260,7 +260,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Align",
["Window", "Align"],
None,
"{horizontal?: \"left\"|\"center\"|\"right\", vertical?: \"top\"|\"center\"|\"bottom\", to?: \"selection\"|\"artboard\"|\"key\" (default: the key object when the selection has one, select.key, else the selection; a key guide, select.key {guide}, stays put and the objects line up on its line: a vertical guide sets where left, center and right go and vertical alignment leaves them, a horizontal one the other way round; aligning to the key, the other selected ruler guides move too: a vertical guide to the key's left edge, center or right edge, a horizontal one to its top, center or bottom; aligning to the artboard moves selected guides to its edges too (#3463), and with only guides selected aligning to the selection moves them to their collective bounds), artboard?: index (0-based; with to: \"artboard\", the artboard to align to; the app passes the active one; default: the artboard under the center of the selection, else the first), bounds?: \"preview\"|\"geometric\" (default: the Use Preview Bounds preference; preview bounds take in strokes), patterns?: bool (Transform Patterns: pattern fills and strokes transform with the art; default: prefs transformPatternTiles)} With anchor points selected (Direct Selection), the points align instead: to their own bounds, to the artboard (#1180), or, aligning to the key with a key anchor (select.key {id, anchor}), to the key anchor, which stays put",
"{horizontal?: \"left\"|\"center\"|\"right\", vertical?: \"top\"|\"center\"|\"bottom\", to?: \"selection\"|\"artboard\"|\"key\" (default: the key object when the selection has one, select.key, else the selection; a key guide, select.key {guide}, stays put and the objects line up on its line: a vertical guide sets where left, center and right go and vertical alignment leaves them, a horizontal one the other way round; aligning to the key, the other selected ruler guides move too: a vertical guide to the key's left edge, center or right edge, a horizontal one to its top, center or bottom; aligning to the artboard moves selected guides to its edges too (#3463), and with only guides selected aligning to the selection moves them to their collective bounds), artboard?: index (0-based; with to: \"artboard\", the artboard to align to; the app passes the active one; default: the artboard under the center of the selection, else the first), bounds?: \"preview\"|\"geometric\" (default: the Use Preview Bounds preference; preview bounds take in strokes, geometry effects and projected 3D art), patterns?: bool (Transform Patterns: pattern fills and strokes transform with the art; default: prefs transformPatternTiles)} With anchor points selected (Direct Selection), the points align instead: to their own bounds, to the artboard (#1180), or, aligning to the key with a key anchor (select.key {id, anchor}), to the key anchor, which stays put",
has_selection_or_guides,
align
),
@@ -269,7 +269,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Distribute",
["Window", "Align"],
None,
"{horizontal?: \"left\"|\"center\"|\"right\", vertical?: \"top\"|\"center\"|\"bottom\", spacing?: pt (used with a key, select.key: the key object, or the key guide, select.key {guide}, stays put and the lines are placed this far apart, outward from its line, in their order on that line; 0 puts them all on its line; a key guide along the axis leaves everything where it is; not used without a key, or with anchor points selected and no key anchor), to?: \"selection\"|\"artboard\"|\"key\" (default: the key while there is one, else the selection; \"key\" without spacing distributes as \"selection\" does; with anchor points selected, with \"selection\" or \"artboard\" the key anchor is not the key and all the points are spaced as without one; not used with spacing and a key object; with a key guide, \"selection\" or \"artboard\" distributes without it as the key), artboard?: index (0-based; with to: \"artboard\", the artboard to distribute across; the app passes the active one; default: as object.align's), bounds?: \"preview\"|\"geometric\" (default: the Use Preview Bounds preference; preview bounds take in strokes), patterns?: bool (Transform Patterns: pattern fills and strokes transform with the art; default: prefs transformPatternTiles)} space the selected objects' left edges, centers or right edges (top edges, centers or bottom edges) in their order on that line, with the selected ruler guides across the axis (vertical ones for horizontal; #1597): a guide has no size, so its edges and center are its line, and guides along the axis stay. Without spacing and a key they are spaced evenly, the first and last stay put, and fewer than three don't move; with spacing and a key, see spacing (two are enough); with to: \"artboard\", the first one's left (top) edge goes to the artboard's left (top) edge, the last one's right (bottom) edge goes to the artboard's right (bottom) edge, and two are enough. With anchor points selected (Direct Selection), the points are spaced evenly between the first and the last along the axis instead (#1636); with spacing and a key anchor (select.key {id, anchor}), the key anchor stays put and the others are placed spacing apart, outward from it, in their order along the axis",
"{horizontal?: \"left\"|\"center\"|\"right\", vertical?: \"top\"|\"center\"|\"bottom\", spacing?: pt (used with a key, select.key: the key object, or the key guide, select.key {guide}, stays put and the lines are placed this far apart, outward from its line, in their order on that line; 0 puts them all on its line; a key guide along the axis leaves everything where it is; not used without a key, or with anchor points selected and no key anchor), to?: \"selection\"|\"artboard\"|\"key\" (default: the key while there is one, else the selection; \"key\" without spacing distributes as \"selection\" does; with anchor points selected, with \"selection\" or \"artboard\" the key anchor is not the key and all the points are spaced as without one; not used with spacing and a key object; with a key guide, \"selection\" or \"artboard\" distributes without it as the key), artboard?: index (0-based; with to: \"artboard\", the artboard to distribute across; the app passes the active one; default: as object.align's), bounds?: \"preview\"|\"geometric\" (default: the Use Preview Bounds preference; preview bounds take in strokes, geometry effects and projected 3D art), patterns?: bool (Transform Patterns: pattern fills and strokes transform with the art; default: prefs transformPatternTiles)} space the selected objects' left edges, centers or right edges (top edges, centers or bottom edges) in their order on that line, with the selected ruler guides across the axis (vertical ones for horizontal; #1597): a guide has no size, so its edges and center are its line, and guides along the axis stay. Without spacing and a key they are spaced evenly, the first and last stay put, and fewer than three don't move; with spacing and a key, see spacing (two are enough); with to: \"artboard\", the first one's left (top) edge goes to the artboard's left (top) edge, the last one's right (bottom) edge goes to the artboard's right (bottom) edge, and two are enough. With anchor points selected (Direct Selection), the points are spaced evenly between the first and the last along the axis instead (#1636); with spacing and a key anchor (select.key {id, anchor}), the key anchor stays put and the others are placed spacing apart, outward from it, in their order along the axis",
can_distribute,
distribute
),
@@ -278,7 +278,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Distribute Spacing",
["Window", "Align"],
None,
"{axis?: \"horizontal\"|\"vertical\" (default: \"horizontal\"), spacing?: pt (the key object, select.key, or the key guide, select.key {guide}, stays put and the others are spaced from it; a key guide along the axis leaves everything where it is), to?: \"selection\"|\"artboard\"|\"key\" (used without spacing, and with a key guide; with anchor points selected, with \"selection\" or \"artboard\" the key anchor is not the key and all the points are spaced as without one; default: the key while there is one, else the selection; \"key\" without spacing spaces as \"selection\" does), artboard?: index (0-based; with to: \"artboard\", the artboard to space across; the app passes the active one; default: as object.align's), bounds?: \"preview\"|\"geometric\" (default: the Use Preview Bounds preference; preview bounds take in strokes), patterns?: bool (Transform Patterns: pattern fills and strokes transform with the art; default: prefs transformPatternTiles)} without spacing, make the gaps between the selected objects equal, in the order of their left (top) edges, with the selected ruler guides across the axis as items with no size (#1597; guides along the axis stay): the first item's left (top) edge and the last one's right (bottom) edge stay put, or with to: \"artboard\" go to the artboard's left (top) and right (bottom) edges. With anchor points selected (Direct Selection), the points are spaced evenly along the axis instead, or `spacing` apart from the first (#1636), or with a key anchor (select.key {id, anchor}) `spacing` apart outward from the key anchor, which stays put",
"{axis?: \"horizontal\"|\"vertical\" (default: \"horizontal\"), spacing?: pt (the key object, select.key, or the key guide, select.key {guide}, stays put and the others are spaced from it; a key guide along the axis leaves everything where it is), to?: \"selection\"|\"artboard\"|\"key\" (used without spacing, and with a key guide; with anchor points selected, with \"selection\" or \"artboard\" the key anchor is not the key and all the points are spaced as without one; default: the key while there is one, else the selection; \"key\" without spacing spaces as \"selection\" does), artboard?: index (0-based; with to: \"artboard\", the artboard to space across; the app passes the active one; default: as object.align's), bounds?: \"preview\"|\"geometric\" (default: the Use Preview Bounds preference; preview bounds take in strokes, geometry effects and projected 3D art), patterns?: bool (Transform Patterns: pattern fills and strokes transform with the art; default: prefs transformPatternTiles)} without spacing, make the gaps between the selected objects equal, in the order of their left (top) edges, with the selected ruler guides across the axis as items with no size (#1597; guides along the axis stay): the first item's left (top) edge and the last one's right (bottom) edge stay put, or with to: \"artboard\" go to the artboard's left (top) and right (bottom) edges. With anchor points selected (Direct Selection), the points are spaced evenly along the axis instead, or `spacing` apart from the first (#1636), or with a key anchor (select.key {id, anchor}) `spacing` apart outward from the key anchor, which stays put",
can_distribute,
distribute_spacing
),
+279 -1
View File
@@ -1,5 +1,5 @@
//! Use Preview Bounds: the Transform panel values, the bounding box, Align and Distribute measure
//! visual bounds (strokes and geometry effects included) when it is on.
//! visual bounds (strokes, geometry and projected 3D effects included) when it is on.
use std::sync::Arc;
@@ -103,6 +103,284 @@ fn near(a: Rect, b: Rect, tolerance: f64) -> bool {
[(a.x0, b.x0), (a.y0, b.y0), (a.x1, b.x1), (a.y1, b.y1)].iter().all(|(x, y)| (x - y).abs() <= tolerance)
}
const PREVIEW_3D: [&str; 4] = ["threeD.extrude", "threeD.revolve", "threeD.inflate", "threeD.rotate"];
/// A live projected rectangle, with the effect on the object or its painted fill.
fn projected_rect(s: &mut Session, effect: &str, item: bool) -> NodeId {
let id = rect(s, 100.0, 80.0, 0.0);
run(s, "effect.apply", json!({"ids": [id.0], "effect": effect, "params": params_3d(effect), "item": if item { json!(0) } else { Value::Null }}));
id
}
/// Settings for `effect` that turn the art and give it depth.
fn params_3d(effect: &str) -> Value {
let mut params = json!({"rotationX": -20, "rotationY": 35, "rotationZ": 15, "perspectiveAngle": 0, "shade": false});
match effect {
"threeD.revolve" => {
params["segments"] = json!(8);
params["angle"] = json!(240);
params["offset"] = json!(12);
}
"threeD.extrude" => {
params["depth"] = json!(40);
params["bevel"] = json!("rounded");
}
"threeD.inflate" => params["depth"] = json!(20),
_ => {}
}
params
}
/// Measure the renderer's projected vector art, including any geometry effects left after 3D.
fn projected(s: &Session, id: NodeId) -> Rect {
let d = &s.doc().unwrap().doc;
let n = d.node(id).unwrap();
let art = vectorcraft_render::effects::revolve_art(n).or_else(|| vectorcraft_render::effects::solid_art(n)).unwrap();
vectorcraft_render::effects::preview::visual_bounds(&d.symbol_boxes(), &art).unwrap()
}
/// All four projected effects contribute at object and item scope; off and hidden keep source bounds.
#[test]
fn preview_3d_measures_the_projected_art_at_object_and_item_scope() {
for effect in PREVIEW_3D {
for item in [false, true] {
let mut s = session();
let id = projected_rect(&mut s, effect, item);
let expected = projected(&s, id);
let source = geometric(&s, id);
assert!(!near(expected, source, 1e-3), "the fixture must change its bounds: {effect}");
preview(&mut s, true);
assert!(near(s.transform_bounds(&[id]).unwrap(), expected, 1e-6), "{effect}, item={item}");
preview(&mut s, false);
assert_eq!(s.transform_bounds(&[id]), Some(source));
preview(&mut s, true);
run(&mut s, "effect.setParams", json!({"ids": [id.0], "index": 0, "item": if item { json!(0) } else { Value::Null }, "visible": false}));
assert_eq!(s.transform_bounds(&[id]), Some(source), "hidden {effect}, item={item}");
}
}
}
/// Align and spacing use projected edges, with one undo step and no repeat-alignment edit.
#[test]
fn preview_3d_align_and_spacing_measure_projected_edges() {
for effect in PREVIEW_3D {
let mut s = session();
let a = projected_rect(&mut s, effect, false);
let b = rect(&mut s, 20.0, 30.0, 0.0);
preview(&mut s, true);
run(&mut s, "select.set", json!({"ids": [a.0, b.0]}));
let before = s.doc().unwrap().doc.clone();
let history = s.doc().unwrap().history.undo.len();
run(&mut s, "object.align", json!({"horizontal": "left"}));
assert!((projected(&s, a).x0 - geometric(&s, b).x0).abs() < 1e-6, "{effect}");
assert_eq!(s.doc().unwrap().history.undo.len(), history + 1);
let aligned = s.doc().unwrap().doc.clone();
run(&mut s, "object.align", json!({"horizontal": "left"}));
assert_eq!(s.doc().unwrap().history.undo.len(), history + 1, "already aligned {effect}");
assert_eq!(s.doc().unwrap().doc, aligned);
run(&mut s, "edit.undo", json!({}));
assert_eq!(s.doc().unwrap().doc, before);
run(&mut s, "edit.redo", json!({}));
assert_eq!(s.doc().unwrap().doc, aligned);
let mut s = session();
let a = projected_rect(&mut s, effect, false);
let b = rect(&mut s, 350.0, 30.0, 0.0);
preview(&mut s, true);
run(&mut s, "select.set", json!({"ids": [a.0, b.0]}));
let before = s.doc().unwrap().doc.clone();
run(&mut s, "object.distributeSpacing", json!({"axis": "horizontal", "spacing": 0}));
assert!((projected(&s, a).x1 - geometric(&s, b).x0).abs() < 1e-6, "{effect}");
run(&mut s, "edit.undo", json!({}));
assert_eq!(s.doc().unwrap().doc, before);
}
}
/// A group's and a symbol's projected members are measured as art rather than flat source paths.
#[test]
fn preview_3d_measures_projected_group_and_symbol_members() {
for effect in PREVIEW_3D {
let mut source = session();
let source_id = projected_rect(&mut source, effect, false);
let expected = projected(&source, source_id);
let mut d = Document::new(600.0, 400.0);
let mut shape = source.doc().unwrap().doc.node(source_id).unwrap().clone();
shape.id = d.alloc_id();
let group = Node::group(d.alloc_id(), vec![Arc::new(shape.clone())]);
let group_id = group.id;
let layer = d.layers[0].id;
d.insert(Some(layer), 0, group).unwrap();
shape.id = d.alloc_id();
d.symbols.push(Symbol { dynamic: false, name: "3D / Bounds".into(), art: Arc::new(shape) });
let shift = Affine::translate((250.0, 0.0));
let instance = Node::new(d.alloc_id(), NodeKind::SymbolInstance { symbol: "3D / Bounds".into(), xf: shift });
let instance_id = instance.id;
d.insert(Some(layer), 1, instance).unwrap();
let mut s = Session::new();
s.add_document(d, None);
preview(&mut s, true);
assert!(near(s.transform_bounds(&[group_id]).unwrap(), expected, 1e-6), "group {effect}");
assert!(near(s.transform_bounds(&[instance_id]).unwrap(), shift.transform_rect_bbox(expected), 1e-6), "symbol {effect}");
}
}
/// A symbol instance with a 3D effect of its own is measured by the art the renderer projects from its symbol.
#[test]
fn preview_3d_measures_an_instance_with_its_own_effect() {
for effect in PREVIEW_3D {
let mut d = Document::new(600.0, 400.0);
let square = Node::path(
d.alloc_id(),
shapes::rectangle(Rect::new(0.0, 0.0, 100.0, 80.0)),
Appearance::basic(Paint::solid(Color::BLACK), Paint::None, 0.0),
);
d.symbols.push(Symbol { dynamic: false, name: "3D / Own".into(), art: Arc::new(square) });
let instance = Node::new(d.alloc_id(), NodeKind::SymbolInstance { symbol: "3D / Own".into(), xf: Affine::translate((50.0, 40.0)) });
let (layer, id) = (d.layers[0].id, instance.id);
d.insert(Some(layer), 0, instance).unwrap();
let mut s = Session::new();
s.add_document(d, None);
run(&mut s, "effect.apply", json!({"ids": [id.0], "effect": effect, "params": params_3d(effect)}));
let d = &s.doc().unwrap().doc;
let n = d.node(id).unwrap();
let art = vectorcraft_render::effects::revolve_art_in(Some(d), n).or_else(|| vectorcraft_render::effects::solid_art_in(Some(d), n)).unwrap();
let expected = vectorcraft_render::effects::preview::visual_bounds(&d.symbol_boxes(), &art).unwrap();
let source = geometric(&s, id);
assert!(!near(expected, source, 1e-3), "the fixture must change its bounds: {effect}");
preview(&mut s, true);
assert!(near(s.transform_bounds(&[id]).unwrap(), expected, 1e-6), "{effect}");
}
}
/// Dynamic instance overrides are applied before deciding which painted 3D surfaces remain.
#[test]
fn preview_3d_dynamic_symbol_overrides_precede_projection() {
for effect in PREVIEW_3D {
let mut source = session();
let source_id = projected_rect(&mut source, effect, false);
let full = projected(&source, source_id);
let mut d = Document::new(600.0, 400.0);
let mut art = source.doc().unwrap().doc.node(source_id).unwrap().clone();
art.id = d.alloc_id();
d.symbols.push(Symbol { dynamic: true, name: "3D / Dynamic".into(), art: Arc::new(art) });
let mut instance = Node::new(d.alloc_id(), NodeKind::SymbolInstance { symbol: "3D / Dynamic".into(), xf: Affine::IDENTITY });
instance
.extras_mut()
.symbol_overrides
.push(vectorcraft_doc::symbol_overrides::SymbolOverride { fill: Some(Paint::None), ..Default::default() });
let id = instance.id;
let changed = vectorcraft_doc::symbol_overrides::dynamic_art(&d.symbols[0].art, &instance);
let expected = vectorcraft_render::effects::preview::visual_bounds(&d.symbol_boxes(), &changed);
if effect == "threeD.extrude" {
assert!(expected.is_some(), "the Extrude fixture must retain its source bounds");
}
assert!(expected.is_none_or(|b| !near(b, full, 1e-3)), "the override must remove the projected surface: {effect}");
let layer = d.layers[0].id;
d.insert(Some(layer), 0, instance).unwrap();
let mut s = Session::new();
s.add_document(d, None);
preview(&mut s, true);
let actual = s.transform_bounds(&[id]);
assert!(
match (actual, expected) {
(Some(a), Some(b)) => near(a, b, 1e-6),
(None, None) => true,
_ => false,
},
"overridden {effect}: {actual:?}, expected {expected:?}"
);
run(&mut s, "symbol.instance.reset", json!({"ids": [id.0]}));
assert!(near(s.transform_bounds(&[id]).unwrap(), full, 1e-6), "reset {effect}");
}
}
/// Geometry after projection remains part of the measured stack at object and item scope.
#[test]
fn preview_3d_applies_geometry_after_the_projected_surface() {
for effect in PREVIEW_3D {
for item in [false, true] {
let mut s = session();
let id = projected_rect(&mut s, effect, item);
run(
&mut s,
"effect.apply",
json!({"ids": [id.0], "effect": "path.offsetPath", "params": {"offset": 5}, "item": if item { json!(0) } else { Value::Null }}),
);
let expected = projected(&s, id);
preview(&mut s, true);
assert!(near(s.transform_bounds(&[id]).unwrap(), expected, 1e-6), "{effect}, item={item}");
}
}
}
/// Typed width sizes the projected art and remains one undoable edit.
#[test]
fn preview_3d_set_bounds_sizes_the_projected_width() {
for effect in PREVIEW_3D {
let mut s = session();
let id = projected_rect(&mut s, effect, false);
let target = projected(&s, id).width() * 1.25;
preview(&mut s, true);
let before = s.doc().unwrap().doc.clone();
let history = s.doc().unwrap().history.undo.len();
run(&mut s, "object.setBounds", json!({"width": target, "reference": 0, "proportional": true, "strokes": false}));
assert!((projected(&s, id).width() - target).abs() < 1e-4, "{effect}: {:?}, target {target}", projected(&s, id));
assert_eq!(s.doc().unwrap().history.undo.len(), history + 1);
run(&mut s, "edit.undo", json!({}));
assert_eq!(s.doc().unwrap().doc, before);
}
}
/// A rotated selection measures the projected surface in its own bounding-box frame.
#[test]
fn preview_3d_oriented_box_follows_projected_art() {
for effect in PREVIEW_3D {
let mut s = session();
let id = projected_rect(&mut s, effect, false);
run(&mut s, "object.rotate", json!({"angle": 30}));
let d = &s.doc().unwrap().doc;
let angle = d.bbox_angle(&[id]);
assert!(angle.abs() > 0.1);
let n = d.node(id).unwrap();
let art = vectorcraft_render::effects::revolve_art(n).or_else(|| vectorcraft_render::effects::solid_art(n)).unwrap();
let frame = vectorcraft_doc::OrientedBox { angle, rect: Rect::ZERO }.to_doc().inverse();
let expected = vectorcraft_render::effects::preview::bounds_in(&d.symbol_boxes(), &art, frame).unwrap();
preview(&mut s, true);
let measured = s.transform_box(&[id]).unwrap();
assert_eq!(measured.angle, angle);
assert!(near(measured.rect, expected, 1e-6), "{effect}: {measured:?} vs {expected:?}");
}
}
/// A click on a member of a layer with a 3D effect selects that member, with Use Preview Bounds on
/// or off, and the layer is still measured by its projected art.
#[test]
fn a_click_selects_the_member_of_a_layer_with_a_3d_effect() {
for effect in PREVIEW_3D {
for on in [false, true] {
let mut s = session();
let id = rect(&mut s, 100.0, 80.0, 0.0);
run(&mut s, "paint.setFill", json!({"color": "#0000ff"}));
let layer = s.doc().unwrap().doc.layers[0].id;
run(&mut s, "effect.apply", json!({"ids": [layer.0], "effect": effect, "params": params_3d(effect), "item": null}));
preview(&mut s, on);
run(&mut s, "select.none", json!({}));
let v = ViewInfo::default();
s.select_tool("selection", v).unwrap();
for k in [PointerKind::Down, PointerKind::Up] {
s.pointer(&PointerEvent::new(k, 140.0, 125.0), v).unwrap();
}
assert_eq!(s.active().unwrap().selection.objects, [id], "{effect}, preview={on}");
let d = &s.doc().unwrap().doc;
let art =
vectorcraft_render::effects::revolve_art(&d.layers[0]).or_else(|| vectorcraft_render::effects::solid_art(&d.layers[0])).unwrap();
let expected = vectorcraft_render::effects::preview::visual_bounds(&d.symbol_boxes(), &art).unwrap();
let measured = vectorcraft_render::effects::preview::bounds_of(d, &[layer], true).unwrap();
assert!(near(measured, expected, 1e-6), "{effect}: {measured:?} vs {expected:?}");
}
}
}
#[test]
fn a_square_with_offset_path_is_measured_by_the_offset_shape() {
let mut s = session();
+6 -3
View File
@@ -6760,9 +6760,12 @@ also measured by its reshaped art when its symbol's art has geometry effects. A
Pathfinder effects, or with a fill or stroke of its own that has geometry effects or paints members with geometry
effects, is measured by its evaluated art. A blend, envelope or repeat whose objects have geometry effects is
measured by its evaluated art, with those objects measured after their effects. A 100 pt square without a stroke,
with Offset Path 10, measures 120 pt, and type with Outline Object is measured by its glyph outlines. Raster effects such as shadows and glows are not
measured. In one object, the art of at most 4,096 symbol instances is measured with its geometry effects, and the
other instances are measured without them. `object.setBounds` with `width: 100` gives that type a glyph box 100 pt
with Offset Path 10, measures 120 pt, and type with Outline Object is measured by its glyph outlines.
Extrude & Bevel, Revolve, Inflate and Rotate are measured by their projected vector art, including effects on
individual fills or strokes and geometry effects after projection. Groups and symbol instances include their
members' projected art. Raster effects such as shadows and glows are not measured. In one object, the art of at
most 4,096 symbol instances is measured with its geometry or 3D effects, and the other instances are measured
without them. `object.setBounds` with `width: 100` gives that type a glyph box 100 pt
wide.
```json
+1
View File
@@ -1421,6 +1421,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- Without a twist, a tapered Extrude & Bevel wall (and each bevel band) is one flat face; only a twist cuts walls into slices, so no seam between slices paints a light tick or a light line on a tapered, untwisted wall (#7019). Test: `solid::tests::a_tapered_wall_is_one_flat_face_and_a_twisted_one_is_sliced`.
- Extrude & Bevel cuts a corner square where the bevel opens it and its miter would reach past four times the width (a sharp point with the bevel outside, a narrow notch with it inside), so the bevel (and, with the bevel outside, the walls) no longer runs out to a spike that does not line up with the art (#7525). Tests: `solid::tests::a_bevel_cuts_sharp_corners_square`, `solid::tests::a_cap_draws_no_empty_segment_at_a_corner_cut_square`.
- Extrude & Bevel, Inflate and Rotate apply to type: it makes a solid of its glyph outlines, painted with its own fills and strokes or, when it has none, its characters' colour (the first run's), and stays type, so editing the text reshapes the solid (#4715).
- Use Preview Bounds measures Extrude & Bevel, Revolve, Inflate and Rotate by VectorCraft's projected vector art, including fill and stroke effects, group and symbol members, and geometry after projection. Engine regressions cover all four families, hidden effects and the preference off, alignment and spacing with Undo, typed width, and oriented boxes. Raster effects are not measured yet. The [user guide](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf) (printed page 95, Info panel) says Use Preview Bounds counts the stroke and other appearance attributes in an object's dimensions.
- Extrude & Bevel, Inflate and Rotate (Effect › 3D and Materials): live effects in the `three-d` crate with depth, twist, taper, solid or hollow caps, five original bevel shapes (width, height, repeat, spacing, inside, both sides), Inflate's volume, both sides, twist, taper and cap, Rotate's turned fills and strokes, Position presets, the rotation and light gizmos, SVG/PDF vector output and Expand Appearance; one 3D effect per object; covered by geometry, effect, canvas-versus-export, command and dialog tests ([three-d.md](three-d.md)).
- Extrude & Bevel and Inflate build detailed shapes: each solid takes up to 65,536 outline points and 163,840 faces (VectorCraft's own limits, was 2,048 points and 32,768 faces), counted before any point is sampled; when the faces do not fit, every curve takes fewer pieces, down to 4. A closed path of 2,000 curves extrudes with a bevel and inflates, and paths of 5,000 and 10,000 curves build at the default settings (`crates/three-d/src/solid/tests_limits.rs`).
- The solids of one Extrude & Bevel (both kinds) or Inflate effect on one object, its fill's, its strokes' and a group's members' together, keep up to 163,840 faces (VectorCraft's own limit). Each solid is built in turn; once their faces pass the limit, no later solid is built, the object draws its source art, and applying or editing the effect, Export 3D Object and Expand as Wireframes report that the 3D surface is too complex. Tests `solids::tests::an_objects_solids_count_their_faces_together`, `a_groups_solids_together_past_the_limit_draw_the_source`, `a_fill_and_strokes_together_past_the_limit_draw_the_source`.