diff --git a/crates/engine/src/cmd/pathops.rs b/crates/engine/src/cmd/pathops.rs index b30a6a6c37..61406fdc61 100644 --- a/crates/engine/src/cmd/pathops.rs +++ b/crates/engine/src/cmd/pathops.rs @@ -190,7 +190,7 @@ pub fn specs() -> Vec { "Clean Up…", ["Object", "Path"], None, - "{strayPoints?: true, unpaintedObjects?: true, emptyTextPaths?: true, hairlineSlivers?: false (closed paths and compound paths outside template layers with a visible fill, no visible stroke and no effect, whose fill no circle `sliverWidth` across fits inside; a compound path counts as one object, and guides, the clipping paths of groups and layers and the members of live and generated art stay), sliverWidth?: pt 0.001..3 (0.03 mm, VectorCraft's own default)} remove them from the visible, unlocked objects (not those on a locked artboard), as one undo step, except the clipping paths of groups and layers and what a group or compound path used as one holds → {removed, warning?: how many shapes hairlineSlivers could not measure (too complex, or past the run's limit of work) and left as they are}", + "{strayPoints?: true, unpaintedObjects?: true, emptyTextPaths?: true, hairlineSlivers?: false (closed paths and compound paths outside template layers with a visible fill, no visible stroke and no effect, whose fill no circle `sliverWidth` across fits inside; a compound path counts as one object, and guides, the clipping paths of groups and layers, objects at 0% opacity and their members, and the members of live and generated art stay), sliverWidth?: pt 0.001..3 (0.03 mm, VectorCraft's own default)} remove them from the visible, unlocked objects (not those on a locked artboard), as one undo step, except the clipping paths of groups and layers and what a group or compound path used as one holds → {removed, warning?: how many shapes hairlineSlivers could not measure (too complex, or past the run's limit of work) and left as they are}", has_doc, clean_up ), @@ -1804,8 +1804,9 @@ pub(crate) fn unmeasured_warning(count: usize) -> Option { /// The hairline slivers ([`is_hairline_sliver`]) among the visible, unlocked objects of `d` (not /// those on a locked artboard or in a template layer) for which `within` holds, in the layers and /// groups of the whole document. A compound path counts as one object. The clipping paths of groups -/// and layers (and all of a clipping group used as one), the members of live and generated art, and -/// the members of groups and layers whose own stroke or effect paints them are left out. +/// and layers (and all of a clipping group used as one), the members of live and generated art, +/// objects at 0 % opacity and everything in a group or layer at 0 %, and the members of groups and +/// layers whose own stroke or effect paints them are left out. pub(crate) fn hairline_slivers(d: &Document, width: f64, within: &dyn Fn(NodeId) -> bool) -> Slivers { struct Walk<'a> { width: f64, @@ -1817,7 +1818,8 @@ pub(crate) fn hairline_slivers(d: &Document, width: f64, within: &dyn Fn(NodeId) out: Vec<(NodeId, Option)>, } fn visit(n: &Node, clip_path: bool, w: &mut Walk<'_>) { - if !n.visible || n.locked || n.is_template() || clip_path { + // An object at 0 % opacity, or anything in a group or layer at 0 %, paints nothing. + if !n.visible || n.locked || n.is_template() || clip_path || n.opacity <= 0.0 { return; } match &n.kind { diff --git a/crates/engine/src/cmd/select.rs b/crates/engine/src/cmd/select.rs index f10bb5b342..931504dedb 100644 --- a/crates/engine/src/cmd/select.rs +++ b/crates/engine/src/cmd/select.rs @@ -211,7 +211,7 @@ pub fn specs() -> Vec { "Hairline Slivers…", ["Select", "Object"], None, - "{width?: pt 0.001..3 (0.03 mm, VectorCraft's own default)} select, in the document or inside the isolated group, the closed paths and compound paths that object.path.cleanUp's hairlineSlivers removes with this sliverWidth: a visible fill, no visible stroke, no effect, and no circle `width` across fits inside the fill; a compound path counts as one object, and hidden and locked objects, template layers, clipping paths, guides and the members of live and generated art are left out → {count, warning?: how many shapes could not be measured (too complex, or past the run's limit of work) and were left out}", + "{width?: pt 0.001..3 (0.03 mm, VectorCraft's own default)} select, in the document or inside the isolated group, the closed paths and compound paths that object.path.cleanUp's hairlineSlivers removes with this sliverWidth: a visible fill, no visible stroke, no effect, and no circle `width` across fits inside the fill; a compound path counts as one object, and hidden and locked objects, objects at 0% opacity and their members, template layers, clipping paths, guides and the members of live and generated art are left out → {count, warning?: how many shapes could not be measured (too complex, or past the run's limit of work) and were left out}", has_doc, select_hairline_slivers ), diff --git a/crates/engine/src/tests/pathops.rs b/crates/engine/src/tests/pathops.rs index 6b4c9f534a..f4e251638f 100644 --- a/crates/engine/src/tests/pathops.rs +++ b/crates/engine/src/tests/pathops.rs @@ -1316,6 +1316,31 @@ fn hairline_slivers_leave_art_on_a_locked_artboard_alone() { assert!(s.doc().unwrap().doc.node(sliver).is_some()); } +/// A sliver at 0 % opacity, and one in a group at 0 % opacity, paint nothing and are left alone. +#[test] +fn hairline_slivers_leave_art_at_zero_opacity_alone() { + let mut s = session(); + let clear = filled(&mut s, "M10 10 L50 40 L10.001 10.0015 Z"); + let member = filled(&mut s, "M100 10 L140 40 L100.001 10.0015 Z"); + s.execute("select.set", &json!({"ids": [member.0]})).unwrap(); + let group = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap()); + let seen = filled(&mut s, "M200 10 L240 40 L200.001 10.0015 Z"); + s.edit("t", |d, _| { + d.node_mut(clear).unwrap().opacity = 0.0; + d.node_mut(group).unwrap().opacity = 0.0; + d.node_mut(seen).unwrap().opacity = 0.5; + Ok(()) + }) + .unwrap(); + s.execute("select.none", &json!({})).unwrap(); + let only = json!({"strayPoints": false, "unpaintedObjects": false, "emptyTextPaths": false, "hairlineSlivers": true}); + assert_eq!(s.execute("select.object.hairlineSlivers", &json!({})).unwrap()["count"], 1); + assert_eq!(s.execute("object.path.cleanUp", &only).unwrap()["removed"], 1); + let d = &s.doc().unwrap().doc; + assert!(d.node(clear).is_some() && d.node(member).is_some(), "a sliver at 0 % opacity went"); + assert!(d.node(seen).is_none(), "a sliver at 50 % opacity stayed"); +} + /// A shape too complex to measure is kept, and both commands say how many there were. #[test] fn hairline_slivers_keep_shapes_too_complex_to_measure_and_count_them() { diff --git a/docs/mcp.md b/docs/mcp.md index 876f5a3901..b633ff7224 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -8220,8 +8220,9 @@ VectorCraft's own value, and `hairlineSlivers` is off by default. In the desktop Slivers checkbox and a Sliver Width field, shown in the stroke unit, or in points when that unit's field would round 0.001 pt to 0. `select.object.hairlineSlivers {width?}` (Select › Object › Hairline Slivers…) selects the objects Clean Up would remove, only inside the isolated group while one is isolated, and replies `{count, warning?}`. Neither command -takes hidden or locked objects, objects in template layers, art on locked artboards, guides, the clipping paths of -groups and layers, shapes with an effect, or the members of Live Paint groups and other live or generated art. A shape +takes hidden or locked objects, objects at 0% opacity or in a group or layer at 0% opacity, objects in template +layers, art on locked artboards, guides, the clipping paths of groups and layers, what a group or compound path used as +a clipping path holds, shapes with an effect, or the members of Live Paint groups and other live or generated art. A shape that holds a circle 15/16 of the width across is kept too. A shape too complex to measure is kept as well, and so is every shape still unmeasured when one run reaches its limit of work; the reply's `warning` says how many there were: