mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 11:05:03 +00:00
Pathfinder: Divide keeps the pieces a group's own fill paints under Remove Unpainted Artwork
A live Divide effect with removeUnpainted on left out every piece of a member with no visible fill, even where the group's own fill paints the members. A compound shape's area has no paint of its own, so a filled compound shape drew nothing. A group's or compound shape's own visible fill now counts as painting its pieces for Divide. Outline's open segments still go by their source's fill.
This commit is contained in:
@@ -66,7 +66,7 @@ pub const PATHFINDER_EFFECT_PRECISION: std::ops::RangeInclusive<f64> = 0.001..=1
|
||||
/// The documentation of [`PATHFINDER_OPTION_KEYS`], as a literal for `concat!`.
|
||||
macro_rules! options_doc {
|
||||
() => {
|
||||
"precision?: pt 0.001..10 (effect.apply: Pathfinder Options › Precision; 0.01 when missing; results are refit to within it and pieces thinner than it are dropped), removeRedundantPoints?: bool (effect.apply: Pathfinder Options › Remove Redundant Points; false when missing; results lose the anchors that don't change their shape to within precision), removeUnpainted?: bool (effect.apply: Pathfinder Options › Divide and Outline Will Remove Unpainted Artwork; false when missing; Divide and Outline leave out the pieces of members with no visible fill, the other operations ignore it)"
|
||||
"precision?: pt 0.001..10 (effect.apply: Pathfinder Options › Precision; 0.01 when missing; results are refit to within it and pieces thinner than it are dropped), removeRedundantPoints?: bool (effect.apply: Pathfinder Options › Remove Redundant Points; false when missing; results lose the anchors that don't change their shape to within precision), removeUnpainted?: bool (effect.apply: Pathfinder Options › Divide and Outline Will Remove Unpainted Artwork; false when missing; Divide and Outline leave out the pieces of members with no visible fill, except that Divide keeps every piece when the group or compound shape has a visible fill of its own; the other operations ignore it)"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -555,6 +555,10 @@ pub fn pathfinder_children(doc: Option<&Document>, group: &Node, hook: Option<Ou
|
||||
out.extend(source.iter().skip(art).cloned());
|
||||
return Some(out);
|
||||
}
|
||||
// The group's own fill paints its members' geometry, a compound shape's area included
|
||||
// ([`evaluate_container`]), so with one Remove Unpainted Artwork leaves out no Divide piece.
|
||||
// Outline's pieces are open segments, which still go by their own fill.
|
||||
let own_fill = has_visible_fill(group);
|
||||
let mut stack: Vec<Arc<Node>> = if group.is_compound_shape() {
|
||||
// The group's own appearance paints the area ([`evaluate_container`]), so the art has none.
|
||||
match compound_shape_area(doc, group, hook) {
|
||||
@@ -644,7 +648,12 @@ pub fn pathfinder_children(doc: Option<&Document>, group: &Node, hook: Option<Ou
|
||||
} else {
|
||||
// Divide and Outline Will Remove Unpainted Artwork: the pieces of members with no
|
||||
// visible fill go.
|
||||
let unpainted = options.remove_unpainted && matches!(op, PathfinderOp::Divide | PathfinderOp::Outline);
|
||||
let unpainted = options.remove_unpainted
|
||||
&& match op {
|
||||
PathfinderOp::Divide => !own_fill,
|
||||
PathfinderOp::Outline => true,
|
||||
_ => false,
|
||||
};
|
||||
po::pathfinder_with(op, &shapes, options.precision)
|
||||
.into_iter()
|
||||
.filter(|r| !r.path.is_empty() && !(unpainted && !has_visible_fill(&sources[r.key as usize])))
|
||||
|
||||
@@ -120,6 +120,50 @@ fn divide_and_outline_draw_nothing_for_unpainted_members() {
|
||||
}
|
||||
}
|
||||
|
||||
/// With Remove Unpainted Artwork, Divide keeps the area of a compound shape whose own appearance
|
||||
/// has a visible fill and leaves out the area of one without. Outline's open segments of the area
|
||||
/// go either way.
|
||||
#[test]
|
||||
fn remove_unpainted_keeps_a_filled_compound_shapes_area() {
|
||||
for effect in ["pathfinder.divide", "pathfinder.outline"] {
|
||||
for filled in [true, false] {
|
||||
let mut g = compound_shape(ShapeMode::Add);
|
||||
if !filled {
|
||||
g.appearance = Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0).into();
|
||||
}
|
||||
g.appearance.effects.push(Effect { id: effect.into(), params: serde_json::json!({"removeUnpainted": true}), visible: true });
|
||||
let out = pathfinder_children(None, &g, None).unwrap();
|
||||
let kept = filled && effect == "pathfinder.divide";
|
||||
assert_eq!(!out.is_empty(), kept, "{effect}, filled {filled}: {out:#?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// With Remove Unpainted Artwork, Divide keeps the pieces of an unfilled member when its group's
|
||||
/// own visible fill paints them and leaves them out when the group has no fill. Outline leaves out
|
||||
/// the member's segments either way.
|
||||
#[test]
|
||||
fn remove_unpainted_keeps_members_a_groups_own_fill_paints() {
|
||||
let unfilled = Arc::new(Node::path(
|
||||
NodeId(2),
|
||||
shapes::rectangle(Rect::new(5.0, 0.0, 15.0, 10.0)),
|
||||
Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0),
|
||||
));
|
||||
for effect in ["pathfinder.divide", "pathfinder.outline"] {
|
||||
for filled in [true, false] {
|
||||
let mut g = Node::group(NodeId(10), vec![sq(1, 0.0, Color::rgb(1.0, 0.0, 0.0)), unfilled.clone()]);
|
||||
if filled {
|
||||
g.appearance = Appearance::basic(Paint::solid(Color::rgb(0.0, 1.0, 0.0)), Paint::None, 0.0).into();
|
||||
}
|
||||
g.appearance.effects.push(Effect { id: effect.into(), params: serde_json::json!({"removeUnpainted": true}), visible: true });
|
||||
let out = pathfinder_children(None, &g, None).unwrap();
|
||||
assert!(out.iter().any(|n| n.id == NodeId(1)), "{effect}, filled {filled}: {out:#?}");
|
||||
let kept = filled && effect == "pathfinder.divide";
|
||||
assert_eq!(out.iter().any(|n| n.id == NodeId(2)), kept, "{effect}, filled {filled}: {out:#?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an "H" in blue type at 100 pt on a baseline at y = 80, with its stems on either
|
||||
/// side of x = 100.
|
||||
fn type_h() -> Node {
|
||||
|
||||
+3
-2
@@ -4891,8 +4891,9 @@ whatever the options are then.
|
||||
|
||||
Each Effect › Pathfinder effect (`pathfinder.add` … `pathfinder.softMix`, not Trap) keeps Pathfinder Options of its own
|
||||
in its params: `precision` (a number, 0.001–10 pt), `removeRedundantPoints` and `removeUnpainted` (true or false), which
|
||||
mean what they mean for the panel's operations; the other operations ignore `removeUnpainted`. `effect.apply` fills
|
||||
the ones `params` leave out from the current Pathfinder Options, and the values join its journal entry. An effect saved
|
||||
mean what they mean for the panel's operations; the other operations ignore `removeUnpainted`, and Divide keeps every
|
||||
piece when the group or compound shape has a visible fill of its own. `effect.apply` fills the ones `params` leave out
|
||||
from the current Pathfinder Options, and the values join its journal entry. An effect saved
|
||||
without them evaluates with precision 0.01 and both switches off, as before effects kept them. `effect.setParams
|
||||
{index, params: {precision?, removeRedundantPoints?, removeUnpainted?}}` edits them as one undo step; values the
|
||||
effect already evaluates with record no undo step and return `{ids: []}`. A precision out of range, or a switch that
|
||||
|
||||
Reference in New Issue
Block a user