mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 13:33:51 +00:00
Symbols: instance fill and stroke effects keep clipping reach, Pathfinder results and Shaper faces
The merge of main left two match arms for symbol instances in `Node::reach`, so the arm that takes in the region of a clipping path with live geometry effects in the art no longer ran, and clippy stopped on the unreachable pattern. Symbol instances now have one arm that takes in both that region and the shapes the art paints with the effects of the instance's own fill or stroke. The shapes an instance's fill or stroke effects paint now come from the result of a Pathfinder effect on a group or layer in the art, not from the members it combines, and leave out the original shapes a Shaper group holds. A click where only those shapes would grow no longer selects the instance.
This commit is contained in:
+17
-14
@@ -256,17 +256,8 @@ impl Node {
|
||||
.map(|b| b.inflate(o, o))
|
||||
}
|
||||
NodeKind::Intertwine { children } => children.iter().fold(None, |acc, c| vectorcraft_geom::union_opt(acc, c.reach(symbols))),
|
||||
// The frame and each shape the image's own fills and strokes paint, or a symbol
|
||||
// instance's box and each shape its art paints with the geometry effects of the
|
||||
// instance's own fill or stroke, a stroke's grown by the farthest it can reach from its
|
||||
// shape.
|
||||
NodeKind::Image(_) | NodeKind::SymbolInstance { .. } => {
|
||||
let start = if matches!(self.kind, NodeKind::Image(_)) { self.geometric(symbols) } else { self.visual(symbols) };
|
||||
crate::hit::image_paint(symbols.map(SymbolBoxes::document), self).iter().fold(start, |acc, (bp, _, item)| {
|
||||
let o = if let crate::AppearanceItem::Stroke(s) = item { s.reach() } else { 0.0 };
|
||||
vectorcraft_geom::union_opt(acc, (!bp.elements().is_empty()).then(|| bp.bounding_box().inflate(o, o)))
|
||||
})
|
||||
}
|
||||
// The frame and each shape the image's own fills and strokes paint.
|
||||
NodeKind::Image(_) => self.with_own_paint(self.geometric(symbols), symbols),
|
||||
// Keys and steps placed on a spine, turned to it with Align to Path, can reach past the
|
||||
// keys and the spine.
|
||||
NodeKind::Blend { children, spec } => {
|
||||
@@ -277,13 +268,15 @@ impl Node {
|
||||
NodeKind::Layer { children, clip: true, .. } | NodeKind::Group { children, clip: true } => {
|
||||
vectorcraft_geom::union_opt(self.visual(symbols), children.first().and_then(|c| crate::hit::reshaped_clip_box(c)))
|
||||
}
|
||||
// The live geometry effects of the clipping paths in the art can draw it past its box.
|
||||
// The live geometry effects of the clipping paths in the art can draw it past its box,
|
||||
// and the box takes in each shape the art paints with the geometry effects of the
|
||||
// instance's own fill or stroke.
|
||||
NodeKind::SymbolInstance { symbol, xf } => {
|
||||
let Some((s, art, region)) = symbols.and_then(|s| {
|
||||
let a = s.art(symbol)?;
|
||||
Some((s, a, a.reshaped?))
|
||||
}) else {
|
||||
return self.visual(symbols);
|
||||
return self.with_own_paint(self.visual(symbols), symbols);
|
||||
};
|
||||
let map = s.document().symbol_slice_map_of(symbol, art.geometric, *xf);
|
||||
let placed = if moves_only(*xf) && map.is_none() {
|
||||
@@ -299,12 +292,22 @@ impl Node {
|
||||
map.map_or_else(|| xf.transform_rect_bbox(all), |m| m.placement_bounds(all)).inflate(grow, grow)
|
||||
};
|
||||
let o = self.appearance.outset();
|
||||
vectorcraft_geom::union_opt(self.visual(symbols), self.projected(Some(placed)).map(|b| b.inflate(o, o)))
|
||||
self.with_own_paint(vectorcraft_geom::union_opt(self.visual(symbols), self.projected(Some(placed)).map(|b| b.inflate(o, o))), symbols)
|
||||
}
|
||||
_ => self.visual(symbols),
|
||||
}
|
||||
}
|
||||
|
||||
/// `start` grown by each shape the node's own fills and strokes paint
|
||||
/// ([`crate::hit::set_image_paint`]), a stroke's grown by the farthest it can reach from its
|
||||
/// shape.
|
||||
fn with_own_paint(&self, start: Option<Rect>, symbols: Option<&SymbolBoxes>) -> Option<Rect> {
|
||||
crate::hit::image_paint(symbols.map(SymbolBoxes::document), self).iter().fold(start, |acc, (bp, _, item)| {
|
||||
let o = if let crate::AppearanceItem::Stroke(s) = item { s.reach() } else { 0.0 };
|
||||
vectorcraft_geom::union_opt(acc, (!bp.elements().is_empty()).then(|| bp.bounding_box().inflate(o, o)))
|
||||
})
|
||||
}
|
||||
|
||||
/// Geometric bounds (no stroke), recursively. Clip groups are bounded by their clip path. A
|
||||
/// symbol instance is measured as its transform applied to the 20 × 20 square around the origin
|
||||
/// that symbols made in the app keep their art in ([`Node::geometric_bounds_with`] measures
|
||||
|
||||
@@ -489,10 +489,11 @@ fn push_painted(doc: Option<&Document>, c: &Node, out: &mut Vec<(BezPath, FillRu
|
||||
/// its active fill and stroke ([`has_item_geometry`]): the paths of the art [`reshape`] makes of it,
|
||||
/// each with its own geometry effects and those of each fill and stroke applied
|
||||
/// ([`crate::bake_type_appearance`], [`push_painted`]), the paths that the own fills and strokes of
|
||||
/// the groups and layers in the art paint ([`crate::evaluate_container`]), the shapes that the own
|
||||
/// fills and strokes of the images in the art paint ([`image_paint`]), and the instances in that
|
||||
/// art that took those effects, in turn. Hidden objects, clipping paths, guides and the members of
|
||||
/// clip groups add nothing, and neither does an instance more than
|
||||
/// the groups and layers in the art paint and the results of their Pathfinder effects
|
||||
/// ([`crate::evaluate_container`]), the shapes that the own fills and strokes of the images in the
|
||||
/// art paint ([`image_paint`]), and the instances in that art that took those effects, in turn.
|
||||
/// Hidden objects, clipping paths, guides, the members of clip groups and the original shapes of
|
||||
/// Shaper groups add nothing, and neither does an instance more than
|
||||
/// [`vectorcraft_doc::depth::MAX_DEPTH`] deep or whose symbol's art would take the objects measured
|
||||
/// so far past `budget`.
|
||||
fn instance_paint(doc: Option<&Document>, n: &Node, depth: usize, budget: &mut u64, out: &mut Vec<(BezPath, FillRule, AppearanceItem)>) {
|
||||
@@ -526,12 +527,16 @@ fn painted_in(doc: Option<&Document>, n: &Node, depth: usize, budget: &mut u64,
|
||||
NodeKind::SymbolInstance { .. } => instance_paint(doc, n, depth + 1, budget, out),
|
||||
_ if n.clips() => {}
|
||||
_ => {
|
||||
let evaluated = crate::has_container_appearance(n).then(|| crate::evaluate_container(doc, n)).flatten();
|
||||
// A Pathfinder effect paints its result, not the members it combines.
|
||||
let evaluated = (crate::has_container_appearance(n) || crate::has_pathfinder(n)).then(|| crate::evaluate_container(doc, n)).flatten();
|
||||
let g = evaluated.as_ref().unwrap_or(n);
|
||||
if g.clips() {
|
||||
return;
|
||||
}
|
||||
for c in g.children().into_iter().flatten() {
|
||||
// A Shaper group's first member holds its original shapes, which are not drawn. The
|
||||
// group's own fills and strokes can be painted before it, so it is found by its id.
|
||||
let sources = n.extras().shaper.is_some().then(|| n.children().and_then(|c| c.first()).map(|c| c.id)).flatten();
|
||||
for c in g.children().into_iter().flatten().filter(|c| Some(c.id) != sources) {
|
||||
painted_in(doc, c, depth, budget, out);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,6 +415,63 @@ fn a_click_on_the_grown_fill_of_an_image_in_the_art_selects_the_instance() {
|
||||
assert_eq!(hit_at(&s, 60.0, opt), None, "a click past the grown fill");
|
||||
}
|
||||
|
||||
/// A group in the symbol's art with Effect › Pathfinder › Subtract: the instance's fill effect
|
||||
/// grows the result, and a click past both shapes where only the subtracted shape would grow does
|
||||
/// not select the instance.
|
||||
#[test]
|
||||
fn a_click_on_a_shape_a_pathfinder_effect_in_the_art_subtracts_misses_the_instance() {
|
||||
let mut s = session();
|
||||
// The back square runs from 50 to 110 and the front one from 80 to 140; the result runs from 50 to 80.
|
||||
let back = NodeId(run(&mut s, "shape.rectangle", json!({"x": 50, "y": 50, "width": 60, "height": 100}))["id"].as_u64().unwrap());
|
||||
run(&mut s, "paint.setFill", json!({"color": "#ff0000"}));
|
||||
run(&mut s, "paint.setStroke", json!({"color": "#0000ff"}));
|
||||
run(&mut s, "stroke.set", json!({"weight": 4}));
|
||||
let front = NodeId(run(&mut s, "shape.rectangle", json!({"x": 80, "y": 50, "width": 60, "height": 100}))["id"].as_u64().unwrap());
|
||||
let g = NodeId(run(&mut s, "object.group", json!({"ids": [back.0, front.0]}))["id"].as_u64().unwrap());
|
||||
run(&mut s, "effect.apply", json!({"ids": [g.0], "effect": "pathfinder.subtract"}));
|
||||
run(&mut s, "select.set", json!({"ids": [g.0]}));
|
||||
let id = NodeId(run(&mut s, "symbol.new", json!({"name": "Subtracted"}))["id"].as_u64().unwrap());
|
||||
run(&mut s, "appearance.addFill", json!({"ids": [id.0]}));
|
||||
let row = node(&s, id).appearance.items.len() - 1;
|
||||
run(&mut s, "appearance.setItem", json!({"ids": [id.0], "index": row, "none": true}));
|
||||
let opt = vectorcraft_doc::hit::HitOptions { tol: 1.0, ..Default::default() };
|
||||
assert_eq!(hit_at(&s, 45.0, opt), None);
|
||||
offset_row(&mut s, id, row, 10.0);
|
||||
let r = render(&s);
|
||||
assert!(near(r.pixel(45, 100), RED), "the result's fill grows by the offset: {:?}", r.pixel(45, 100));
|
||||
assert!(near(r.pixel(145, 100), WHITE), "the subtracted shape is not drawn: {:?}", r.pixel(145, 100));
|
||||
assert_eq!(hit_at(&s, 45.0, opt), Some(id), "a click on the result's grown fill");
|
||||
assert_eq!(hit_at(&s, 145.0, opt), None, "a click where only the subtracted shape would grow");
|
||||
}
|
||||
|
||||
/// A Shaper group in the symbol's art: the instance's fill effect grows the faces it shows, and a
|
||||
/// click where only its original shapes would grow does not select the instance.
|
||||
#[test]
|
||||
fn a_click_on_a_shaper_groups_original_shapes_in_the_art_misses_the_instance() {
|
||||
let mut s = session();
|
||||
run(&mut s, "paint.setStroke", json!({"none": true, "ids": []}));
|
||||
for x in [0, 50] {
|
||||
run(&mut s, "paint.setFill", json!({"color": "#ff0000", "ids": []}));
|
||||
run(&mut s, "shape.rectangle", json!({"x": x, "y": 50, "width": 100, "height": 100}));
|
||||
}
|
||||
// The scribble inside the overlap removes the front rectangle's face; the face left runs from 0 to 50.
|
||||
let g = NodeId(run(&mut s, "shaper.scribble", json!({"points": [[65, 70], [85, 90], [65, 110], [85, 130]]}))["id"].as_u64().unwrap());
|
||||
assert!(node(&s, g).extras().shaper.is_some());
|
||||
run(&mut s, "select.set", json!({"ids": [g.0]}));
|
||||
let id = NodeId(run(&mut s, "symbol.new", json!({"name": "Shaped"}))["id"].as_u64().unwrap());
|
||||
run(&mut s, "appearance.addFill", json!({"ids": [id.0]}));
|
||||
let row = node(&s, id).appearance.items.len() - 1;
|
||||
run(&mut s, "appearance.setItem", json!({"ids": [id.0], "index": row, "none": true}));
|
||||
let opt = vectorcraft_doc::hit::HitOptions { tol: 1.0, ..Default::default() };
|
||||
assert_eq!(hit_at(&s, 57.0, opt), None);
|
||||
offset_row(&mut s, id, row, 10.0);
|
||||
let r = render(&s);
|
||||
assert!(near(r.pixel(57, 100), RED), "the face's fill grows by the offset: {:?}", r.pixel(57, 100));
|
||||
assert!(near(r.pixel(125, 100), WHITE), "the original shapes are not drawn: {:?}", r.pixel(125, 100));
|
||||
assert_eq!(hit_at(&s, 57.0, opt), Some(id), "a click on the face's grown fill");
|
||||
assert_eq!(hit_at(&s, 125.0, opt), None, "a click on an original shape");
|
||||
}
|
||||
|
||||
/// Of several fills, only the topmost one's effects reach the art, and only while it is visible.
|
||||
#[test]
|
||||
fn only_the_topmost_visible_instance_fill_reshapes_the_art() {
|
||||
|
||||
Reference in New Issue
Block a user