mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 13:08:32 +00:00
Merge pull request #8102 from slafebre/fix/8093-pathfinder-clip-masks
Fix #8093: Pathfinder takes a clip group's members where its mask shows them
This commit is contained in:
@@ -9,7 +9,7 @@ use serde_json::{Value, json};
|
||||
use vectorcraft_color::BlendMode;
|
||||
use vectorcraft_doc::appearance::{AppearanceItem, StrokeLayer};
|
||||
use vectorcraft_doc::{AnchorRef, Appearance, Document, Node, NodeId, NodeKind, SegmentRef, TextObject};
|
||||
use vectorcraft_geom::{FillRule, PathData};
|
||||
use vectorcraft_geom::{FillRule, PathData, SubPath};
|
||||
use vectorcraft_pathops as po;
|
||||
use vectorcraft_pathops::{BoolOp, PathfinderOp};
|
||||
|
||||
@@ -352,6 +352,94 @@ pub(crate) fn pf_leaves(d: &Document, n: &Node, out: &mut Vec<Node>) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The region a clip group's members show through: its clipping path's outline
|
||||
/// ([`vectorcraft_render::effects::clip_outline`]), cut by the clip groups around it.
|
||||
struct Clip {
|
||||
path: PathData,
|
||||
rule: FillRule,
|
||||
}
|
||||
|
||||
/// Does `path` have an anchor or handle that isn't a finite number?
|
||||
fn has_invalid_coordinates(path: &PathData) -> bool {
|
||||
path.subpaths.iter().flat_map(|sp| &sp.anchors).any(|a| [a.p, a.h_in, a.h_out].iter().any(|q| !(q.x.is_finite() && q.y.is_finite())))
|
||||
}
|
||||
|
||||
/// A Pathfinder operation's leaf shape ([`pf_leaves`]) with the region its clip groups show it
|
||||
/// through, `None` outside any clip group.
|
||||
type ClippedLeaf = (Node, Option<Arc<Clip>>);
|
||||
|
||||
/// [`pf_leaves`], each with the region the clip groups it is in show it through (#8093). A clip
|
||||
/// group's clipping path is not a leaf, and the members of one whose clipping path clips by nothing
|
||||
/// are hidden, as on the canvas: their region is empty.
|
||||
fn clipped_pf_leaves(d: &Document, n: &Node, clip: Option<&Arc<Clip>>, precision: f64, out: &mut Vec<ClippedLeaf>) -> Result<()> {
|
||||
let (NodeKind::Group { children, clip: clips } | NodeKind::Layer { children, clip: clips, .. }) = &n.kind else {
|
||||
let mut lv = vec![];
|
||||
leaves(n, &mut lv);
|
||||
out.extend(lv.into_iter().map(|l| (l, clip.cloned())));
|
||||
return Ok(());
|
||||
};
|
||||
let hook = |c: &Node| vectorcraft_render::effects::outline_object(Some(d), c);
|
||||
if let Some(art) = vectorcraft_render::effects::compound_shape_art(Some(d), n, Some(&hook)) {
|
||||
out.push((art, clip.cloned()));
|
||||
return Ok(());
|
||||
}
|
||||
if !*clips {
|
||||
return children.iter().try_for_each(|c| clipped_pf_leaves(d, c, clip, precision, out));
|
||||
}
|
||||
let Some((first, rest)) = children.split_first() else { return Ok(()) };
|
||||
let mut region = match vectorcraft_render::effects::clip_outline(first) {
|
||||
Some((outline, rule)) => Clip { path: PathData::from_bezpath(&outline), rule },
|
||||
None => Clip { path: PathData::default(), rule: FillRule::NonZero },
|
||||
};
|
||||
if has_invalid_coordinates(®ion.path) {
|
||||
return Err(EngineError::Other("paths contain invalid coordinates".into()));
|
||||
}
|
||||
if let Some(outer) = clip.filter(|_| !region.path.is_empty()) {
|
||||
let path = po::try_boolean(®ion.path, region.rule, &outer.path, outer.rule, BoolOp::Intersect, precision)
|
||||
.map_err(|e| EngineError::Other(e.to_string()))?;
|
||||
region = Clip { path, rule: FillRule::NonZero };
|
||||
}
|
||||
let region = Arc::new(region);
|
||||
rest.iter().try_for_each(|c| clipped_pf_leaves(d, c, Some(®ion), precision, out))
|
||||
}
|
||||
|
||||
/// `path`, filled by `rule`, where `clip` shows it: its area intersected with the region, filled
|
||||
/// non-zero, and with `lines` (Divide, whose open contours cut) its open contours' parts inside the
|
||||
/// region, so their hidden parts cut nothing.
|
||||
fn clipped(path: PathData, rule: FillRule, clip: &Clip, lines: bool, precision: f64) -> Result<(PathData, FillRule)> {
|
||||
if has_invalid_coordinates(&path) {
|
||||
// Left as it is for the operation to refuse ("paths contain invalid coordinates").
|
||||
return Ok((path, rule));
|
||||
}
|
||||
let (Some(within), Some(bounds)) = (clip.path.control_bounds(), path.control_bounds()) else { return Ok((PathData::default(), rule)) };
|
||||
if within.intersect(bounds).is_zero_area() && !bounds.is_zero_area() {
|
||||
// Wholly outside the region (a line's bounds may be flat, so only an area's are trusted).
|
||||
return Ok((PathData::default(), rule));
|
||||
}
|
||||
let (open, closed): (Vec<SubPath>, Vec<SubPath>) =
|
||||
if lines { path.subpaths.into_iter().partition(|sp| !sp.closed) } else { (vec![], path.subpaths) };
|
||||
let mut subs = vec![];
|
||||
if !closed.is_empty() {
|
||||
let area = po::try_boolean(&PathData::new(closed), rule, &clip.path, clip.rule, BoolOp::Intersect, precision)
|
||||
.map_err(|e| EngineError::Other(e.to_string()))?;
|
||||
subs.extend(area.subpaths);
|
||||
}
|
||||
if !open.is_empty() {
|
||||
let open = PathData::new(open);
|
||||
// Each segment is sampled at least every 1/16 of the region's shorter side (and 24 times),
|
||||
// and the crossings found are refined: a part of the region narrower than that, which a
|
||||
// line crosses between two samples, can be missed.
|
||||
let step = (within.width().min(within.height()) / 16.0).max(precision);
|
||||
let outline = clip.path.to_bezpath();
|
||||
let outside = |q| !vectorcraft_geom::hit::fill_contains(&outline, clip.rule, q);
|
||||
match super::draw2::erase_outline(&open, step, &outside) {
|
||||
Some(pieces) => subs.extend(pieces.into_iter().flat_map(|p| p.subpaths)),
|
||||
None => subs.extend(open.subpaths),
|
||||
}
|
||||
}
|
||||
Ok((PathData::new(subs), FillRule::NonZero))
|
||||
}
|
||||
|
||||
/// How many shapes a Pathfinder operation takes from `n` selected alone: its leaf shapes, however
|
||||
/// deep its groups nest (an expanded stroke is a group inside the group, #1635). Inside a compound
|
||||
/// shape, a blend, an envelope or another live object and a symbol instance count as one shape
|
||||
@@ -591,6 +679,10 @@ fn run_pf(s: &mut Session, p: &Value, op: PathfinderOp) -> Result<Value> {
|
||||
}
|
||||
let shape_mode =
|
||||
matches!(op, PathfinderOp::Unite | PathfinderOp::MinusFront | PathfinderOp::Intersect | PathfinderOp::Exclude | PathfinderOp::MinusBack);
|
||||
// An operand its clipping masks hide altogether is an empty shape for the operations whose
|
||||
// result it changes (Intersect gives nothing, Minus Front loses its back object, Minus Back its
|
||||
// front one, Crop its cropping shape); the others leave it out, which gives the same art.
|
||||
let keeps_hidden = matches!(op, PathfinderOp::Intersect | PathfinderOp::MinusFront | PathfinderOp::MinusBack | PathfinderOp::Crop);
|
||||
let label = pf_label(op);
|
||||
let options = pf_options(s, p, &format!("object.pathfinder.{}", pf_id(op)))?;
|
||||
let ids = s.edit(label, |d, sel| {
|
||||
@@ -598,63 +690,95 @@ fn run_pf(s: &mut Session, p: &Value, op: PathfinderOp) -> Result<Value> {
|
||||
let mut styles: Vec<Style> = vec![];
|
||||
let mut shapes: Vec<po::Shape> = vec![];
|
||||
let mut names: Vec<Option<String>> = vec![];
|
||||
let mut push = |mut path: PathData, rule: FillRule, mut st: Style, name: Option<String>| {
|
||||
if path.is_empty() {
|
||||
return;
|
||||
}
|
||||
// Trim, Merge and Crop remove any strokes (and Merge then merges by fill alone), as the
|
||||
// public Pathfinder documentation describes.
|
||||
if matches!(op, PathfinderOp::Trim | PathfinderOp::Merge | PathfinderOp::Crop) {
|
||||
st.appearance.items.retain(|i| !matches!(i, AppearanceItem::Stroke(_)));
|
||||
}
|
||||
if op == PathfinderOp::Divide && st.appearance.items.iter().any(|i| matches!(i, AppearanceItem::Fill(f) if !f.paint.is_none())) {
|
||||
// Filled open contours keep their implicit closing edge. A zero-area line
|
||||
// stays a cutter; normalised area also catches zero-signed-area self crossings.
|
||||
for sub in path.subpaths.iter_mut().filter(|sp| !sp.closed) {
|
||||
sub.closed = po::encloses_area(sub) || po::area(&PathData::single(sub.clone()), rule) > 0.0;
|
||||
// `hidden`: the masks hide the operand altogether, and its empty path stands for it.
|
||||
let mut push =
|
||||
|mut path: PathData, mut rule: FillRule, mut st: Style, name: Option<String>, clip: Option<&Clip>, hidden: bool| -> Result<()> {
|
||||
if path.is_empty() && !(hidden && keeps_hidden) {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
let key = match styles.iter().position(|x| *x == st) {
|
||||
Some(k) => k,
|
||||
None => {
|
||||
styles.push(st);
|
||||
styles.len() - 1
|
||||
// Trim, Merge and Crop remove any strokes (and Merge then merges by fill alone), as the
|
||||
// public Pathfinder documentation describes.
|
||||
if matches!(op, PathfinderOp::Trim | PathfinderOp::Merge | PathfinderOp::Crop) {
|
||||
st.appearance.items.retain(|i| !matches!(i, AppearanceItem::Stroke(_)));
|
||||
}
|
||||
if op == PathfinderOp::Divide && st.appearance.items.iter().any(|i| matches!(i, AppearanceItem::Fill(f) if !f.paint.is_none())) {
|
||||
// Filled open contours keep their implicit closing edge. A zero-area line
|
||||
// stays a cutter; normalised area also catches zero-signed-area self crossings.
|
||||
for sub in path.subpaths.iter_mut().filter(|sp| !sp.closed) {
|
||||
sub.closed = po::encloses_area(sub) || po::area(&PathData::single(sub.clone()), rule) > 0.0;
|
||||
}
|
||||
}
|
||||
if let Some(clip) = clip {
|
||||
(path, rule) = clipped(path, rule, clip, op == PathfinderOp::Divide, options.precision)?;
|
||||
if path.is_empty() && !keeps_hidden {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
let key = match styles.iter().position(|x| *x == st) {
|
||||
Some(k) => k,
|
||||
None => {
|
||||
styles.push(st);
|
||||
styles.len() - 1
|
||||
}
|
||||
};
|
||||
shapes.push(po::Shape::new(path, rule, key as u64));
|
||||
names.push(name);
|
||||
Ok(())
|
||||
};
|
||||
shapes.push(po::Shape::new(path, rule, key as u64));
|
||||
names.push(name);
|
||||
};
|
||||
// Whether a clip group was among the selection, for the error when its mask hides it all.
|
||||
let mut masked = false;
|
||||
for id in &roots {
|
||||
let n = d.node(*id).ok_or(EngineError::NoNode(*id))?;
|
||||
let mut lv = vec![];
|
||||
pf_leaves(d, n, &mut lv);
|
||||
clipped_pf_leaves(d, n, None, options.precision, &mut lv)?;
|
||||
masked |= lv.iter().any(|(_, clip)| clip.is_some());
|
||||
if lv.is_empty() {
|
||||
continue;
|
||||
}
|
||||
if shape_mode
|
||||
&& roots.len() > 1
|
||||
&& lv.len() > 1
|
||||
&& let Some(top) = lv.last()
|
||||
{
|
||||
// Among other objects, a group acts as one shape (the union of its leaves) with
|
||||
// its top leaf's style. Selected alone, its members are the shapes (#1450).
|
||||
let parts: Vec<(PathData, FillRule)> = lv.iter().filter_map(node_path).collect();
|
||||
let refs: Vec<(&PathData, FillRule)> = parts.iter().map(|(p, r)| (p, *r)).collect();
|
||||
let name = n.name.clone().or_else(|| lv.iter().find_map(|l| l.name.clone()));
|
||||
if shape_mode && roots.len() > 1 && lv.len() > 1 {
|
||||
// Among other objects, a group acts as one shape (the union of its leaves, each
|
||||
// where its clip groups show it) with the style of its top leaf that shows.
|
||||
// Selected alone, its members are the shapes (#1450).
|
||||
let mut parts: Vec<(&Node, PathData, FillRule)> = vec![];
|
||||
for (l, clip) in &lv {
|
||||
let Some((p, r)) = node_path(l) else { continue };
|
||||
let (p, r) = match clip {
|
||||
Some(clip) => clipped(p, r, clip, false, options.precision)?,
|
||||
None => (p, r),
|
||||
};
|
||||
if !p.is_empty() {
|
||||
parts.push((l, p, r));
|
||||
}
|
||||
}
|
||||
let name = n.name.clone().or_else(|| parts.iter().find_map(|(l, ..)| l.name.clone()));
|
||||
let Some((top, ..)) = parts.last() else {
|
||||
// The masks hide the whole group.
|
||||
if let Some((top, _)) = lv.last() {
|
||||
push(PathData::default(), FillRule::NonZero, style_of(top), name, None, true)?;
|
||||
}
|
||||
continue;
|
||||
};
|
||||
let top = *top;
|
||||
let refs: Vec<(&PathData, FillRule)> = parts.iter().map(|(_, p, r)| (p, *r)).collect();
|
||||
push(
|
||||
po::try_unite_all_with(&refs, options.precision).map_err(|e| EngineError::Other(e.to_string()))?,
|
||||
FillRule::NonZero,
|
||||
style_of(top),
|
||||
name,
|
||||
);
|
||||
None,
|
||||
false,
|
||||
)?;
|
||||
} else {
|
||||
for l in &lv {
|
||||
for (l, clip) in &lv {
|
||||
if let Some((p, r)) = node_path(l) {
|
||||
push(p, r, style_of(l), n.name.clone().or_else(|| l.name.clone()));
|
||||
push(p, r, style_of(l), n.name.clone().or_else(|| l.name.clone()), clip.as_deref(), clip.is_some())?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if shapes.is_empty() && masked {
|
||||
return Err(EngineError::Other(format!("{label}: the clipping masks hide the selected art")));
|
||||
}
|
||||
if shapes.is_empty() {
|
||||
return Err(EngineError::Other(format!("{label}: select paths, compound paths, groups or text")));
|
||||
}
|
||||
|
||||
@@ -122,6 +122,7 @@ mod panelcmds;
|
||||
mod paragraphs;
|
||||
mod params;
|
||||
mod path_menu_enabled;
|
||||
mod pathfinder_clip;
|
||||
mod pathops;
|
||||
mod pathtype;
|
||||
mod pattern;
|
||||
|
||||
@@ -0,0 +1,311 @@
|
||||
//! Pathfinder on clip groups (#8093): a clip group's members take part only where its clipping
|
||||
//! path shows them, so Divide and the other operations leave out the hidden art.
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
use vectorcraft_doc::NodeKind;
|
||||
use vectorcraft_geom::{FillRule, PathData, Rect};
|
||||
|
||||
use crate::*;
|
||||
|
||||
fn session() -> Session {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 800, "height": 600})).unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
fn id(v: &Value) -> NodeId {
|
||||
NodeId(v["id"].as_u64().unwrap_or_else(|| panic!("no id in {v}")))
|
||||
}
|
||||
|
||||
fn rect(s: &mut Session, x: f64, y: f64, w: f64, h: f64, fill: Color) -> NodeId {
|
||||
let r = id(&s.execute("shape.rectangle", &json!({"x": x, "y": y, "width": w, "height": h})).unwrap());
|
||||
s.edit("fill", |d, _| {
|
||||
d.node_mut(r).unwrap().appearance.set_fill(Paint::solid(fill));
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
r
|
||||
}
|
||||
|
||||
fn clip(s: &mut Session, ids: &[NodeId]) -> NodeId {
|
||||
id(&s.execute("object.clippingMask.make", &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()})).unwrap())
|
||||
}
|
||||
|
||||
fn red() -> Color {
|
||||
Color::rgb(1.0, 0.0, 0.0)
|
||||
}
|
||||
|
||||
fn blue() -> Color {
|
||||
Color::rgb(0.0, 0.0, 1.0)
|
||||
}
|
||||
|
||||
fn green() -> Color {
|
||||
Color::rgb(0.0, 1.0, 0.0)
|
||||
}
|
||||
|
||||
/// A red square at (0, 0) and a blue one at (50, 50), both 100 pt, clipped by a 100 pt square
|
||||
/// mask at (25, 25): the clip group. The mask shows 8750 pt² of them.
|
||||
fn clipped_pair(s: &mut Session) -> NodeId {
|
||||
let a = rect(s, 0.0, 0.0, 100.0, 100.0, red());
|
||||
let b = rect(s, 50.0, 50.0, 100.0, 100.0, blue());
|
||||
let mask = rect(s, 25.0, 25.0, 100.0, 100.0, green());
|
||||
clip(s, &[a, b, mask])
|
||||
}
|
||||
|
||||
/// The shapes `op` makes of the selection, the members of the group it makes or the one shape:
|
||||
/// (fill, path, rule) each.
|
||||
fn pieces(s: &mut Session, op: &str) -> Vec<(Paint, PathData, FillRule)> {
|
||||
let r = s.execute(op, &json!({})).unwrap();
|
||||
let g = s.doc().unwrap().doc.node(NodeId(r["ids"][0].as_u64().unwrap())).cloned().unwrap();
|
||||
let shape = |n: &vectorcraft_doc::Node| match &n.kind {
|
||||
NodeKind::Path { path, rule, .. } => (n.appearance.fill_paint(), path.clone(), *rule),
|
||||
NodeKind::Compound { children, rule } => {
|
||||
let subs = children.iter().flat_map(|c| c.path_data().unwrap().subpaths.clone()).collect();
|
||||
(n.appearance.fill_paint(), PathData::new(subs), *rule)
|
||||
}
|
||||
k => panic!("not a path: {k:?}"),
|
||||
};
|
||||
match &g.kind {
|
||||
NodeKind::Group { children, .. } => children.iter().map(|c| shape(c)).collect(),
|
||||
_ => vec![shape(&g)],
|
||||
}
|
||||
}
|
||||
|
||||
fn area(p: &(Paint, PathData, FillRule)) -> f64 {
|
||||
vectorcraft_pathops::area(&p.1, p.2)
|
||||
}
|
||||
|
||||
fn bounds(ps: &[(Paint, PathData, FillRule)]) -> Rect {
|
||||
ps.iter().filter_map(|p| p.1.bounds()).reduce(|a, b| a.union(b)).unwrap()
|
||||
}
|
||||
|
||||
fn select(s: &mut Session, ids: &[NodeId]) {
|
||||
s.execute("select.set", &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()})).unwrap();
|
||||
}
|
||||
|
||||
fn assert_inside(r: Rect, within: Rect) {
|
||||
assert!(within.inflate(1e-6, 1e-6).contains_rect(r), "{r:?} reaches out of {within:?}");
|
||||
}
|
||||
|
||||
/// The issue's case: Divide on a clip group gives the pieces the mask shows, cut along it, and the
|
||||
/// hidden art goes.
|
||||
#[test]
|
||||
fn divide_on_a_clip_group_keeps_only_what_the_mask_shows() {
|
||||
let mut s = session();
|
||||
let g = clipped_pair(&mut s);
|
||||
select(&mut s, &[g]);
|
||||
let ps = pieces(&mut s, "object.pathfinder.divide");
|
||||
assert_eq!(ps.len(), 3, "red alone, the overlap and blue alone: {ps:?}");
|
||||
let total: f64 = ps.iter().map(area).sum();
|
||||
assert!((total - 8750.0).abs() < 1.0, "the visible area, not the whole art: {total}");
|
||||
assert_inside(bounds(&ps), Rect::new(25.0, 25.0, 125.0, 125.0));
|
||||
let blue: f64 = ps.iter().filter(|p| p.0 == Paint::solid(blue())).map(area).sum();
|
||||
assert!((blue - 5625.0).abs() < 1.0, "the overlap takes the front (blue) fill: {blue}");
|
||||
assert!(ps.iter().all(|p| p.0 != Paint::solid(green())), "the clipping path adds no piece: {ps:?}");
|
||||
}
|
||||
|
||||
/// An irregular mask: a square clipped by a circle divides into a disc.
|
||||
#[test]
|
||||
fn divide_cuts_along_a_curved_clipping_path() {
|
||||
let mut s = session();
|
||||
let square = rect(&mut s, 100.0, 100.0, 300.0, 300.0, red());
|
||||
let circle = id(&s.execute("shape.ellipse", &json!({"x": 150, "y": 150, "width": 200, "height": 200})).unwrap());
|
||||
let g = clip(&mut s, &[square, circle]);
|
||||
select(&mut s, &[g]);
|
||||
let ps = pieces(&mut s, "object.pathfinder.divide");
|
||||
assert_eq!(ps.len(), 1, "{ps:?}");
|
||||
let disc = std::f64::consts::PI * 100.0 * 100.0;
|
||||
assert!((area(&ps[0]) - disc).abs() < disc * 1e-3, "{} vs {disc}", area(&ps[0]));
|
||||
assert_inside(bounds(&ps), Rect::new(150.0, 150.0, 350.0, 350.0));
|
||||
}
|
||||
|
||||
/// A clip group inside a clip group: its members show only where both masks do.
|
||||
#[test]
|
||||
fn nested_clip_groups_cut_by_both_masks() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 0.0, 0.0, 200.0, 200.0, red());
|
||||
let inner_mask = rect(&mut s, 0.0, 0.0, 100.0, 200.0, green());
|
||||
let inner = clip(&mut s, &[a, inner_mask]);
|
||||
let outer_mask = rect(&mut s, 0.0, 50.0, 200.0, 100.0, green());
|
||||
let outer = clip(&mut s, &[inner, outer_mask]);
|
||||
select(&mut s, &[outer]);
|
||||
let ps = pieces(&mut s, "object.pathfinder.divide");
|
||||
assert_eq!(ps.len(), 1, "{ps:?}");
|
||||
assert!((area(&ps[0]) - 10000.0).abs() < 1.0, "100 × 100 shows: {}", area(&ps[0]));
|
||||
assert_inside(bounds(&ps), Rect::new(0.0, 50.0, 100.0, 150.0));
|
||||
}
|
||||
|
||||
/// A member the mask hides altogether gives no piece.
|
||||
#[test]
|
||||
fn a_member_the_mask_hides_gives_no_piece() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 0.0, 0.0, 100.0, 100.0, red());
|
||||
let b = rect(&mut s, 300.0, 300.0, 100.0, 100.0, blue());
|
||||
let mask = rect(&mut s, 0.0, 0.0, 150.0, 150.0, green());
|
||||
let g = clip(&mut s, &[a, b, mask]);
|
||||
select(&mut s, &[g]);
|
||||
let ps = pieces(&mut s, "object.pathfinder.divide");
|
||||
assert_eq!(ps.len(), 1, "only the red square shows: {ps:?}");
|
||||
assert_eq!(ps[0].0, Paint::solid(red()));
|
||||
}
|
||||
|
||||
/// A cutting line in a clip group cuts only where the mask shows it: its hidden part leaves the
|
||||
/// other selected art alone.
|
||||
#[test]
|
||||
fn a_clipped_cutting_line_cuts_only_where_it_shows() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 0.0, 0.0, 100.0, 100.0, red());
|
||||
let line = id(&s.execute("shape.line", &json!({"x1": 50, "y1": -50, "x2": 50, "y2": 400})).unwrap());
|
||||
let mask = rect(&mut s, 0.0, 0.0, 100.0, 100.0, green());
|
||||
let g = clip(&mut s, &[a, line, mask]);
|
||||
let other = rect(&mut s, 0.0, 200.0, 100.0, 100.0, blue());
|
||||
select(&mut s, &[g, other]);
|
||||
let ps = pieces(&mut s, "object.pathfinder.divide");
|
||||
let red = ps.iter().filter(|p| p.0 == Paint::solid(red())).count();
|
||||
let blue = ps.iter().filter(|p| p.0 == Paint::solid(blue())).count();
|
||||
assert_eq!((red, blue), (2, 1), "the line halves the red square, not the blue one: {ps:?}");
|
||||
}
|
||||
|
||||
/// Every Shape Mode and Pathfinder button takes the members as the mask shows them (#3367 asks
|
||||
/// this of Merge). The mask, 100 × 60 pt at (25, 25), cuts through the squares' overlap: it shows
|
||||
/// 4500 pt² of red, 2625 pt² of blue and 1750 pt² of their overlap.
|
||||
#[test]
|
||||
fn every_operation_takes_only_what_the_mask_shows() {
|
||||
for (op, want) in [
|
||||
("unite", Some(5375.0)),
|
||||
("minusFront", Some(2750.0)),
|
||||
("minusBack", Some(875.0)),
|
||||
("intersect", Some(1750.0)),
|
||||
("exclude", Some(3625.0)),
|
||||
("trim", Some(5375.0)),
|
||||
("merge", Some(5375.0)),
|
||||
("crop", Some(1750.0)),
|
||||
("outline", None),
|
||||
] {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 0.0, 0.0, 100.0, 100.0, red());
|
||||
let b = rect(&mut s, 50.0, 50.0, 100.0, 100.0, blue());
|
||||
let mask = rect(&mut s, 25.0, 25.0, 100.0, 60.0, green());
|
||||
let g = clip(&mut s, &[a, b, mask]);
|
||||
select(&mut s, &[g]);
|
||||
let ps = pieces(&mut s, &format!("object.pathfinder.{op}"));
|
||||
assert_inside(bounds(&ps), Rect::new(25.0, 25.0, 125.0, 85.0));
|
||||
if let Some(want) = want {
|
||||
let total: f64 = ps.iter().map(area).sum();
|
||||
assert!((total - want).abs() < 1.0, "{op}: {total}, want {want}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Among other objects a clip group acts as one shape: the union of what its mask shows.
|
||||
#[test]
|
||||
fn a_clip_group_among_other_objects_is_the_area_its_mask_shows() {
|
||||
let mut s = session();
|
||||
let g = clipped_pair(&mut s);
|
||||
let other = rect(&mut s, 300.0, 0.0, 50.0, 50.0, blue());
|
||||
select(&mut s, &[g, other]);
|
||||
let ps = pieces(&mut s, "object.pathfinder.unite");
|
||||
let total: f64 = ps.iter().map(area).sum();
|
||||
assert!((total - (8750.0 + 2500.0)).abs() < 1.0, "{total}");
|
||||
}
|
||||
|
||||
/// Among other objects a clip group takes the style of its top member that shows: a member the
|
||||
/// mask hides paints nothing.
|
||||
#[test]
|
||||
fn a_hidden_top_member_gives_no_style() {
|
||||
let mut s = session();
|
||||
// Below the clip group, so the result takes the group's style.
|
||||
let other = rect(&mut s, 50.0, 50.0, 100.0, 100.0, green());
|
||||
let a = rect(&mut s, 0.0, 0.0, 100.0, 100.0, red());
|
||||
let b = rect(&mut s, 300.0, 300.0, 100.0, 100.0, blue());
|
||||
let mask = rect(&mut s, 0.0, 0.0, 150.0, 150.0, green());
|
||||
let g = clip(&mut s, &[a, b, mask]);
|
||||
select(&mut s, &[other, g]);
|
||||
let ps = pieces(&mut s, "object.pathfinder.unite");
|
||||
assert_eq!(ps.len(), 1, "{ps:?}");
|
||||
assert_eq!(ps[0].0, Paint::solid(red()), "not the hidden blue member's fill");
|
||||
assert!((area(&ps[0]) - 17500.0).abs() < 1.0, "{}", area(&ps[0]));
|
||||
}
|
||||
|
||||
/// A selection the masks hide altogether says so.
|
||||
#[test]
|
||||
fn art_the_masks_hide_altogether_is_refused_with_a_reason() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 300.0, 300.0, 100.0, 100.0, red());
|
||||
let mask = rect(&mut s, 0.0, 0.0, 100.0, 100.0, green());
|
||||
let g = clip(&mut s, &[a, mask]);
|
||||
select(&mut s, &[g]);
|
||||
let undo = s.doc().unwrap().history.undo.len();
|
||||
let e = s.execute("object.pathfinder.divide", &json!({})).unwrap_err().to_string();
|
||||
assert!(e.contains("clipping masks hide"), "{e}");
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), undo, "nothing changes");
|
||||
}
|
||||
|
||||
/// A clip group its mask hides altogether, selected with a red square at (0, 0) and a blue one at
|
||||
/// (50, 50), each 100 pt, at `position` in the stacking order (0: at the back).
|
||||
fn with_a_hidden_clip_group(s: &mut Session, position: usize) {
|
||||
let mut ids = vec![];
|
||||
for i in 0..3 {
|
||||
if i == position {
|
||||
// Two members, so among other objects the group is one shape: their union.
|
||||
let a = rect(s, 300.0, 300.0, 100.0, 100.0, green());
|
||||
let b = rect(s, 450.0, 300.0, 100.0, 100.0, green());
|
||||
let mask = rect(s, 0.0, 0.0, 100.0, 100.0, green());
|
||||
ids.push(clip(s, &[a, b, mask]));
|
||||
} else {
|
||||
let at = if ids.len() == usize::from(position == 0) { 0.0 } else { 50.0 };
|
||||
ids.push(rect(s, at, at, 100.0, 100.0, if at == 0.0 { red() } else { blue() }));
|
||||
}
|
||||
}
|
||||
select(s, &ids);
|
||||
}
|
||||
|
||||
/// A selected object its masks hide altogether is an empty operand: Intersect, Minus Front with
|
||||
/// it at the back, Minus Back with it in front and Crop with it on top give nothing, and the other
|
||||
/// operations make what they make without it.
|
||||
#[test]
|
||||
fn a_hidden_operand_is_an_empty_shape_where_it_changes_the_result() {
|
||||
for (op, position) in [("intersect", 1), ("minusFront", 0), ("minusBack", 2), ("crop", 2)] {
|
||||
let mut s = session();
|
||||
with_a_hidden_clip_group(&mut s, position);
|
||||
let undo = s.doc().unwrap().history.undo.len();
|
||||
let e = s.execute(&format!("object.pathfinder.{op}"), &json!({})).unwrap_err().to_string();
|
||||
assert!(e.contains("empty result"), "{op}: {e}");
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), undo, "{op}: nothing changes");
|
||||
}
|
||||
for (op, position, want) in [("unite", 2, 17500.0), ("exclude", 2, 15000.0), ("minusFront", 2, 7500.0), ("minusBack", 0, 7500.0)] {
|
||||
let mut s = session();
|
||||
with_a_hidden_clip_group(&mut s, position);
|
||||
let ps = pieces(&mut s, &format!("object.pathfinder.{op}"));
|
||||
let total: f64 = ps.iter().map(area).sum();
|
||||
assert!((total - want).abs() < 1.0, "{op}: {total}, want {want}");
|
||||
assert!(ps.iter().all(|p| p.0 != Paint::solid(green())), "{op}: the hidden group's style: {ps:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A clip group whose clipping path clips by nothing (here an empty group) hides its members, as on
|
||||
/// the canvas: they are a hidden operand too, not left out of the selection.
|
||||
#[test]
|
||||
fn a_clipping_path_that_clips_by_nothing_hides_the_members() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 0.0, 0.0, 100.0, 100.0, red());
|
||||
let b = rect(&mut s, 50.0, 50.0, 100.0, 100.0, blue());
|
||||
let m1 = rect(&mut s, 300.0, 300.0, 100.0, 100.0, green());
|
||||
let m2 = rect(&mut s, 450.0, 300.0, 100.0, 100.0, green());
|
||||
let mask = rect(&mut s, 300.0, 300.0, 300.0, 100.0, green());
|
||||
let g = clip(&mut s, &[m1, m2, mask]);
|
||||
s.edit("empty clipping path", |d, _| {
|
||||
let empty = vectorcraft_doc::Node::group(d.alloc_id(), vec![]);
|
||||
let NodeKind::Group { children, .. } = &mut d.node_mut(g).unwrap().kind else { panic!("not a group") };
|
||||
children[0] = std::sync::Arc::new(empty);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
select(&mut s, &[a, b, g]);
|
||||
let e = s.execute("object.pathfinder.intersect", &json!({})).unwrap_err().to_string();
|
||||
assert!(e.contains("empty result"), "not the squares' overlap: {e}");
|
||||
select(&mut s, &[g]);
|
||||
let e = s.execute("object.pathfinder.divide", &json!({})).unwrap_err().to_string();
|
||||
assert!(e.contains("clipping masks hide"), "{e}");
|
||||
}
|
||||
@@ -1417,6 +1417,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- Live effects with previewing dialogs: Distort & Transform, Path, Convert to Shape, 15 Warp styles, Round Corners, Scribble, Effect → Pathfinder (all 10 operations, live on groups; several loose objects are grouped first, in one undo step), Color Adjustments (Brightness/Contrast, Curves, Levels, Hue/Saturation, Shift to Color, Temperature/Tint, on vectors, live type and embedded images), and raster drop shadow, glows and feather. SVG and PDF export keep live effects (geometry baked; SVG raster effects as filters). Zig Zag spaces its ridges evenly along each segment, so lines and curves get a regular wave in Corner and Smooth (#1558). Warp › Arc (the effect and Envelope › Make with Warp) bends in the object's real proportions: a circular arc with concentric edges and no fold-over at 100%, so Arc on art that isn't square draws differently from before (#1581, fixes #1578). `effect.apply` and `effect.setParams` give an error for a misspelt or wrongly typed effect parameter instead of running the effect with its default (#1623, #1592). Roughen with Smooth keeps turn-backs smooth instead of making cusps that draw as spikes (#1646, #1643). Scribble draws one zig-zag per region, with no lines across holes and notches; convex shapes are unchanged (#1651, #1648). On the canvas, in Expand Appearance and in exports, Effect → Pathfinder uses the glyph outlines of type in the group, and results painted like the type keep its opacity and blend mode.
|
||||
- Cmd/Ctrl+4 (`pathfinder.repeat`) repeats the last successful Pathfinder panel operation, direct `object.pathfinder.*` command or `command.batch` step (including Actions playback) on the current selection; the panel menu names it. `action.batch`, Trap, compound-shape edits and live effects do not set history. Public references: [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html), [Pathfinder panel overview](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/pathfinder-panel-overview.html).
|
||||
- Pathfinder Options ([Pathfinder panel overview](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/pathfinder-panel-overview.html)): the panel menu's Pathfinder Options… sets Precision (0.001–10 pt: results refit to within it, thinner pieces dropped), Remove Redundant Points and Divide and Outline Will Remove Unpainted Artwork (`object.pathfinder.options`, kept in the preferences) for every Shape Mode and Pathfinder operation; the defaults keep the earlier output (`pathops` `precision_drops_pieces_thinner_than_it`, engine `tests_pathops` Pathfinder Options tests, `panels::pathfinder` dialog test).
|
||||
- Pathfinder on clip groups (#8093): a clip group's members take part in the Shape Modes and Pathfinder buttons (`object.pathfinder.*`) only where its clipping path shows them, so Divide cuts the visible art along the mask and the hidden art goes; nested clip groups cut by each mask, a member the mask hides gives no piece, a cutting line's hidden part cuts nothing, a selected object the masks hide altogether counts as an empty shape where that changes the result (Intersect, Minus Front, Minus Back, Crop), and the clipping path adds no piece of its own (the public documentation doesn't say what Pathfinder does with masked art; our choice, asked on the issue). A cutting line is clipped by sampling, so a part of the mask much narrower than the mask itself can be missed. Make Compound Shape, Trap and the Pathfinder effects still take the members whole. Tests: `crates/engine/src/tests/pathfinder_clip.rs`.
|
||||
- Pathfinder › Trap ([trapping](https://helpx.adobe.com/illustrator/using/trapping.html), [Pathfinder panel](https://helpx.adobe.com/illustrator/using/pathfinder-panel-overview.html)): the Pathfinder panel menu's Trap… (`object.pathfinder.trap`) and Effect › Pathfinder › Trap… (`pathfinder.trap`, live on groups) add, where two objects' visible areas of different solid colours meet, a strip of the darker one's area along the edge, filled with the lighter colour at the Tint Reduction percentage and set to overprint (Reverse Traps: the darker colour spreads instead, but not a rich black); Thickness 0.01–5000 pt across vertical edges, Height/Width scales it across horizontal ones, Traps with Process Color paints a swatch colour's trap with its CMYK equivalent; the effect also has Precision and Remove Redundant Points. The panel's Trap is one undo step and groups the traps above the topmost selected object, selected; with no adjoining edges of different colours it says so and changes nothing. Tests: `crates/pathops/src/trap.rs`, `crates/effects/src/trap.rs`, `group::tests::trap_effect_adds_an_overprinting_strip_above_the_members`, `crates/engine/src/tests/trap.rs`, `panels::pathfinder::tests::trap_opens_its_options_and_ok_traps_the_selection`.
|
||||
- Compound shapes ([Create compound shapes with Pathfinder](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/create-compound-shapes-with-pathfinder.html), [Pathfinder panel overview](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/pathfinder-panel-overview.html)): the Pathfinder panel menu's Make Compound Shape (every member in Add) and Alt-clicking a Shape Mode (every member in that mode) make the two or more selected paths, compound paths, groups, compound shapes or type a live compound shape (`object.compoundShape.make`): a group whose members each keep a shape mode and stay editable, drawn, printed and exported (SVG, PDF and the rest through the baked document) as the area the modes make from the backmost member up, open paths closed, painted with its own appearance, taken from the topmost member not subtracting. With members selected (Direct Selection, Layers panel, isolation mode) a Shape Mode button sets theirs (`object.compoundShape.setMode`) and is lit for the mode they share; paint given to a member goes to the compound shape. Release Compound Shape gives the members back as they were (`object.compoundShape.release`); Expand Compound Shape and the panel's Expand button turn it into the path or compound path of its area (`object.compoundShape.expand`). Shape Modes and Pathfinders take a compound shape as its area. Saved files keep it (`compound_shape`, `shape_mode`; an unknown mode reads as Add). Blends, envelopes and objects with a warp or another geometry effect are members as they draw (a blend's steps, an envelope's distorted art, the warped outline), and the area follows an edit of the blend, envelope or warp; Release gives them back as they were. Tests: `crates/engine/src/tests/compound_shape.rs`, `group::tests::compound_shapes_draw_the_area_their_shape_modes_make`, `group::tests::nested_compound_shapes_take_part_as_their_area`, `panels::pathfinder::tests::compound_shape_items_follow_the_selection`, the `CompoundShape` op of the property-test strategies. Not yet: the question marks on mixed member modes, hit-testing by the area (a click hits the members).
|
||||
- Effect › Path › Outline Object has no options. Type that carries it is drawn, exported (PDF and SVG as paths, with no font) and expanded as its glyph outlines while it stays editable, and the effects after it reshape those outlines. Paths and images draw as before. With Use Preview Bounds on, type is measured by its glyph outlines. Public reference: [Summary of effects](https://web.archive.org/web/20210901011839/https://helpx.adobe.com/illustrator/using/summary-effects.html) (archived copy).
|
||||
|
||||
Reference in New Issue
Block a user