Symbols: picking and outlining a dynamic instance's part stays within one object limit

Outlining a part of a dynamic symbol's instance expanded every nested
instance whose fill or stroke effects reshape its art, at every level, with
no limit, so art that nests many such instances a few levels deep took work
that grew with each level. A part pick charged each object it tested but
copied each nested instance's art before charging anything for it.

The part outline now shares the object limit a click has, and each object
it outlines takes one object of it. The art of a nested instance takes its
size from the limit before it is copied, and the art an object's own
effects draw takes its size once evaluated; nothing more is copied or
evaluated once the limit is used up. The art of the instance itself is
charged by its walk, as before.
This commit is contained in:
dotCooCoo committed 2026-11-21 03:30:44 -08:00
1 parent d8db9eda83
commit b06bccfaeb
2 files changed
+145 -13

No files matched your search

+63 -10
View File
@@ -1609,7 +1609,17 @@ fn painted_hit(painted: &Painted, p: Point, opt: HitOptions) -> Option<HitKind>
/// is tested here. Never with `outline`, where the canvas draws no effects, nor while a
/// [`DrawnOff`] guard lives.
fn reshapes_instance_art(n: &Node, symbols: &SymbolBoxes, outline: bool) -> bool {
!outline && !DRAWN_OFF.get() && matches!(n.kind, NodeKind::SymbolInstance { .. }) && !image_paint(Some(symbols.document()), n).is_empty()
!outline
&& !DRAWN_OFF.get()
&& matches!(n.kind, NodeKind::SymbolInstance { .. })
&& n.appearance.items.iter().any(|i| !i.effects().is_empty())
&& !image_paint(Some(symbols.document()), n).is_empty()
}
/// How many objects `n` holds with its opacity masks' art ([`Node::count_with_masks`]), what
/// testing or outlining it takes from the [`ArtWalk`] limit.
fn walk_size(n: &Node) -> u64 {
u64::try_from(n.count_with_masks()).unwrap_or(u64::MAX)
}
/// The art that symbol instance `n` draws with a visible effect of its own, the effects of its
@@ -1617,17 +1627,28 @@ fn reshapes_instance_art(n: &Node, symbols: &SymbolBoxes, outline: bool) -> bool
/// visible effects of its own and of its fills and strokes, as outlined paths ([`set_drawn_art`]).
/// `None` for other objects, with `outline`, where the canvas draws no effects, for an instance or
/// type without such an effect, while a [`DrawnOff`] guard lives, and when no geometry effect
/// changes what it draws.
/// changes what it draws. Evaluating the art is work that walking it does not count, so the art
/// takes its objects from the [`ArtWalk`] limit of the click or outline under way, and the walk of
/// it takes them again. Once the limit is used up, the result is `Some` of an empty group, which
/// hits and outlines nothing, and no more art is evaluated.
fn own_effects_art(n: &Node, symbols: &SymbolBoxes, outline: bool) -> Option<Node> {
let has = match n.kind {
NodeKind::SymbolInstance { .. } => n.appearance.effects.iter().any(|e| e.visible),
NodeKind::Text(_) => has_own_effects(n),
_ => false,
};
if outline || DRAWN_OFF.get() || !has {
if outline || DRAWN_OFF.get() || !has || DRAWN_ART.get().is_none() {
return None;
}
DRAWN_ART.get()?(symbols, n)
let nothing = || Some(Node::group(n.id, vec![]));
if ArtWalk::used_up() {
return nothing();
}
let art = DRAWN_ART.get()?(symbols, n)?;
if !ArtWalk::take(walk_size(&art)) {
return nothing();
}
Some(art)
}
/// Is `p` within `tol` of the type path of `t` (in `n`), what "Type Object Selection by Path
@@ -1744,12 +1765,36 @@ impl<'a> InstanceArt<'a> {
/// outlined where the canvas draws it. Not with `outline`, where the canvas draws no effects.
fn drawn(doc: &'a Document, inst: &Node, outline: bool) -> Option<Self> {
let mut art = Self::of(doc, inst)?;
#[cfg(test)]
ARTS_WALKED.with(|c| c.set(c.get() + 1));
if !outline && let Some(f) = INSTANCE_ROW_ART.get() {
f(Some(doc), inst, &mut art.art);
}
Some(art)
}
/// [`Self::drawn`] for symbol instance `inst` in the art of another instance, outside Outline.
/// Copying the art and adding the effects to it is work that walking it does not count, so the
/// art takes as many objects as placing it makes ([`Self::size`]) from the [`ArtWalk`] limit of
/// the click or outline under way before it is copied, as the marquee takes the art it places,
/// and the walk of it takes its objects again. `None` once fewer are left.
fn nested(doc: &'a Document, inst: &Node) -> Option<Self> {
if ArtWalk::used_up() {
return None;
}
let NodeKind::SymbolInstance { symbol, xf } = &inst.kind else { return None };
let boxes = doc.symbol_boxes().quick();
let source = boxes.symbol_art(symbol)?;
let size = match boxes.slice_map(symbol, *xf) {
Some(m) => m.most_placed_with(source, &boxes),
None => walk_size(source),
};
if !ArtWalk::take(size) {
return None;
}
Self::drawn(doc, inst, false)
}
/// The map that the objects inside group or layer `n` are moved by as one piece: `whole`, the
/// map of an object around `n` that is moved as one piece, or else the map of the 9-slice cell
/// `n` lies in ([`crate::NineSliceMap::one_cell`]). `None` when `n` is placed through the guides
@@ -1958,7 +2003,7 @@ fn drawn_instance_hit(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes
if symbols.art(symbol).is_none() || ArtWalk::used_up() {
return None;
}
let art = InstanceArt::drawn(symbols.document(), n, false)?;
let art = InstanceArt::nested(symbols.document(), n)?;
let opt = HitOptions { clip_outlines: false, ..opt };
let _art_only = ArtOnly::set();
FindPart { art: &art, p, opt, symbols, whole_instance: true, drawn: true }.find(&art.art, &mut vec![], None, false)
@@ -2112,8 +2157,11 @@ pub fn symbol_part_outline(doc: &Document, inst: &Node, path: &[u32]) -> Option<
/// outlines are cut to the bounds of the plain clipping paths, without their live effects, as
/// [`symbol_part_at`] counts them. The outline is empty when the effects of a clipping path around
/// the object leave no region. Elsewhere the outlines follow the geometry effects of the instance's
/// active fill and stroke, as [`symbol_part_at`] does.
/// active fill and stroke, as [`symbol_part_at`] does. Outlining visits at most as many objects of
/// symbol art as one click does ([`ArtWalk`]), the art of the instances nested in the part included,
/// and leaves out what is past that limit.
pub fn symbol_part_outline_in_view(doc: &Document, inst: &Node, path: &[u32], opt: HitOptions) -> Option<BezPath> {
let _walk = ArtWalk::open();
let mut outline = opt.outline || below_preview_off(doc, inst, opt.scope);
let art = InstanceArt::drawn(doc, inst, outline)?;
let part = crate::symbol_overrides::part(&art.art, path)?;
@@ -2164,11 +2212,16 @@ fn limit_within(clip: &Node, limit: Option<Rect>, outline: bool) -> Option<Optio
/// [`symbol_part_outline_in_view`] for placed object `n`, cut to `limit` when there is one. A path
/// or compound path whose geometry effects reshape it is outlined as the art they draw
/// ([`drawn_art`]), a symbol instance with geometry effects of its own and type whose effects
/// reshape it as the art they draw ([`own_effects_art`]), and a symbol instance whose fill or stroke effects reshape its art as that
/// art drawn with them ([`InstanceArt::drawn`]), as [`FindPart`] tests them, except with `outline`
/// and while a [`DrawnOff`] guard lives.
/// reshape it as the art they draw ([`own_effects_art`]), and a symbol instance whose fill or
/// stroke effects reshape its art as that art drawn with them ([`InstanceArt::drawn`]), as
/// [`FindPart`] tests them, except with `outline` and while a [`DrawnOff`] guard lives. Each object
/// visited takes one object of the [`ArtWalk`] limit, and nothing more is outlined once the limit
/// is used up.
fn outline_within(n: &Node, symbols: &SymbolBoxes, limit: Option<Rect>, outline: bool, out: &mut BezPath) {
use vectorcraft_geom::kurbo::Shape;
if !ArtWalk::take(1) {
return;
}
if matches!(n.kind, NodeKind::Path { .. } | NodeKind::Compound { .. })
&& let Some(art) = drawn_art(symbols, n, outline)
{
@@ -2185,7 +2238,7 @@ fn outline_within(n: &Node, symbols: &SymbolBoxes, limit: Option<Rect>, outline:
&& reshapes_instance_art(n, symbols, outline)
{
if symbols.art(symbol).is_some()
&& let Some(art) = InstanceArt::drawn(symbols.document(), n, false)
&& let Some(art) = InstanceArt::nested(symbols.document(), n)
&& let Some(placed) = art.place(&art.art, None)
{
outline_within(&placed, symbols, limit, outline, out);
+82 -3
View File
@@ -1324,11 +1324,11 @@ fn evaluated_art_is_not_kept_while_a_placed_document_may_show_in_it() {
assert_eq!(evaluated(), before + 2);
}
/// For instances of the symbol "Painted", a fill that paints the square from (300, 0) to
/// (320, 20); nothing for anything else.
/// For instances of the symbols whose names start with "Painted", a fill that paints the square
/// from (300, 0) to (320, 20); nothing for anything else.
fn painted_far_away(_: Option<&Document>, n: &Node) -> Vec<(BezPath, FillRule, AppearanceItem)> {
match &n.kind {
NodeKind::SymbolInstance { symbol, .. } if symbol == "Painted" => {
NodeKind::SymbolInstance { symbol, .. } if symbol.starts_with("Painted") => {
let square = shapes::rectangle(Rect::new(300.0, 0.0, 320.0, 20.0)).to_bezpath();
vec![(square, FillRule::NonZero, AppearanceItem::Fill(crate::FillLayer::new(Paint::solid(Color::rgb(1.0, 0.0, 0.0)))))]
}
@@ -3041,6 +3041,85 @@ fn a_click_counts_the_members_of_an_intertwine_group_in_symbol_art_toward_one_li
assert_eq!(with_art_limit(100, || at(140.0)).0, Some(id), "on the squares' paths");
}
/// An instance of the symbol named `symbol`, not moved, whose fill has a geometry effect:
/// [`painted_far_away`] gives it shapes when the name starts with "Painted", so a part pick and a
/// part outline walk its art as drawn with its fill's effects ([`InstanceArt::drawn`]).
fn painted_instance_of(d: &mut Document, symbol: &str) -> Arc<Node> {
let mut n = Node::new(d.alloc_id(), NodeKind::SymbolInstance { symbol: symbol.into(), xf: vectorcraft_geom::Affine::IDENTITY });
n.appearance = Appearance::default_art().into();
let offset = crate::Effect { id: "path.offsetPath".into(), params: serde_json::json!({"offset": 10}), visible: true };
n.appearance.items[0].effects_mut().push(offset);
Arc::new(n)
}
/// Five levels of symbols: "Painted 0" is a 1 pt square, and each level above holds 8 instances
/// of the level below whose fills have a geometry effect. Returns the id of an instance of
/// "Painted 4" on the layer.
fn painted_chain(d: &mut Document) -> NodeId {
let l = d.layers[0].id;
let dot = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(0.0, 0.0, 1.0, 1.0)), Appearance::default_art());
d.symbols.push(crate::Symbol { dynamic: false, name: "Painted 0".into(), art: Arc::new(dot) });
for level in 1..5 {
let members = (0..8).map(|_| painted_instance_of(d, &format!("Painted {}", level - 1))).collect();
group_symbol(d, &format!("Painted {level}"), members);
}
let inst = instance_of(d, "Painted 4");
let id = inst.id;
d.insert(Some(l), 0, Arc::unwrap_or_clone(inst)).unwrap();
id
}
/// The outline of a part of a dynamic symbol's instance visits at most the art walk's limit of
/// objects, though the part is an instance whose art, drawn with its fill's effects, nests
/// instances 3 levels deep, 8 at each level. Within the limit every square is outlined.
#[test]
fn a_parts_outline_walks_nested_reshaped_symbol_instances_within_one_limit() {
set_image_paint(painted_far_away);
let mut d = Document::new(600.0, 400.0);
let id = painted_chain(&mut d);
let n = d.node(id).unwrap();
let squares = |o: &BezPath| o.elements().iter().filter(|e| matches!(e, vectorcraft_geom::kurbo::PathEl::MoveTo(_))).count();
// Part [0] is an instance of "Painted 3": 8 × 8 × 8 squares.
assert_eq!(squares(&symbol_part_outline(&d, n, &[0]).unwrap()), 512, "within the limit");
let (outline, _, arts) = with_art_limit(100, || symbol_part_outline(&d, n, &[0]).unwrap());
assert!(squares(&outline) < 100, "{} squares outlined", squares(&outline));
assert!(arts < 100, "{arts} instances' art walked");
}
/// A part pick in a dynamic symbol's instance visits at most the art walk's limit of objects of
/// nested instances whose art, drawn with their fills' effects, is walked: in a chain of nested
/// instances, and in instances whose clip groups the click misses, where only the clip group
/// itself is tested. A click on the clipped art of a nested instance is still found.
#[test]
fn a_part_pick_walks_nested_reshaped_symbol_instances_within_one_limit() {
set_image_paint(painted_far_away);
let mut d = Document::new(600.0, 400.0);
let id = painted_chain(&mut d);
let opt = HitOptions::default();
let (hit, _, arts) = with_art_limit(100, || symbol_part_at(&d, d.node(id).unwrap(), Point::new(150.0, 50.0), opt));
assert_eq!(hit, None);
assert!(arts <= 40, "chain: {arts} instances' art walked");
// 30 instances of a clip group whose 10 pt clipping path holds 40 squares: 42 objects each.
let mut d = Document::new(600.0, 400.0);
let l = d.layers[0].id;
let mask = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(0.0, 0.0, 10.0, 10.0)), Appearance::default());
let mut members = vec![Arc::new(mask)];
members.extend((0..40).map(|_| Arc::new(Node::path(d.alloc_id(), shapes::rectangle(Rect::new(0.0, 0.0, 5.0, 5.0)), Appearance::default_art()))));
let mut clip = Node::group(d.alloc_id(), members);
clip.set_clips(true);
d.symbols.push(crate::Symbol { dynamic: false, name: "Painted clip".into(), art: Arc::new(clip) });
let members = (0..30).map(|_| painted_instance_of(&mut d, "Painted clip")).collect();
group_symbol(&mut d, "Clips", members);
let inst = instance_of(&mut d, "Clips");
let id = inst.id;
d.insert(Some(l), 0, Arc::unwrap_or_clone(inst)).unwrap();
let n = d.node(id).unwrap();
let (hit, _, arts) = with_art_limit(300, || symbol_part_at(&d, n, Point::new(150.0, 50.0), opt));
assert_eq!(hit, None);
assert!(arts <= 8, "clip groups: {arts} instances' art walked");
assert_eq!(with_art_limit(300, || symbol_part_at(&d, n, Point::new(2.0, 2.0), opt)).0, Some(vec![29]), "the clipped art");
}
/// In a dynamic symbol's art that placing through its 9-slice guides could make more than
/// [`crate::MAX_SYMBOL_NODES`] objects of, Direct Selection picks and outlines nothing, as the
/// canvas draws nothing of it. At the art's natural size the same art is picked.