Selection: clicks and marquees follow an object's own geometry effects

A click or a marquee with the selection tools now finds a path or compound
path where its live geometry effects draw it, the copies a Transform effect
makes included, and not where its own geometry no longer paints.

- The engine registers its Use Preview Bounds evaluator with
  `vectorcraft_doc::hit::set_drawn_art`. Hit testing keeps the evaluated art
  per object, evaluates it again when the object, the document's symbols,
  patterns, swatches or live inputs change, and widens each object's cull box
  by the art its effects draw.
- Groups and layers with geometry effects or fills and strokes of their own
  are hit through their evaluated art. Clicks, Select Behind, the locked
  objects under the pointer and marquees map the art back to the members it
  is drawn from, at the depth each tool selects, and Direct Selection takes a
  group whose own paint the art draws.
- Clipping paths keep their own geometry, except that a clip group's own
  effect moves where its mask outline is taken. An isolated clip group's
  members are marqueed by their own geometry, as clicks take them. A clip
  group whose evaluated art holds only its clipping path is tested member by
  member.
- Outline view uses the plain paths, and a layer with Preview off is clicked
  in outline. Intertwine groups keep their woven hit order.

Docs: docs/target-app-parity.md.
This commit is contained in:
dotCooCoo
2026-11-15 15:50:59 -08:00
parent 957397e7a1
commit 963c06620e
5 changed files with 1051 additions and 57 deletions
+525 -56
View File
@@ -239,6 +239,190 @@ thread_local! {
static LIVE_EVALUATED: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
}
/// The art an object draws in Preview with the geometry effects in it applied, at every depth, as
/// plain art whose objects keep the ids of the objects they are drawn from: `None` when no geometry
/// effect in it changes what it draws. Effects are evaluated above this crate, so the engine
/// registers one with [`set_drawn_art`].
pub type DrawnArt = fn(&SymbolBoxes<'_>, &Node) -> Option<Node>;
static DRAWN_ART: OnceLock<DrawnArt> = OnceLock::new();
/// Register how the art an object draws with its geometry effects is found, for clicks and
/// marquees (the first registration stays).
pub fn set_drawn_art(f: DrawnArt) {
// Already set: the same engine, registered by another session.
let _ = DRAWN_ART.set(f);
}
/// The art of an object found by [`drawn`] (none, or one object), with what it was found from, and
/// the box round everything that art can paint.
struct EvaluatedDrawn {
of: EvaluatedLive,
reach: Option<Rect>,
}
/// How many objects' drawn art [`drawn`] keeps on each thread. Every pointer move measures every
/// object with effects that it passes, so the art of all of a document's objects with effects is
/// kept, within [`LIVE_KEPT_SIZE`], not only the latest few as with live objects.
const DRAWN_KEPT: usize = 4096;
thread_local! {
/// The drawn art [`drawn`] keeps, by object, and the sum of their sizes.
static DRAWN: RefCell<(HashMap<NodeId, EvaluatedDrawn>, usize)> = RefCell::new((HashMap::new(), 0));
/// Whether [`drawn`] gives no art: set while art it gave is tested ([`DrawnOff`]).
static DRAWN_OFF: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
}
#[cfg(test)]
thread_local! {
/// How many objects' drawn art [`drawn`] evaluated on this thread.
static DRAWN_EVALUATED: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
}
/// While a guard lives, [`drawn`] gives no art: the art it gave already has every geometry effect
/// in it applied, and is tested as it is.
struct DrawnOff {
was: bool,
}
impl DrawnOff {
fn set() -> Self {
Self { was: DRAWN_OFF.replace(true) }
}
}
impl Drop for DrawnOff {
fn drop(&mut self) {
DRAWN_OFF.set(self.was);
}
}
/// `f()`, with `mask` under a [`DrawnOff`] guard: the clipping path of a clip group or of a
/// clipping layer is clicked and touched by its own geometry, whatever its geometry effects do to
/// the region it clips to.
fn plain<T>(mask: bool, f: impl FnOnce() -> T) -> T {
let _off = mask.then(DrawnOff::set);
f()
}
/// The art object `n` draws with the geometry effects in it applied ([`set_drawn_art`]), empty when
/// none changes what it draws, and the box round everything that art can paint. `None` while
/// nothing is registered, while a [`DrawnOff`] guard lives, for objects whose art is not evaluated
/// ([`evaluates`]), and when nothing in `n`, nor the art of a symbol an instance in it shows, has a
/// visible effect ([`draws_effects`]). The art is evaluated again when `n`, a symbol of the
/// document, its patterns, swatches or color groups, or the [`LiveInputs`] have changed since, and
/// on every call while it holds a placed document ([`holds_placed`]). When the art kept is full, new
/// art replaces as much other art as it needs room for, and art larger than [`LIVE_KEPT_SIZE`] is
/// kept alone.
fn drawn(symbols: &SymbolBoxes, n: &Node) -> Option<(Rc<Vec<Node>>, Option<Rect>)> {
let f = DRAWN_ART.get()?;
if DRAWN_OFF.get() || !evaluates(n) || !(has_own_effects(n) || draws_effects(symbols, n)) {
return None;
}
let doc = symbols.document();
let inputs = live_inputs();
let kept = DRAWN.with_borrow(|(kept, _)| kept.get(&n.id).filter(|e| e.of.is_of(doc, n, inputs)).map(|e| (e.of.art.clone(), e.reach)));
if kept.is_some() {
return kept;
}
#[cfg(test)]
DRAWN_EVALUATED.with(|c| c.set(c.get() + 1));
let art = f(symbols, n);
let reach = art.as_ref().and_then(|a| a.reach_bounds_with(symbols));
let art = Rc::new(art.into_iter().collect::<Vec<_>>());
let size = art_size(&art).saturating_add(art_size(std::slice::from_ref(n)));
if !holds_placed(doc, n) {
let of = EvaluatedLive {
node: n.clone(),
symbols: doc.symbols.iter().map(|s| (s.name.clone(), s.art.clone())).collect(),
patterns: doc.patterns.clone(),
swatches: doc.swatches.clone(),
swatch_groups: doc.swatch_groups.clone(),
inputs,
art: art.clone(),
size,
};
DRAWN.with_borrow_mut(|(kept, total)| {
if let Some(old) = kept.remove(&n.id) {
*total = total.saturating_sub(old.of.size);
}
while kept.len() >= DRAWN_KEPT || total.saturating_add(size) > LIVE_KEPT_SIZE {
let Some(other) = kept.keys().next().copied() else { break };
if let Some(old) = kept.remove(&other) {
*total = total.saturating_sub(old.of.size);
}
}
kept.insert(n.id, EvaluatedDrawn { of, reach });
*total = total.saturating_add(size);
});
}
Some((art, reach))
}
/// Is `n` an object whose art [`drawn`] evaluates: a path or compound path, or a group or layer with
/// geometry effects or fills and strokes of its own, which paint its members as their effects draw
/// them?
fn evaluates(n: &Node) -> bool {
match &n.kind {
NodeKind::Path { guide, .. } => !guide,
NodeKind::Compound { .. } => true,
NodeKind::Group { .. } | NodeKind::Layer { .. } => has_own_effects(n) || !n.appearance.items.is_empty(),
_ => false,
}
}
/// The art path or compound path `n` draws with its geometry effects ([`drawn`]) in Preview, or
/// group or layer `n` with geometry effects or fills and strokes of its own: `None` in outline
/// (`outline`, where the canvas draws no effects), for other objects, and when no geometry effect
/// changes what it draws. Also `None` for a clip group or layer whose art holds only its clipping
/// path and that path's strokes, not the art it clips: its members are then tested one by one.
fn drawn_art(symbols: &SymbolBoxes, n: &Node, outline: bool) -> Option<Rc<Vec<Node>>> {
if outline {
return None;
}
drawn(symbols, n).map(|(art, _)| art).filter(|art| !art.is_empty() && (!n.clips() || holds_clipped_art(n, art)))
}
/// Does `art`, the drawn art of clip group or layer `n`, hold any of the objects `n` clips (its
/// members after the clipping path), or does `n` clip none?
fn holds_clipped_art(n: &Node, art: &[Node]) -> bool {
let clipped: HashSet<NodeId> = n.children().into_iter().flatten().skip(1).map(|c| c.id).collect();
if clipped.is_empty() {
return true;
}
let mut found = false;
for a in art {
a.walk(&mut |c| found |= clipped.contains(&c.id));
}
found
}
/// `base`, a box round what `n` paints without its geometry effects, grown to hold the art they
/// draw ([`effects_reach`]). `None` when `base` is.
fn drawn_reach(symbols: &SymbolBoxes, n: &Node, base: Option<Rect>) -> Option<Rect> {
let base = base?;
Some(effects_reach(symbols, n).map_or(base, |r| base.union(r)))
}
/// The box round the art that the geometry effects in `n` draw: that of its own art ([`drawn`])
/// when it is evaluated ([`evaluates`]), else the union of its members' in a group, layer or
/// Intertwine group. `None` when
/// no geometry effect changes what it draws, and while a [`DrawnOff`] guard lives.
fn effects_reach(symbols: &SymbolBoxes, n: &Node) -> Option<Rect> {
if DRAWN_OFF.get() {
return None;
}
if evaluates(n) {
return drawn(symbols, n).filter(|(art, _)| !art.is_empty()).and_then(|(_, reach)| reach);
}
match &n.kind {
NodeKind::Group { children, .. } | NodeKind::Layer { children, .. } | NodeKind::Intertwine { children } => {
children.iter().fold(None, |acc, c| vectorcraft_geom::union_opt(acc, effects_reach(symbols, c)))
}
_ => None,
}
}
/// Topmost editable object under `p`.
pub fn hit_test(doc: &Document, p: Point, opt: HitOptions) -> Option<Hit> {
hit_test_skipping(doc, p, opt, &|_| false, true)
@@ -368,6 +552,11 @@ pub fn objects_at(doc: &Document, p: Point, opt: HitOptions, scope: Option<NodeI
fn objects_at_layer(layer: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes, tops: &mut Vec<NodeId>, seen: &mut HashSet<NodeId>) -> bool {
let Some(children) = layer.children() else { return true };
let opt = if matches!(layer.kind, NodeKind::Layer { preview: false, .. }) { HitOptions { outline: true, ..opt } } else { opt };
// A layer whose own geometry effects reshape its art is hit where that art is drawn, which the
// general traversal finds ([`hit_children`]).
if drawn_art(symbols, layer, opt.outline).is_some() {
return false;
}
if layer.clips()
&& let Some(clip) = children.first()
{
@@ -400,11 +589,11 @@ fn objects_at_layer(layer: &Node, p: Point, opt: HitOptions, symbols: &SymbolBox
}
let skip = |id| seen.contains(&id);
let mut chain = Vec::new();
let hit = match &c.kind {
let hit = plain(i == 0 && layer.clips(), || match &c.kind {
NodeKind::Group { .. } | NodeKind::Intertwine { .. } => hit_children(c, p, opt, symbols, &skip, &mut chain, true).is_some(),
NodeKind::Blend { .. } => hit_children(c, p, opt, symbols, &skip, &mut chain, true).is_some() || hit_leaf(c, p, opt, symbols).is_some(),
_ => hit_leaf(c, p, opt, symbols).is_some(),
};
});
if hit && seen.insert(c.id) {
tops.push(c.id);
}
@@ -461,6 +650,23 @@ pub fn locked_objects_at(doc: &Document, p: Point, opt: HitOptions) -> Vec<NodeI
/// whole, and an unlocked layer, group, blend or envelope in Edit Contents is searched inside.
fn locked_children(parent: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes, out: &mut Vec<NodeId>) {
let Some(children) = parent.children() else { return };
// A group or layer whose own geometry effects reshape what it holds: the locked objects drawn
// under `p` ([`drawn_hit`]).
if !(parent.clips() && edits_inside(parent, opt.scope))
&& let Some(art) = drawn_art(symbols, parent, opt.outline)
{
let _off = DrawnOff::set();
let mut list = |id: NodeId, _: HitKind| {
if let Some(locked) = locked_member(parent, id, opt)
&& !out.contains(&locked)
{
out.push(locked);
}
out.len() >= MAX_LOCKED_AT
};
art.iter().rev().any(|a| art_hit(a, p, opt, symbols, &mut list));
return;
}
if parent.clips() && !edits_inside(parent, opt.scope) && children.first().is_some_and(|clip| !clip_contains(clip, p, opt.outline)) {
return;
}
@@ -473,7 +679,7 @@ fn locked_children(parent: &Node, p: Point, opt: HitOptions, symbols: &SymbolBox
continue;
}
if c.locked {
if locked_hit(c, p, opt, symbols) {
if plain(i == 0 && parent.clips(), || locked_hit(c, p, opt, symbols)) {
out.push(c.id);
}
continue;
@@ -598,13 +804,26 @@ pub fn set_clip_region(f: ClipRegion) {
/// then can the registered [`ClipRegion`] find a geometry effect in it.
fn has_effects(clip: &Node) -> bool {
let mut found = false;
clip.walk(&mut |n| {
let visible = |e: &crate::Effect| e.visible;
found |= n.appearance.effects.iter().any(visible) || n.appearance.items.iter().any(|i| i.effects().iter().any(visible));
clip.walk(&mut |n| found |= has_own_effects(n));
found
}
/// Does `n`, anything it holds, or the art of a symbol an instance in it shows have a visible
/// effect? Only then can the registered [`DrawnArt`] find a geometry effect in it.
fn draws_effects(symbols: &SymbolBoxes, n: &Node) -> bool {
let mut found = false;
n.walk(&mut |c| {
found = found || has_own_effects(c) || matches!(&c.kind, NodeKind::SymbolInstance { symbol, .. } if symbols.has_effects(symbol));
});
found
}
/// Does `n` itself have a visible effect, of its own or on one of its own fills or strokes?
fn has_own_effects(n: &Node) -> bool {
let visible = |e: &crate::Effect| e.visible;
n.appearance.effects.iter().any(visible) || n.appearance.items.iter().any(|i| i.effects().iter().any(visible))
}
/// A clipping path's region evaluated by [`clip_region`] on this thread: the clipping path and the
/// [`LiveInputs`] as they were, the region (`None` without geometry effects) and the number of its
/// path elements.
@@ -747,15 +966,7 @@ pub fn clip_regions(clip: &Node) -> Vec<(vectorcraft_geom::BezPath, vectorcraft_
/// hidden, when it can't be edited (`editable_only`), when it is the part of a Shaper group that
/// isn't shown, or when `p` is outside its reach.
fn may_hit(parent: &Node, i: usize, c: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes, editable_only: bool) -> bool {
if shaper_hides(parent, i, opt.scope) {
return false;
}
// Read-only samples can read locked/template art; hidden art never participates.
if !c.visible || editable_only && (c.locked || c.is_template()) {
return false;
}
// A ruler guide is picked by the guide commands, never by an object hit test.
if c.is_ruler_guide() || opt.skip_guides && matches!(c.kind, NodeKind::Path { guide: true, .. }) {
if !may_reach(parent, i, c, opt, editable_only) {
return false;
}
// (An envelope's content sits where it was, not where the envelope draws it.)
@@ -764,11 +975,28 @@ fn may_hit(parent: &Node, i: usize, c: &Node, p: Point, opt: HitOptions, symbols
|| cull_reach(c, symbols).is_none_or(|b| b.inflate(opt.tol, opt.tol).contains(p))
}
/// Can a click hit `c`, the child `i` of `parent`, or something inside it, wherever it is? Not
/// when it is hidden, when it can't be edited (`editable_only`), when it is a ruler guide or a
/// guide while guides are locked or hidden, or when it is the part of a Shaper group that isn't
/// shown.
fn may_reach(parent: &Node, i: usize, c: &Node, opt: HitOptions, editable_only: bool) -> bool {
if shaper_hides(parent, i, opt.scope) {
return false;
}
// Read-only samples can read locked/template art; hidden art never participates.
if !c.visible || editable_only && (c.locked || c.is_template()) {
return false;
}
// A ruler guide is picked by the guide commands, never by an object hit test.
!(c.is_ruler_guide() || opt.skip_guides && matches!(c.kind, NodeKind::Path { guide: true, .. }))
}
/// A box round everything `c` can paint, for culling clicks: [`Node::reach_bounds_with`], except
/// that paths and compound paths are measured by their control points ([`PathData::control_bounds`],
/// which hold the curves) instead of along their curves, which a compound path of thousands of
/// members takes milliseconds to do on every click and hover. The box only rules points out, and it
/// is at least as large, so the same objects are hit.
/// is at least as large, so the same objects are hit. It also holds the art that the geometry
/// effects in `c` draw ([`drawn_reach`]), wherever they move it.
///
/// [`PathData::control_bounds`]: vectorcraft_geom::PathData::control_bounds
fn cull_reach(c: &Node, symbols: &SymbolBoxes) -> Option<Rect> {
@@ -777,10 +1005,10 @@ fn cull_reach(c: &Node, symbols: &SymbolBoxes) -> Option<Rect> {
NodeKind::Compound { children, .. } if children.iter().all(|m| m.path_data().is_some()) => {
children.iter().filter_map(|m| m.path_data().and_then(vectorcraft_geom::PathData::control_bounds)).reduce(|a, b| a.union(b))
}
_ => return c.reach_bounds_with(symbols),
_ => return drawn_reach(symbols, c, c.reach_bounds_with(symbols)),
};
let o = c.appearance.outset();
control.map(|b| b.inflate(o, o))
drawn_reach(symbols, c, control.map(|b| b.inflate(o, o)))
}
/// The members of compound path `children` that a click at `p` within `tol` can touch, as one
@@ -854,19 +1082,36 @@ fn hit_children(
editable_only: bool,
) -> Option<Hit> {
let children = parent.children()?;
if parent.clips()
&& let Some(clip) = children.first()
{
if let Some(kind) = clip_outline_hit(parent, clip, p, opt, symbols, editable_only).filter(|_| !skip(clip.id)) {
let clip = children.first().filter(|_| parent.clips());
// The selection tools in isolation mode within a clip group (or a layer with a clipping mask)
// hit what it holds outside its clipping mask too.
let edited = clip.is_some() && opt.clip_outlines && editable_only && edits_inside(parent, opt.scope);
// A group or layer whose own geometry effects reshape what it holds hits where that art is drawn.
let art = if edited { None } else { drawn_art(symbols, parent, opt.outline) };
if let Some(clip) = clip {
// The clipping mask's outline first, where it is drawn.
let drawn_clip = art.as_deref().and_then(|a| a.first()).filter(|a| a.clips()).and_then(|a| a.children()?.first());
let kind = match drawn_clip {
Some(drawn) => {
let takes = opt.clip_outlines && editable_only && may_reach(parent, 0, clip, opt, editable_only);
takes.then(|| clip_outline(drawn, p, opt)).flatten()
}
None => clip_outline_hit(parent, clip, p, opt, symbols, editable_only),
};
if let Some(kind) = kind.filter(|_| !skip(clip.id)) {
chain.push(clip.id);
return Some(Hit { leaf: clip.id, ancestry: chain.clone(), kind, contents_of: None, layers: 1 });
}
// Elsewhere a clip group (or a layer with a clipping mask) only hits inside it, except for
// the selection tools in isolation mode within it.
let edited = opt.clip_outlines && editable_only && edits_inside(parent, opt.scope);
if !edited && !clip_contains(clip, p, opt.outline) {
return None;
}
}
if let Some(art) = art {
return drawn_hit(parent, &art, p, opt, symbols, skip, chain, editable_only);
}
// Elsewhere a clip group (or a layer with a clipping mask) only hits inside it.
if let Some(clip) = clip
&& !edited
&& !clip_contains(clip, p, opt.outline)
{
return None;
}
for i in hit_order(parent, children, p) {
let Some(c) = children.get(i) else { continue };
@@ -874,7 +1119,7 @@ fn hit_children(
continue;
}
chain.push(c.id);
let hit = match &c.kind {
let hit = plain(i == 0 && clip.is_some(), || match &c.kind {
// A sublayer whose Preview is off is clicked in outline, like an outline view.
NodeKind::Layer { preview: false, .. } => hit_children(c, p, HitOptions { outline: true, ..opt }, symbols, skip, chain, editable_only),
NodeKind::Layer { .. } | NodeKind::Group { .. } | NodeKind::Intertwine { .. } => {
@@ -887,7 +1132,7 @@ fn hit_children(
NodeKind::Blend { .. } => hit_children(c, p, opt, symbols, skip, chain, editable_only)
.or_else(|| hit_leaf(c, p, opt, symbols).map(|kind| Hit { leaf: c.id, ancestry: chain.clone(), kind, contents_of: None, layers: 1 })),
_ => hit_leaf(c, p, opt, symbols).map(|kind| Hit { leaf: c.id, ancestry: chain.clone(), kind, contents_of: None, layers: 1 }),
};
});
if hit.is_some() {
return hit;
}
@@ -896,6 +1141,123 @@ fn hit_children(
None
}
/// What a click at `p` hits in `art`, the art that group or layer `parent` draws with its own
/// geometry effects ([`drawn_art`]): the member of `parent` that the topmost object of the art hit
/// there is drawn from, found by its id, at the depth [`hit_children`] gives it, or `parent` itself,
/// when it is not a layer, for art of its own (its own fills and strokes). Where that member can't be hit (hidden, locked,
/// skipped, a guide, a Shaper group's part that isn't shown), the click goes on to the art below.
#[allow(clippy::too_many_arguments)]
fn drawn_hit(
parent: &Node,
art: &[Node],
p: Point,
opt: HitOptions,
symbols: &SymbolBoxes,
skip: &dyn Fn(NodeId) -> bool,
chain: &mut Vec<NodeId>,
editable_only: bool,
) -> Option<Hit> {
let _off = DrawnOff::set();
let mut found = None;
let mut accept = |id: NodeId, kind: HitKind| {
found = member_chain(parent, id, opt, skip, editable_only).map(|path| (path, kind));
found.is_some()
};
if !art.iter().rev().any(|a| art_hit(a, p, opt, symbols, &mut accept)) {
return None;
}
let (path, kind) = found?;
let leaf = path.last().copied().unwrap_or(parent.id);
chain.extend(path);
Some(Hit { leaf, ancestry: chain.clone(), kind, contents_of: None, layers: 1 })
}
/// The ids from a child of `parent` down to its member `id`, when a click may hit each of them
/// ([`may_reach`], and not passed over by `skip`); empty when `id` is `parent` itself, `parent` is
/// not a layer and `skip` does not pass over it. `None` otherwise, and when `id` is not in `parent`.
fn member_chain(parent: &Node, id: NodeId, opt: HitOptions, skip: &dyn Fn(NodeId) -> bool, editable_only: bool) -> Option<Vec<NodeId>> {
// A layer's own fills and strokes are not an object to select.
if id == parent.id {
return (!skip(id) && !parent.is_layer()).then(Vec::new);
}
let mut steps = vec![];
if !path_to(parent, id, &mut steps) {
return None;
}
let reachable = steps.iter().all(|(n, i, c)| may_reach(n, *i, c, opt, editable_only) && !skip(c.id));
reachable.then(|| steps.iter().map(|(_, _, c)| c.id).collect())
}
/// Each container from `n` down to its member `id`, with the index and the child it holds on the
/// way, into `path`. `false` when `id` is not in `n`.
fn path_to<'a>(n: &'a Node, id: NodeId, path: &mut Vec<(&'a Node, usize, &'a Node)>) -> bool {
for (i, c) in n.children().into_iter().flatten().enumerate() {
path.push((n, i, c));
if c.id == id || path_to(c, id, path) {
return true;
}
path.pop();
}
false
}
/// The locked object [`locked_objects_at`] lists for member `id` of `parent`: the outermost object
/// with its own lock on, from a child of `parent` down to `id`, when a click may reach each of them
/// ([`may_reach`] with locked objects counted) and none is a locked or template layer, as
/// [`locked_children`] goes down. `None` otherwise.
fn locked_member(parent: &Node, id: NodeId, opt: HitOptions) -> Option<NodeId> {
let mut steps = vec![];
if !path_to(parent, id, &mut steps) {
return None;
}
for (n, i, c) in steps {
if !may_reach(n, i, c, opt, false) || c.is_layer() && (c.locked || c.is_template()) {
return None;
}
if c.locked {
return Some(c.id);
}
}
None
}
/// Does a click at `p` hit an object of `art` (the art [`drawn_art`] gives) that `accept` takes? The
/// objects are tried front first, the members of an Intertwine group in the order they are drawn at
/// `p` ([`hit_order`]), and `accept` is given the id and the hit kind of each object hit until it
/// takes one.
fn art_hit(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes, accept: &mut dyn FnMut(NodeId, HitKind) -> bool) -> bool {
if !n.visible {
return false;
}
if !edits_contents(n) && n.extras().shaper.is_none() && n.reach_bounds_with(symbols).is_some_and(|b| !b.inflate(opt.tol, opt.tol).contains(p)) {
return false;
}
match &n.kind {
NodeKind::Group { children, .. } | NodeKind::Layer { children, .. } | NodeKind::Intertwine { children } => {
// A layer with Preview off is clicked in outline, as [`hit_children`] clicks it.
let opt = HitOptions { outline: opt.outline || previews_off(n), ..opt };
if n.clips()
&& let Some(clip) = children.first()
{
// The selection tools take a clipping path on its outline before the art it clips,
// as [`hit_children`] does.
if opt.clip_outlines
&& clip.visible
&& let Some(kind) = clip_outline(clip, p, opt)
&& accept(clip.id, kind)
{
return true;
}
if !clip_contains(clip, p, opt.outline) {
return false;
}
}
hit_order(n, children, p).any(|i| children.get(i).is_some_and(|c| !shaper_hides(n, i, None) && art_hit(c, p, opt, symbols, accept)))
}
_ => hit_leaf(n, p, opt, symbols).is_some_and(|kind| accept(n.id, kind)),
}
}
/// The order a click at `p` tries the children of `parent` in, front first: their stacking order
/// from the top, except that in an Intertwine group the members are tried in the order they are
/// drawn at `p`, from the top ([`crate::intertwine::tier_at`]).
@@ -964,10 +1326,17 @@ thread_local! {
/// What a click at `p` hits on leaf object `n`: its outline, strokes and fills, its frame or its
/// bounds, by kind. Raster effects (drop shadows, glows, blurs) do not take clicks: the area they
/// paint beyond the object is left out here and in [`cull_reach`], so a click there reaches the
/// object under it.
/// object under it. Except in outline, a path or compound path with geometry effects is hit by the
/// art they draw ([`drawn_art`]), its own geometry only where that art lies.
fn hit_leaf(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes) -> Option<HitKind> {
#[cfg(test)]
LEAVES_TESTED.with(|c| c.set(c.get() + 1));
// A path or compound path whose geometry effects reshape it is hit where its art is drawn, and
// not where its own geometry no longer paints.
if let Some(art) = drawn_art(symbols, n, opt.outline) {
let _off = DrawnOff::set();
return art.iter().rev().find_map(|a| hit_any(a, p, opt, symbols));
}
match &n.kind {
NodeKind::Path { path, rule, .. } => {
if opt.outline
@@ -1131,16 +1500,26 @@ fn hit_any(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes) -> Option
}
// Nor art whose reach does not hold `p`, as in [`may_hit`]: a blend's steps far from `p` are
// passed by without being measured.
if !edits_contents(n) && n.extras().shaper.is_none() && n.reach_bounds_with(symbols).is_some_and(|b| !b.inflate(opt.tol, opt.tol).contains(p)) {
if !edits_contents(n)
&& n.extras().shaper.is_none()
&& drawn_reach(symbols, n, n.reach_bounds_with(symbols)).is_some_and(|b| !b.inflate(opt.tol, opt.tol).contains(p))
{
return None;
}
// A group whose own geometry effects reshape its members hits where that art is drawn.
if matches!(n.kind, NodeKind::Group { .. })
&& let Some(art) = drawn_art(symbols, n, opt.outline)
{
let _off = DrawnOff::set();
return art.iter().rev().find_map(|a| hit_any(a, p, opt, symbols));
}
match &n.kind {
// A clip group only hits inside its clipping path.
NodeKind::Group { children, clip } => {
if *clip && children.first().is_some_and(|c| !clip_contains(c, p, opt.outline)) {
return None;
}
children.iter().rev().find_map(|c| hit_any(c, p, opt, symbols))
children.iter().enumerate().rev().find_map(|(i, c)| plain(i == 0 && *clip, || hit_any(c, p, opt, symbols)))
}
// An intertwine group hits by its members, as on the canvas.
NodeKind::Intertwine { children } => children.iter().rev().find_map(|c| hit_any(c, p, opt, symbols)),
@@ -1312,7 +1691,7 @@ impl FindPart<'_> {
}
let Ok(i) = u32::try_from(i) else { continue };
path.push(i);
if let Some(kind) = self.find(c, path, whole, outline) {
if let Some(kind) = plain(i == 0 && n.clips(), || self.find(c, path, whole, outline)) {
return Some(kind);
}
path.pop();
@@ -1634,7 +2013,9 @@ pub fn compound_part_at(n: &Node, p: Point, tol: f64) -> Option<NodeId> {
/// clipping mask counts only when the marquee meets the region its clipping path clips to, and then
/// only within that region's bounds. In isolation mode the clipping mask of the isolated container,
/// or of the parent of the single object isolated, does not limit the marquee, as it does not limit
/// the selection tools' clicks.
/// the selection tools' clicks. Except in outline, a path or compound path with geometry effects, and
/// the members of a group or layer with geometry effects of its own, are touched where the art those
/// effects draw lies ([`set_drawn_art`]), as clicks hit them.
pub fn marquee(doc: &Document, r: Rect, scope: Option<NodeId>, leaves: bool) -> Vec<NodeId> {
marquee_with(doc, r, scope, leaves, false, false)
}
@@ -1660,25 +2041,30 @@ fn previews_off(n: &Node) -> bool {
fn marquee_with(doc: &Document, r: Rect, scope: Option<NodeId>, leaves: bool, whole_compounds: bool, outline: bool) -> Vec<NodeId> {
let _walk = ArtWalk::open();
let mut out = Vec::new();
let symbols = doc.symbol_boxes();
// The objects the marquee may touch ([`Top`]).
let tops: Vec<Top> = match scope.and_then(|s| doc.node(s)) {
// Isolated art whose layer, or a group around it, was locked or hidden afterwards: the
// marquee touches none of it, as clicks don't (#5309).
Some(s) if !doc.is_editable(s.id) => vec![],
Some(s) => match s.children() {
Some(c) => c
.iter()
.enumerate()
.filter(|(i, c)| !c.is_ruler_guide() && !shaper_hides(s, *i, scope))
.map(|(_, c)| (c, Some(r), outline, None))
.collect(),
Some(c) => {
// In an isolated clip group, its members by their own geometry, as clicks take
// them ([`edits_inside`]).
let drawn = if s.clips() { None } else { touched_in_art(s, &symbols, r, whole_compounds, outline || previews_off(s)) };
c.iter()
.enumerate()
.filter(|(i, c)| !c.is_ruler_guide() && !shaper_hides(s, *i, scope))
.map(|(_, c)| (c, Some(r), outline, None, drawn.clone()))
.collect()
}
// A single object isolated: only it.
None => doc
.parent_of(s.id)
.and_then(|p| doc.node(p))
.and_then(|p| p.children())
.into_iter()
.flat_map(|c| c.iter().filter(|c| c.id == s.id).map(|c| (c, Some(r), outline, None)))
.flat_map(|c| c.iter().filter(|c| c.id == s.id).map(|c| (c, Some(r), outline, None, None)))
.collect(),
},
// The objects of the layers, looking through sublayers (hidden, locked and template ones
@@ -1687,36 +2073,80 @@ fn marquee_with(doc: &Document, r: Rect, scope: Option<NodeId>, leaves: bool, wh
.layers
.iter()
.filter(|l| l.visible && !l.locked && !l.is_template() && doc.pattern_edit.as_ref().is_none_or(|e| e.layer == l.id))
.flat_map(|l| layer_objects(l, r, outline))
.flat_map(|l| layer_objects(l, &symbols, r, outline, whole_compounds, None))
.collect(),
};
/// The objects of layer `l`, each with the part of `r` that the clipping masks of `l` and of
/// the sublayers it is in leave, whether it is in outline, and for the clipping mask of `l`,
/// `r` for its edge test. The clipping mask itself counts by its own geometry within its plain
/// shapes ([`mask_marquee`]).
fn layer_objects(l: &Node, r: Rect, outline: bool) -> Vec<Top<'_>> {
/// shapes ([`mask_marquee`]). In a layer whose own geometry effects reshape its art, each object
/// comes with the objects that art touches ([`touched_in_art`]), `drawn` when a layer around
/// `l` has such effects.
fn layer_objects<'a>(
l: &'a Node,
s: &SymbolBoxes,
r: Rect,
outline: bool,
whole_compounds: bool,
drawn: Option<Rc<HashSet<NodeId>>>,
) -> Vec<Top<'a>> {
let mut out = vec![];
let outline = outline || previews_off(l);
let drawn = drawn.or_else(|| touched_in_art(l, s, r, whole_compounds, outline));
let inner = marquee_in_parent(l, r, outline);
for (i, c) in l.children().into_iter().flatten().enumerate() {
if c.is_layer() {
if let Some(inner) = inner
if let Some(inner) = if drawn.is_some() { Some(r) } else { inner }
&& c.visible
&& !c.locked
&& !c.is_template()
{
out.extend(layer_objects(c, inner, outline));
out.extend(layer_objects(c, s, inner, outline, whole_compounds, drawn.clone()));
}
} else if !c.is_ruler_guide() {
if i == 0 && l.clips() {
out.push((c, mask_marquee(l, r), outline, Some(r)));
if drawn.is_some() {
out.push((c, Some(r), outline, None, drawn.clone()));
} else if i == 0 && l.clips() {
out.push((c, mask_marquee(l, r), outline, Some(r), None));
} else if inner.is_some() {
out.push((c, inner, outline, None));
out.push((c, inner, outline, None, None));
}
}
}
out
}
/// The ids of the objects of the art that group or layer `n` draws with its own geometry
/// effects ([`drawn_art`]) that the marquee `r` touches, as [`collect_leaves`] collects them.
/// `None` in outline and when it has no such effects.
fn touched_in_art(n: &Node, s: &SymbolBoxes, r: Rect, whole_compounds: bool, outline: bool) -> Option<Rc<HashSet<NodeId>>> {
let art = drawn_art(s, n, outline)?;
let _off = DrawnOff::set();
let mut ids = vec![];
for a in art.iter().filter(|a| a.visible) {
collect_leaves(a, s, r, None, whole_compounds, false, &mut ids);
}
Some(Rc::new(ids.into_iter().collect()))
}
/// The objects inside `n` that a marquee collects ([`collect_leaves`]) whose ids are in
/// `drawn` ([`touched_in_art`]), into `out`: leaves, and groups whose own fills and strokes
/// the art paints there.
fn collect_drawn(n: &Node, drawn: &HashSet<NodeId>, scope: Option<NodeId>, out: &mut Vec<NodeId>) {
for (i, c) in n.children().into_iter().flatten().enumerate() {
if !c.visible || c.locked || shaper_hides(n, i, scope) {
continue;
}
if is_leaf(c) {
if drawn.contains(&c.id) {
out.push(c.id);
}
} else {
if drawn.contains(&c.id) && !c.is_layer() {
out.push(c.id);
}
collect_drawn(c, drawn, scope, out);
}
}
}
/// The part of `r` in which the marquee can touch the clipping path of `parent` by its own
/// geometry: within the bounds of its plain shapes ([`marquee_in`]), where clicks find its
/// outline too ([`clip_outline_hit`]), whatever its live effects do to the region it clips to.
@@ -1749,6 +2179,12 @@ fn marquee_with(doc: &Document, r: Rect, scope: Option<NodeId>, leaves: bool, wh
/// compound paths, layers and groups are touched by their box. A clipping path is touched by
/// its own geometry ([`mask_marquee`]) and on the edge of its region ([`clip_edge_touches`]).
fn touches(n: &Node, s: &SymbolBoxes, r: Rect, scope: Option<NodeId>, whole_compounds: bool, outline: bool) -> bool {
// A path or compound path whose geometry effects reshape it, or a group or layer whose own
// geometry effects reshape its members, is touched where that art is drawn ([`drawn_art`]).
if let Some(art) = drawn_art(s, n, outline || previews_off(n)) {
let _off = DrawnOff::set();
return art.iter().any(|a| a.visible && touches(a, s, r, None, whole_compounds, false));
}
match &n.kind {
NodeKind::Path { path, .. } => vectorcraft_geom::hit::intersects_rect(path, r),
NodeKind::Layer { children, .. } | NodeKind::Group { children, .. } | NodeKind::Intertwine { children } => {
@@ -1758,7 +2194,8 @@ fn marquee_with(doc: &Document, r: Rect, scope: Option<NodeId>, leaves: bool, wh
c.visible
&& !shaper_hides(n, i, scope)
&& if i == 0 && n.clips() {
mask_marquee(n, r).is_some_and(|r| touches(c, s, r, scope, whole_compounds, outline)) || clip_edge_touches(c, r, outline)
plain(true, || mask_marquee(n, r).is_some_and(|r| touches(c, s, r, scope, whole_compounds, outline)))
|| clip_edge_touches(c, r, outline)
} else {
inner.is_some_and(|r| touches(c, s, r, scope, whole_compounds, outline))
}
@@ -1812,6 +2249,15 @@ fn marquee_with(doc: &Document, r: Rect, scope: Option<NodeId>, leaves: bool, wh
match &n.kind {
NodeKind::Layer { children, .. } | NodeKind::Group { children, .. } | NodeKind::Intertwine { children } => {
let outline = outline || previews_off(n);
// The members that the art its own geometry effects draw touches, and a group whose
// own fills and strokes that art paints, as clicks hit it ([`member_chain`]).
if let Some(drawn) = touched_in_art(n, s, r, whole_compounds, outline) {
if drawn.contains(&n.id) && !n.is_layer() {
out.push(n.id);
}
collect_drawn(n, &drawn, scope, out);
return;
}
let inner = marquee_in_parent(n, r, outline);
for (i, c) in children.iter().enumerate() {
if !c.visible || c.locked || shaper_hides(n, i, scope) {
@@ -1820,7 +2266,7 @@ fn marquee_with(doc: &Document, r: Rect, scope: Option<NodeId>, leaves: bool, wh
if i == 0 && n.clips() {
let before = out.len();
if let Some(r) = mask_marquee(n, r) {
collect_leaves(c, s, r, scope, whole_compounds, outline, out);
plain(true, || collect_leaves(c, s, r, scope, whole_compounds, outline, out));
}
if out.len() == before && is_leaf(c) && clip_edge_touches(c, r, outline) {
out.push(c.id);
@@ -1837,12 +2283,33 @@ fn marquee_with(doc: &Document, r: Rect, scope: Option<NodeId>, leaves: bool, wh
}
}
}
let symbols = doc.symbol_boxes();
let locks = doc.locked_artboards();
for (t, r, outline, edge) in tops {
for (t, r, outline, edge, drawn) in tops {
if !t.visible || t.locked || locks.holds_id(t.id) {
continue;
}
// In a layer or isolated container whose own geometry effects reshape its art: by what
// that art touches.
if let Some(drawn) = drawn {
if !leaves {
let mut touched = false;
t.walk(&mut |n| touched |= drawn.contains(&n.id));
if touched {
out.push(t.id);
}
} else {
// A leaf, or a group whose own fills and strokes the art paints, and its members.
if drawn.contains(&t.id) && !t.is_layer() {
out.push(t.id);
}
if !is_leaf(t) {
collect_drawn(t, &drawn, scope, &mut out);
}
}
continue;
}
// A layer's clipping mask counts by its own geometry ([`plain`]).
let _mask = edge.is_some().then(DrawnOff::set);
if leaves {
let before = out.len();
if let Some(r) = r {
@@ -1862,8 +2329,10 @@ fn marquee_with(doc: &Document, r: Rect, scope: Option<NodeId>, leaves: bool, wh
/// An object a marquee may touch ([`marquee_with`]): the object, the part of the marquee in which
/// it can be touched (`None` when nowhere), whether it is in outline, and for the clipping mask of a
/// layer, the marquee whose edge test it also takes (`clip_edge_touches`).
type Top<'a> = (&'a std::sync::Arc<Node>, Option<Rect>, bool, Option<Rect>);
/// layer, the marquee whose edge test it also takes (`clip_edge_touches`), and in a layer or an
/// isolated container whose own geometry effects reshape its art, the ids of the objects of that art
/// the marquee touches (`touched_in_art`).
type Top<'a> = (&'a std::sync::Arc<Node>, Option<Rect>, bool, Option<Rect>, Option<Rc<HashSet<NodeId>>>);
/// The part of a marquee `r` in which it can touch the children of `parent`. For a clip group or a
/// layer with a clipping mask, this is what [`marquee_in_clip`] returns for the plain shapes of its
+417
View File
@@ -307,6 +307,423 @@ fn hovers_past_more_clip_groups_than_the_boxes_kept_evaluate_few_again() {
assert!(again < groups / 8, "{again} of {groups} regions evaluated again");
}
/// A stand-in for the engine's [`DrawnArt`]: an object with a visible effect named `test.shift`
/// draws 100 pt to the right of its own place, and one with a visible effect named `test.copy`
/// draws at its own place and 100 pt to the right. The effects are applied innermost first, and
/// the art keeps the ids of the objects it is drawn from. An instance of a symbol whose art has a
/// visible effect draws as a 50 pt square from (100, 0), white with a black 1 pt stroke. A clip
/// group with a visible effect named `test.mask_only` draws as a group of its clipping path alone,
/// as the engine's art for a clip group whose clipping path's strokes have geometry effects is.
/// Without any of these, no geometry effect changes what an object draws.
fn shifted_art(s: &SymbolBoxes<'_>, n: &Node) -> Option<Node> {
if n.clips()
&& n.appearance.effects.iter().any(|e| e.visible && e.id == "test.mask_only")
&& let Some(mask) = n.children().and_then(|c| c.first())
{
return Some(Node::group(n.id, vec![mask.clone()]));
}
fn draw(s: &SymbolBoxes<'_>, n: &Node, found: &mut bool) -> Node {
if let NodeKind::SymbolInstance { symbol, .. } = &n.kind
&& s.has_effects(symbol)
{
*found = true;
return Node::path(n.id, shapes::rectangle(Rect::new(100.0, 0.0, 150.0, 50.0)), Appearance::default_art());
}
let mut m = n.clone();
if let Some(children) = m.children_mut() {
for c in children.iter_mut() {
*c = Arc::new(draw(s, c, found));
}
}
let has = |id: &str| n.appearance.effects.iter().any(|e| e.visible && e.id == id);
let (shift, copy) = (has("test.shift"), has("test.copy"));
m.appearance.effects.retain(|e| e.id != "test.shift" && e.id != "test.copy");
*found |= shift || copy;
let shifted = |m: &Node| moved(m, vectorcraft_geom::Affine::translate((100.0, 0.0)));
if shift {
shifted(&m)
} else if copy {
Node::group(n.id, vec![Arc::new(shifted(&m)), Arc::new(m)])
} else {
m
}
}
let mut found = false;
let art = draw(s, n, &mut found);
found.then_some(art)
}
/// A visible effect named `id`.
fn effect(id: &str) -> crate::Effect {
crate::Effect { id: id.into(), params: serde_json::json!({}), visible: true }
}
/// A 50 pt square at `x`, `y`, white with a black 1 pt stroke.
fn square(d: &mut Document, x: f64, y: f64) -> Node {
Node::path(d.alloc_id(), shapes::rectangle(Rect::new(x, y, x + 50.0, y + 50.0)), Appearance::default_art())
}
/// The leaf and the kind a click at (`x`, `y`) hits.
fn hit_at(d: &Document, x: f64, y: f64, opt: HitOptions) -> Option<(NodeId, HitKind)> {
hit_test(d, Point::new(x, y), opt).map(|h| (h.leaf, h.kind))
}
/// A path that a geometry effect moves is clicked where it is drawn, and not at its own place,
/// which it no longer paints; with Object Selection by Path Only on its drawn outline, not its
/// fill. Outline view draws no effects: there its own outline is clicked. Hidden, the effect no
/// longer moves what clicks hit.
#[test]
fn a_click_hits_a_paths_shifted_art_not_its_source() {
set_drawn_art(shifted_art);
let mut d = Document::new(300.0, 200.0);
let l = d.layers[0].id;
let mut p = square(&mut d, 0.0, 0.0);
p.appearance.effects.push(effect("test.shift"));
let a = p.id;
d.insert(Some(l), 0, p).unwrap();
let opt = HitOptions::default();
assert_eq!(hit_at(&d, 125.0, 25.0, opt), Some((a, HitKind::Fill)), "where it is drawn");
assert_eq!(hit_at(&d, 25.0, 25.0, opt), None, "its own place");
assert_eq!(objects_at(&d, Point::new(125.0, 25.0), opt, None), [a]);
assert!(objects_at(&d, Point::new(25.0, 25.0), opt, None).is_empty());
let path_only = HitOptions { path_only: true, ..opt };
assert_eq!(hit_at(&d, 125.0, 25.0, path_only), None, "path only: the drawn fill");
assert_eq!(hit_at(&d, 100.0, 25.0, path_only), Some((a, HitKind::Stroke)), "path only: the drawn outline");
let outline = HitOptions { outline: true, ..opt };
assert_eq!(hit_at(&d, 0.5, 25.0, outline), Some((a, HitKind::Outline)), "outline: its own outline");
assert_eq!(hit_at(&d, 100.5, 25.0, outline), None, "outline: no drawn art");
d.node_mut(a).unwrap().appearance.effects[0].visible = false;
assert_eq!(hit_at(&d, 25.0, 25.0, opt), Some((a, HitKind::Fill)), "hidden effect: its own place");
assert_eq!(hit_at(&d, 125.0, 25.0, opt), None, "hidden effect: nothing drawn there");
}
/// A geometry effect that copies a path is clicked on the copy and on the path, the topmost of the
/// stack first. The pointer moving over it evaluates its art once until it changes, and a path
/// without effects is not evaluated.
#[test]
fn a_click_hits_a_paths_copy_and_evaluates_its_art_once_until_it_changes() {
set_drawn_art(shifted_art);
let mut d = Document::new(300.0, 200.0);
let l = d.layers[0].id;
let below = square(&mut d, 100.0, 0.0);
let mut p = square(&mut d, 0.0, 0.0);
p.appearance.effects.push(effect("test.copy"));
let (a, b) = (p.id, below.id);
d.insert(Some(l), 0, below).unwrap();
d.insert(Some(l), 1, p).unwrap();
let evaluated = || DRAWN_EVALUATED.with(std::cell::Cell::get);
let before = evaluated();
let opt = HitOptions::default();
for _ in 0..3 {
assert_eq!(hit_at(&d, 25.0, 25.0, opt).map(|h| h.0), Some(a), "the path");
assert_eq!(hit_at(&d, 125.0, 25.0, opt).map(|h| h.0), Some(a), "its copy, over the square below");
}
assert_eq!(objects_at(&d, Point::new(125.0, 25.0), opt, None), [a, b]);
assert_eq!(evaluated(), before + 1, "evaluated once");
if let Some(NodeKind::Path { path, .. }) = d.node_mut(a).map(|n| &mut n.kind) {
*path = shapes::rectangle(Rect::new(0.0, 0.0, 30.0, 50.0));
}
assert_eq!(hit_at(&d, 140.0, 25.0, opt).map(|h| h.0), Some(b), "narrowed, the copy leaves the square below");
assert_eq!(evaluated(), before + 2, "evaluated again after it changed");
// The square below has no effects: it is never evaluated.
assert_eq!(hit_at(&d, 145.0, 45.0, opt).map(|h| h.0), Some(b));
assert_eq!(evaluated(), before + 2);
}
/// A group without effects or fills and strokes of its own is not evaluated as a whole: a click
/// on the art of a moved member in it evaluates that member only, and finds the group by it.
#[test]
fn a_click_in_a_plain_group_evaluates_only_its_member_with_effects() {
set_drawn_art(shifted_art);
let mut d = Document::new(300.0, 200.0);
let l = d.layers[0].id;
let mut moved = square(&mut d, 0.0, 0.0);
moved.appearance.effects.push(effect("test.shift"));
let still = square(&mut d, 0.0, 100.0);
let (a, g) = (moved.id, d.alloc_id());
d.insert(Some(l), 0, Node::group(g, vec![Arc::new(moved), Arc::new(still)])).unwrap();
let evaluated = || DRAWN_EVALUATED.with(std::cell::Cell::get);
let before = evaluated();
let opt = HitOptions::default();
for _ in 0..3 {
assert_eq!(hit_at(&d, 125.0, 25.0, opt), Some((a, HitKind::Fill)));
assert_eq!(objects_at(&d, Point::new(125.0, 25.0), opt, None), [g]);
}
assert_eq!(evaluated(), before + 1, "only the member with effects, once");
}
/// A compound path that a geometry effect moves keeps its hole where it is drawn, for clicks and
/// marquees.
#[test]
fn a_compound_paths_shifted_art_keeps_its_hole() {
set_drawn_art(shifted_art);
let mut d = Document::new(300.0, 200.0);
let l = d.layers[0].id;
let outer = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(0.0, 0.0, 60.0, 60.0)), Appearance::default());
let hole = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(20.0, 20.0, 40.0, 40.0)), Appearance::default());
let c = d.alloc_id();
let mut compound = Node::new(c, NodeKind::Compound { children: vec![Arc::new(outer), Arc::new(hole)], rule: FillRule::EvenOdd });
compound.appearance = Appearance::default_art().into();
compound.appearance.effects.push(effect("test.shift"));
d.insert(Some(l), 0, compound).unwrap();
let opt = HitOptions::default();
assert_eq!(hit_at(&d, 105.0, 5.0, opt), Some((c, HitKind::Fill)), "its drawn fill");
assert_eq!(hit_at(&d, 130.0, 30.0, opt), None, "its drawn hole");
assert_eq!(hit_at(&d, 5.0, 5.0, opt), None, "its own place");
assert_eq!(marquee(&d, Rect::new(155.0, 25.0, 165.0, 35.0), None, false), [c], "a marquee across the drawn edge");
assert!(marquee(&d, Rect::new(-5.0, 25.0, 5.0, 35.0), None, false).is_empty(), "a marquee across its own edge");
}
/// A marquee touches a path that a geometry effect moves where it is drawn, and not at its own
/// place; in Outline view, at its own place.
#[test]
fn a_marquee_touches_a_paths_shifted_art_not_its_source() {
set_drawn_art(shifted_art);
let mut d = Document::new(300.0, 200.0);
let l = d.layers[0].id;
let mut p = square(&mut d, 0.0, 0.0);
p.appearance.effects.push(effect("test.shift"));
let a = p.id;
d.insert(Some(l), 0, p).unwrap();
let (drawn, own) = (Rect::new(140.0, 40.0, 160.0, 60.0), Rect::new(40.0, 40.0, 60.0, 60.0));
for leaves in [false, true] {
assert_eq!(marquee(&d, drawn, None, leaves), [a], "where it is drawn");
assert!(marquee(&d, own, None, leaves).is_empty(), "its own place");
assert!(marquee_in_view(&d, drawn, None, leaves, true).is_empty(), "outline: no drawn art");
assert_eq!(marquee_in_view(&d, own, None, leaves, true), [a], "outline: its own place");
}
}
/// A group whose own geometry effect moves its members is clicked where each member is drawn: the
/// member, inside the group, is hit, and a locked member lets the click through to what is below
/// and is listed for unlocking there. A marquee there touches the group, or the member for Direct
/// Selection.
#[test]
fn a_groups_own_effect_moves_where_its_members_are_hit() {
set_drawn_art(shifted_art);
let mut d = Document::new(300.0, 200.0);
let l = d.layers[0].id;
let below = square(&mut d, 150.0, 0.0);
let (a, b) = (square(&mut d, 0.0, 0.0), square(&mut d, 50.0, 0.0));
let (below_id, a_id, b_id, g) = (below.id, a.id, b.id, d.alloc_id());
let mut group = Node::group(g, vec![Arc::new(a), Arc::new(b)]);
group.appearance.effects.push(effect("test.shift"));
d.insert(Some(l), 0, below).unwrap();
d.insert(Some(l), 1, group).unwrap();
let opt = HitOptions::default();
let h = hit_test(&d, Point::new(125.0, 25.0), opt).unwrap();
assert_eq!((h.leaf, h.top_object(None)), (a_id, g), "the first member, drawn there");
assert_eq!(h.ancestry, [l, g, a_id]);
assert_eq!(hit_at(&d, 175.0, 25.0, opt).map(|h| h.0), Some(b_id), "the second member, over the square below");
assert_eq!(hit_at(&d, 25.0, 25.0, opt), None, "the first member's own place");
assert_eq!(objects_at(&d, Point::new(175.0, 25.0), opt, None), [g, below_id]);
let drawn = Rect::new(195.0, 20.0, 205.0, 30.0);
assert_eq!(marquee(&d, drawn, None, false), [below_id, g]);
assert_eq!(marquee(&d, drawn, None, true), [below_id, b_id]);
assert!(marquee(&d, Rect::new(-5.0, 20.0, 5.0, 30.0), None, true).is_empty(), "the members' own place");
d.node_mut(b_id).unwrap().locked = true;
assert_eq!(hit_at(&d, 175.0, 25.0, opt).map(|h| h.0), Some(below_id), "a locked member lets the click through");
assert_eq!(marquee(&d, drawn, None, true), [below_id], "nor does a marquee collect it");
assert_eq!(locked_objects_at(&d, Point::new(175.0, 25.0), opt), [b_id], "the Unlock submenu lists it where it is drawn");
assert!(locked_objects_at(&d, Point::new(75.0, 25.0), opt).is_empty(), "and not at its own place");
// Outline view draws no effects: the members are clicked at their own places.
let outline = HitOptions { outline: true, ..opt };
assert_eq!(hit_at(&d, 0.5, 25.0, outline).map(|h| h.0), Some(a_id));
}
/// A layer whose own geometry effect moves its art is clicked and marqueed where the art is
/// drawn. With the layer's Preview off, its art is clicked at its own place, in outline.
#[test]
fn a_layers_own_effect_moves_where_its_art_is_hit() {
set_drawn_art(shifted_art);
let mut d = Document::new(300.0, 200.0);
let l = d.layers[0].id;
let a = square(&mut d, 0.0, 0.0);
let a_id = a.id;
d.insert(Some(l), 0, a).unwrap();
d.node_mut(l).unwrap().appearance.effects.push(effect("test.shift"));
let opt = HitOptions::default();
assert_eq!(hit_at(&d, 125.0, 25.0, opt), Some((a_id, HitKind::Fill)), "where it is drawn");
assert_eq!(hit_at(&d, 25.0, 25.0, opt), None, "its own place");
assert_eq!(objects_at(&d, Point::new(125.0, 25.0), opt, None), [a_id]);
assert!(objects_at(&d, Point::new(25.0, 25.0), opt, None).is_empty());
let (drawn, own) = (Rect::new(145.0, 20.0, 155.0, 30.0), Rect::new(-5.0, 20.0, 5.0, 30.0));
for leaves in [false, true] {
assert_eq!(marquee(&d, drawn, None, leaves), [a_id], "a marquee where it is drawn");
assert!(marquee(&d, own, None, leaves).is_empty(), "a marquee at its own place");
}
if let Some(NodeKind::Layer { preview, .. }) = d.node_mut(l).map(|n| &mut n.kind) {
*preview = false;
}
assert_eq!(hit_at(&d, 0.5, 25.0, opt), Some((a_id, HitKind::Outline)), "preview off: its own outline");
assert_eq!(hit_at(&d, 125.0, 25.0, opt), None, "preview off: no drawn art");
assert_eq!(marquee(&d, own, None, false), [a_id], "preview off: a marquee at its own place");
}
/// In a layer whose own geometry effect moves its art, a sublayer with Preview off is clicked in
/// outline: on the outline of its art where the art is drawn, not inside its fill.
#[test]
fn a_preview_off_sublayer_of_an_effected_layer_is_clicked_in_outline() {
set_drawn_art(shifted_art);
let mut d = Document::new(300.0, 200.0);
let l = d.layers[0].id;
let sub = d.alloc_id();
d.insert(Some(l), 0, Node::layer(sub, "Sub", crate::LayerColor::Preset(2))).unwrap();
let a = square(&mut d, 0.0, 0.0);
let a_id = a.id;
d.insert(Some(sub), 0, a).unwrap();
d.node_mut(l).unwrap().appearance.effects.push(effect("test.shift"));
let opt = HitOptions::default();
assert_eq!(hit_at(&d, 125.0, 25.0, opt), Some((a_id, HitKind::Fill)), "preview on: inside its fill");
if let Some(NodeKind::Layer { preview, .. }) = d.node_mut(sub).map(|n| &mut n.kind) {
*preview = false;
}
assert_eq!(hit_at(&d, 125.0, 25.0, opt), None, "preview off: inside its fill");
assert_eq!(hit_at(&d, 100.5, 25.0, opt), Some((a_id, HitKind::Outline)), "preview off: on its outline");
}
/// A group with fills and strokes of its own around an instance of a symbol whose art has an
/// effect is clicked where its art is drawn, though no object in the group has an effect.
#[test]
fn a_painted_group_around_an_effected_symbols_instance_is_hit_where_its_art_is_drawn() {
set_drawn_art(shifted_art);
let mut d = Document::new(300.0, 200.0);
let l = d.layers[0].id;
let mut art = square(&mut d, 0.0, 0.0);
art.appearance.effects.push(effect("test.raster"));
d.symbols.push(crate::Symbol { dynamic: false, name: "Effected".into(), art: Arc::new(art) });
let (g, inst) = (d.alloc_id(), d.alloc_id());
let instance = Node::new(inst, NodeKind::SymbolInstance { symbol: "Effected".into(), xf: vectorcraft_geom::Affine::IDENTITY });
let mut group = Node::group(g, vec![Arc::new(instance)]);
group.appearance = Appearance::default_art().into();
d.insert(Some(l), 0, group).unwrap();
let opt = HitOptions::default();
assert_eq!(hit_at(&d, 125.0, 25.0, opt), Some((inst, HitKind::Fill)), "where its art is drawn");
assert_eq!(objects_at(&d, Point::new(125.0, 25.0), opt, None), [g]);
}
/// In a layer with fills and strokes of its own whose art is evaluated for a member's geometry
/// effect, an Intertwine group's members are still clicked in the order they are drawn at the
/// click: where the lower member is woven over the upper one, the click takes the lower member.
#[test]
fn an_intertwine_group_in_a_layers_drawn_art_is_hit_in_its_woven_order() {
set_drawn_art(shifted_art);
let mut d = Document::new(300.0, 200.0);
let l = d.layers[0].id;
d.node_mut(l).unwrap().appearance = Appearance::default_art().into();
let mut a = square(&mut d, 0.0, 100.0);
a.extras_mut().intertwine = Some(Box::new(shapes::rectangle(Rect::new(25.0, 100.0, 50.0, 150.0))));
let b = square(&mut d, 25.0, 100.0);
let (a_id, b_id, g) = (a.id, b.id, d.alloc_id());
d.insert(Some(l), 0, Node::new(g, NodeKind::Intertwine { children: vec![Arc::new(a), Arc::new(b)] })).unwrap();
let mut moved = square(&mut d, 200.0, 0.0);
moved.appearance.effects.push(effect("test.shift"));
d.insert(Some(l), 1, moved).unwrap();
let opt = HitOptions::default();
assert_eq!(hit_at(&d, 40.0, 125.0, opt), Some((a_id, HitKind::Fill)), "where the lower member is woven over");
assert_eq!(hit_at(&d, 60.0, 125.0, opt), Some((b_id, HitKind::Fill)), "where the upper member is drawn over");
}
/// The clipping path of a clip group and of a clipping layer is still marqueed by its own geometry
/// when a geometry effect moves what it draws.
#[test]
fn a_clipping_path_keeps_its_own_geometry_under_a_geometry_effect() {
set_drawn_art(shifted_art);
let edge = Rect::new(-5.0, 40.0, 5.0, 60.0);
// A clip group.
let mut d = Document::new(300.0, 200.0);
let l = d.layers[0].id;
let (mut mask, art) = half_clipped(&mut d);
mask.appearance.effects.push(effect("test.shift"));
let (g, mask_id, art_id) = (d.alloc_id(), mask.id, art.id);
let mut clip = Node::group(g, vec![Arc::new(mask), Arc::new(art)]);
clip.set_clips(true);
d.insert(Some(l), 0, clip).unwrap();
assert_eq!(marquee(&d, edge, None, true), [mask_id, art_id], "clip group");
// A clipping layer.
let mut d = Document::new(300.0, 200.0);
let l = d.layers[0].id;
let (mut mask, art) = half_clipped(&mut d);
mask.appearance.effects.push(effect("test.shift"));
let (mask_id, art_id) = (mask.id, art.id);
let layer = d.node_mut(l).unwrap();
if let NodeKind::Layer { children, clip, .. } = &mut layer.kind {
(*children, *clip) = (vec![Arc::new(mask), Arc::new(art)], true);
}
assert_eq!(marquee(&d, edge, None, true), [mask_id, art_id], "clipping layer");
}
/// The selection tools take the clipping path of a clip group whose own geometry effect moves it
/// on its outline where it is drawn, before the art it clips, and not at its own place.
#[test]
fn a_clip_groups_own_effect_moves_where_its_mask_outline_is_hit() {
set_drawn_art(shifted_art);
let mut d = Document::new(400.0, 200.0);
let l = d.layers[0].id;
let (mask, art) = half_clipped(&mut d);
let (g, mask_id, art_id) = (d.alloc_id(), mask.id, art.id);
let mut clip = Node::group(g, vec![Arc::new(mask), Arc::new(art)]);
clip.set_clips(true);
clip.appearance.effects.push(effect("test.shift"));
d.insert(Some(l), 0, clip).unwrap();
let tools = HitOptions { clip_outlines: true, ..HitOptions::default() };
assert_eq!(hit_at(&d, 199.5, 50.0, tools), Some((mask_id, HitKind::Outline)), "the drawn edge, over the art");
assert_eq!(hit_at(&d, 150.0, 50.0, tools).map(|h| h.0), Some(art_id), "the drawn art inside the mask");
assert_eq!(hit_at(&d, 0.5, 50.0, tools), None, "the mask's own edge");
// The same clip group in a group whose own effect moves it.
let mut d = Document::new(400.0, 200.0);
let l = d.layers[0].id;
let (mask, art) = half_clipped(&mut d);
let (g, mask_id, art_id) = (d.alloc_id(), mask.id, art.id);
let mut clip = Node::group(g, vec![Arc::new(mask), Arc::new(art)]);
clip.set_clips(true);
let mut outer = Node::group(d.alloc_id(), vec![Arc::new(clip)]);
outer.appearance.effects.push(effect("test.shift"));
d.insert(Some(l), 0, outer).unwrap();
assert_eq!(hit_at(&d, 199.5, 50.0, tools), Some((mask_id, HitKind::Outline)), "in a moved group: the drawn edge, over the art");
assert_eq!(hit_at(&d, 150.0, 50.0, tools).map(|h| h.0), Some(art_id), "in a moved group: the drawn art");
}
/// In isolation mode in a clip group whose own geometry effect moves it, the selection tools take
/// the art outside the clipping mask by its own geometry, for a marquee as for a click.
#[test]
fn an_isolated_clip_group_with_its_own_effect_is_marqueed_by_its_members_own_geometry() {
set_drawn_art(shifted_art);
let mut d = Document::new(400.0, 200.0);
let l = d.layers[0].id;
let (mask, art) = half_clipped(&mut d);
let (g, art_id) = (d.alloc_id(), art.id);
let mut clip = Node::group(g, vec![Arc::new(mask), Arc::new(art)]);
clip.set_clips(true);
clip.appearance.effects.push(effect("test.shift"));
d.insert(Some(l), 0, clip).unwrap();
let tools = HitOptions { clip_outlines: true, scope: Some(g), ..HitOptions::default() };
assert_eq!(hit_at(&d, 150.0, 50.0, tools).map(|h| h.0), Some(art_id), "a click outside the mask");
let edge = Rect::new(190.0, 40.0, 210.0, 60.0);
for leaves in [false, true] {
assert_eq!(marquee(&d, edge, Some(g), leaves), [art_id], "a marquee across its own edge outside the mask");
}
}
/// A clip group whose drawn art holds only its clipping path still has the art it clips clicked
/// inside the mask.
#[test]
fn a_clip_groups_art_is_hit_when_its_drawn_art_holds_only_the_clipping_path() {
set_drawn_art(shifted_art);
let mut d = Document::new(400.0, 200.0);
let l = d.layers[0].id;
let (mask, art) = half_clipped(&mut d);
let (g, art_id) = (d.alloc_id(), art.id);
let mut clip = Node::group(g, vec![Arc::new(mask), Arc::new(art)]);
clip.set_clips(true);
clip.appearance.effects.push(effect("test.mask_only"));
d.insert(Some(l), 0, clip).unwrap();
let opt = HitOptions::default();
assert_eq!(hit_at(&d, 50.0, 50.0, opt), Some((art_id, HitKind::Fill)), "inside the mask");
assert_eq!(objects_at(&d, Point::new(50.0, 50.0), opt, None), [g]);
assert!(hit_at(&d, 150.0, 50.0, opt).is_none(), "outside the mask");
}
/// Every test of a clip group by its clipping path follows the region a live effect moved it to:
/// the selected art hidden by the mask, a click into a group holding the clip group, the locked
/// objects under the pointer, and, below a clipping layer whose Preview is on, art on a sublayer
+3
View File
@@ -26,6 +26,9 @@ impl Session {
vectorcraft_doc::hit::set_image_paint(vectorcraft_render::effects::image_paint);
// Clicks inside a clip group fall in the region its clipping path's effects give it.
vectorcraft_doc::hit::set_clip_region(vectorcraft_render::effects::reshaped_clip_outline);
// Clicks and marquees find paths, compound paths, groups and layers where their geometry
// effects draw them.
vectorcraft_doc::hit::set_drawn_art(vectorcraft_render::effects::preview::drawn_art);
// Clicks find a blend's steps and an envelope's distorted art where the canvas draws them,
// evaluated again when the fonts, the hyphenation exceptions or the plug-ins change.
vectorcraft_doc::hit::set_live_art(vectorcraft_render::effects::expand_live, || {
+105 -1
View File
@@ -1,6 +1,6 @@
//! Clicks, hovers and marquees with the selection tools leave out the area that raster effects
//! (drop shadows, glows, blurs) paint beyond an object: there they reach the object under the
//! effect, or nothing.
//! effect, or nothing. Clicks and marquees take art where its geometry effects draw it.
use serde_json::{Value, json};
use vectorcraft_doc::NodeId;
@@ -391,3 +391,107 @@ fn group_selection_hover_over_a_drop_shadow_marks_nothing() {
}
assert_eq!(press(&mut s, "groupSelection", (110.0, 50.0), (110.0, 50.0), Mods::default()), [b]);
}
/// A rectangle that a Transform effect moves 100 pt to the right is selected by a click and by a
/// marquee where it is drawn, and not at its own place, which it no longer paints. The same holds
/// for a group whose own Transform effect moves it.
#[test]
fn a_click_and_a_marquee_select_art_where_its_transform_effect_draws_it() {
let mut s = session();
let a = rect(&mut s, 20.0, 20.0, 40.0, 40.0, "#ff0000");
run(&mut s, "effect.apply", json!({"effect": "distort.transform", "ids": [a.0], "params": {"moveH": 100}, "item": null}));
assert_eq!(pixel(&s, 140, 40), [255, 0, 0, 255], "drawn where it moved");
assert_eq!(pixel(&s, 40, 40), WHITE, "not drawn at its own place");
run(&mut s, "select.none", json!({}));
assert!(click(&mut s, 40.0, 40.0).is_empty());
assert_eq!(click(&mut s, 140.0, 40.0), [a]);
assert_eq!(press(&mut s, "selection", (110.0, 10.0), (130.0, 30.0), Mods::default()), [a], "a marquee across its drawn corner");
run(&mut s, "select.none", json!({}));
assert!(press(&mut s, "selection", (10.0, 10.0), (30.0, 30.0), Mods::default()).is_empty(), "a marquee across its own corner");
let mut s = session();
let b = rect(&mut s, 20.0, 120.0, 40.0, 40.0, "#0000ff");
run(&mut s, "select.set", json!({"ids": [b.0]}));
let g = id_of(&run(&mut s, "object.group", json!({})));
run(&mut s, "effect.apply", json!({"effect": "distort.transform", "ids": [g.0], "params": {"moveH": 100}, "item": null}));
assert_eq!(pixel(&s, 140, 140), BLUE, "the group drawn where it moved");
run(&mut s, "select.none", json!({}));
assert!(click(&mut s, 40.0, 140.0).is_empty());
assert_eq!(click(&mut s, 140.0, 140.0), [g]);
assert_eq!(press(&mut s, "selection", (110.0, 110.0), (130.0, 130.0), Mods::default()), [g]);
run(&mut s, "select.none", json!({}));
assert!(press(&mut s, "selection", (10.0, 110.0), (30.0, 130.0), Mods::default()).is_empty());
}
/// A group's own fill paints its member's shape before the member's own Transform effect moves the
/// member: a click there selects the group, and a click on the moved member selects it too. A
/// Direct Selection marquee takes the group there and the member where it moved.
#[test]
fn a_click_selects_a_group_where_its_own_fill_paints_a_moved_member() {
let mut s = session();
let b = rect(&mut s, 20.0, 120.0, 40.0, 40.0, "#0000ff");
run(&mut s, "select.set", json!({"ids": [b.0]}));
let g = id_of(&run(&mut s, "object.group", json!({})));
run(&mut s, "appearance.addFill", json!({}));
run(&mut s, "appearance.setActiveItem", json!({"index": 0}));
run(&mut s, "paint.setFill", json!({"color": "#ff0000"}));
run(&mut s, "effect.apply", json!({"effect": "distort.transform", "ids": [b.0], "params": {"moveH": 100}, "item": null}));
assert_eq!(pixel(&s, 40, 140), [255, 0, 0, 255], "the group's fill at the member's own place");
assert_eq!(pixel(&s, 140, 140), BLUE, "the member where it moved");
run(&mut s, "select.none", json!({}));
assert_eq!(click(&mut s, 40.0, 140.0), [g]);
run(&mut s, "select.none", json!({}));
assert_eq!(click(&mut s, 140.0, 140.0), [g]);
// A marquee across the edge of the group's fill takes the group, and one across the moved
// member's edge takes the member.
let doc = &s.doc().unwrap().doc;
assert_eq!(vectorcraft_doc::hit::marquee(doc, Rect::new(10.0, 130.0, 30.0, 150.0), None, true), [g]);
assert_eq!(vectorcraft_doc::hit::marquee(doc, Rect::new(110.0, 130.0, 130.0, 150.0), None, true), [b]);
}
/// An inner group's own fill paints its member's shape before the member's own Transform effect
/// moves the member, and so does an outer group's own fill around it: a Direct Selection marquee
/// across the edge of those fills takes both groups, and one across the moved member takes it.
#[test]
fn a_marquee_takes_an_inner_groups_own_fill_inside_a_painted_group() {
let mut s = session();
let b = rect(&mut s, 20.0, 120.0, 40.0, 40.0, "#0000ff");
run(&mut s, "select.set", json!({"ids": [b.0]}));
let g = id_of(&run(&mut s, "object.group", json!({})));
run(&mut s, "appearance.addFill", json!({}));
run(&mut s, "appearance.setActiveItem", json!({"index": 0}));
run(&mut s, "paint.setFill", json!({"color": "#ff0000"}));
run(&mut s, "effect.apply", json!({"effect": "distort.transform", "ids": [b.0], "params": {"moveV": -100}, "item": null}));
run(&mut s, "select.set", json!({"ids": [g.0]}));
let o = id_of(&run(&mut s, "object.group", json!({})));
run(&mut s, "appearance.addFill", json!({}));
run(&mut s, "appearance.setActiveItem", json!({"index": 0}));
run(&mut s, "paint.setFill", json!({"color": "#00ff00"}));
assert_eq!(pixel(&s, 40, 140), [0, 255, 0, 255], "the outer group's fill at the member's own place");
assert_eq!(pixel(&s, 40, 40), BLUE, "the member where it moved");
let doc = &s.doc().unwrap().doc;
assert_eq!(vectorcraft_doc::hit::marquee(doc, Rect::new(10.0, 130.0, 30.0, 150.0), None, true), [o, g]);
assert_eq!(vectorcraft_doc::hit::marquee(doc, Rect::new(10.0, 30.0, 30.0, 50.0), None, true), [b]);
}
/// A group's own fill paints its member's shape before the member's own Transform effect moves
/// the member, and so does its layer's own fill around it: a Direct Selection marquee across the
/// edge of the group's fill takes the group, and one across the moved member takes it.
#[test]
fn a_marquee_takes_a_groups_own_fill_inside_a_painted_layer() {
let mut s = session();
let b = rect(&mut s, 20.0, 120.0, 40.0, 40.0, "#0000ff");
run(&mut s, "select.set", json!({"ids": [b.0]}));
let g = id_of(&run(&mut s, "object.group", json!({})));
run(&mut s, "appearance.addFill", json!({}));
run(&mut s, "appearance.setActiveItem", json!({"index": 0}));
run(&mut s, "paint.setFill", json!({"color": "#ff0000"}));
run(&mut s, "effect.apply", json!({"effect": "distort.transform", "ids": [b.0], "params": {"moveV": -100}, "item": null}));
let l = s.doc().unwrap().doc.layers[0].id;
run(&mut s, "appearance.addFill", json!({"ids": [l.0]}));
assert!(!s.doc().unwrap().doc.layers[0].appearance.items.is_empty(), "the layer has a fill of its own");
assert_eq!(pixel(&s, 40, 40), BLUE, "the member where it moved");
let doc = &s.doc().unwrap().doc;
assert_eq!(vectorcraft_doc::hit::marquee(doc, Rect::new(10.0, 130.0, 30.0, 150.0), None, true), [g]);
assert_eq!(vectorcraft_doc::hit::marquee(doc, Rect::new(10.0, 30.0, 30.0, 50.0), None, true), [b]);
}
+1
View File
@@ -661,6 +661,7 @@ since 2026-10-01.
- **Escape in Selection tool drags:** Escape during a Selection tool move or Alt-drag copy, a bounding-box scale or rotation, a marquee, or a corner widget, pie widget or bracket drag cancels it: the art returns to its state at the press, no copy is left, no undo step is added, the release does nothing, and the tool stays chosen. This is VectorCraft's own behavior. Regression tests: `escape_cancels_*` in `select/tests.rs` and `pie.rs`, and `escape_cancels_a_selection_tool_move_copy_scale_or_rotation` in `tests/selectescape.rs`.
- **Selection passes through raster effects:** clicks with the Selection, Direct Selection and Group Selection tools (Group Selection's repeated click included), the Selection tool's pointer and marquee, Direct Selection's marquee, pointer and anchor highlight, and Group Selection's marquee (E for enclosed objects included) leave out the area that a drop shadow, a glow, a blur or another raster effect paints beyond an object. A click on a shadow selects the object under it, or nothing over an empty canvas, a repeated Group Selection click there adds the groups of the object under it, and a press on the shadow of a selected object does not move it ([the help page](https://helpx.adobe.com/illustrator/using/selecting-objects.html)). Over a shadow, Direct Selection highlights only the anchors of the object under it, and Group Selection keeps its own pointer and highlights no anchor, as it does everywhere (VectorCraft's own rule). No setting changes this. This covers paths, groups, type, symbol instances and images. Regression tests: `crates/engine/src/tests/select_effects.rs`.
- **Symbol instances are selected where their art draws past their box:** a click or a marquee selects a symbol instance where a clipping path in its art, moved or reshaped by its live geometry effects, shows the art past the instance's box, as it selects a group of the same art; a click also selects it where a stroke in its art paints past the box ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-objects/select-objects/select-objects.html)). The rest is VectorCraft's own rule: inside the box the instance is selected as before; in Outline view and below a layer whose Preview is off only the box counts; hidden art and the area a raster effect paints are left out. This covers instances in groups, nested in other symbols' art, moved and scaled. Regression tests: `a_symbol_instance_is_hit_where_a_moved_clipping_path_in_its_art_shows_the_art` and `a_symbol_instance_is_hit_on_the_stroke_of_its_art_past_its_box` in `crates/doc/src/hit/tests.rs`.
- **Selection follows geometry effects:** a click or a marquee with the selection tools selects a path or compound path where its live geometry effects (Transform, Offset Path, Roughen, Zig Zag and the other effects that reshape a path, on the object or on its fills and strokes) draw it, the copies a Transform effect makes included, and not where its own geometry no longer paints. The members of a group or layer whose own geometry effects move or reshape them are selected where they are drawn, at the depth each tool selects, and a locked member there lets the click through to what is below and is listed there in the Unlock submenu. A group's own fills and strokes are clicked where they paint its members, and a clipping path inside such a group is taken on its drawn outline before the art it clips. A compound path keeps its holes, Object Selection by Path Only takes the drawn outline and not its fill, and stacking order is kept. The selection tools select objects by clicking or by a marquee ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-objects/select-objects/select-objects.html)), and the effects leave the art they reshape editable ([the help page](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/apply-filter-effects/apply-and-modify-effects.html)); where clicks land on the reshaped art is VectorCraft's own rule. In Outline view clicks and marquees use the plain paths, and in a layer with Preview off they take outlines only. The area a raster effect paints is still left out. Regression tests: `a_*_shifted_art_*`, `a_click_hits_a_paths_copy_and_evaluates_its_art_once_until_it_changes`, `a_groups_own_effect_moves_where_its_members_are_hit`, `a_layers_own_effect_moves_where_its_art_is_hit`, `a_preview_off_sublayer_of_an_effected_layer_is_clicked_in_outline`, `a_painted_group_around_an_effected_symbols_instance_is_hit_where_its_art_is_drawn`, `an_intertwine_group_in_a_layers_drawn_art_is_hit_in_its_woven_order`, `a_click_in_a_plain_group_evaluates_only_its_member_with_effects`, `a_clip_groups_own_effect_moves_where_its_mask_outline_is_hit`, `an_isolated_clip_group_with_its_own_effect_is_marqueed_by_its_members_own_geometry` and `a_clip_groups_art_is_hit_when_its_drawn_art_holds_only_the_clipping_path` in `crates/doc/src/hit/tests.rs`, and `a_click_and_a_marquee_select_art_where_its_transform_effect_draws_it`, `a_click_selects_a_group_where_its_own_fill_paints_a_moved_member`, `a_marquee_takes_an_inner_groups_own_fill_inside_a_painted_group` and `a_marquee_takes_a_groups_own_fill_inside_a_painted_layer` in `crates/engine/src/tests/select_effects.rs`.
- **Global Edit: Shift-click leaves a match out:** while Global Edit is on, a Shift-click with the Selection tool on a highlighted match, or on an object inside a matched group, leaves that match out (`select.globalEditExclude`): it is no longer highlighted and later edits leave it as it is; the object the edit started from stays, and Global Edit ends when fewer than two matches are left ([Update assets quickly with Global Edit](https://helpx.adobe.com/ph_fil/illustrator/how-to/global-editing-sensei.html)). Regression tests: `a_shift_click_*`, `an_object_left_out_*`, `a_group_left_out_*` and `leaving_out_all_but_one_*` in `crates/engine/src/tests/globaledit.rs`.
- **Global Edit leaves out groups holding type or images:** Select › Start Global Edit on a group that holds type or an image, at any depth, refuses to start, and such a group is not taken as a match, as Global Edit does not take images or text ([Edit similar objects globally](https://helpx.adobe.com/illustrator/desktop/manage-objects/edit-objects/edit-similar-objects.html)). Regression test for a group holding type: `global_edit_needs_one_supported_object` in `crates/engine/src/tests/globaledit.rs`.
- **Global Edit Options in the Control bar:** while Select › Start Global Edit can run, the Control bar shows a Global Edit Options dropdown that opens the same options as the Properties panel's (Match: Appearance, Size; On Artboards; Include Objects On Canvas; Result(s)); both set the same options. The dropdown is off while Global Edit is on; it sits after Recolor Artwork, ahead of the X/Y/W/H fields ([Edit similar objects globally](https://helpx.adobe.com/illustrator/desktop/manage-objects/edit-objects/edit-similar-objects.html)). Regression test: `the_control_bar_shows_the_global_edit_options` in `crates/ui-egui/src/chrome/tests.rs`.