From dbf0927385f2a31e718c501b9daad4e63c7d80b6 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 14:31:51 -0800 Subject: [PATCH] Image Trace: the seam fills' clip stays within the traced paths' box The Seam Fills group's clipping path was the image's box. A group with a clip is measured by its clipping path, so on a trace with transparent or ignored margins the expanded trace measured as the whole image, and selection, alignment and resizing used that box. The clipping path is now the image's box cut to the box of the traced paths: on a turned image it has up to eight corners, and the anchor limit counts eight for it. docs/mcp.md, the params text and the progress line describe the clip. --- crates/engine/src/cmd/buildcmds.rs | 2 +- crates/engine/src/cmd/buildcmds/trace.rs | 100 +++++++++++++++++------ crates/engine/src/tests/build.rs | 44 ++++++---- docs/mcp.md | 9 +- docs/target-app-parity.md | 2 +- 5 files changed, 111 insertions(+), 46 deletions(-) diff --git a/crates/engine/src/cmd/buildcmds.rs b/crates/engine/src/cmd/buildcmds.rs index 7a0aa54d32..d523577ae8 100644 --- a/crates/engine/src/cmd/buildcmds.rs +++ b/crates/engine/src/cmd/buildcmds.rs @@ -144,7 +144,7 @@ pub fn specs() -> Vec { "Make", ["Object", "Image Trace"], None, - "{id?: image or Image Trace group (default: selection), preset?: name (imageTrace.presets), savedPreset?: {settings} (a saved preset's settings, which the journal records so a replay traces with them after the preset is changed, renamed or deleted; used in place of the saved preset `preset` names), enhanced?: false (the preset's enhanced version: with Auto Grouping, and with Shapes in all but High Fidelity Photo; Flat Logo has none and is traced as it is), params?: {mode: \"blackAndWhite\"|\"grayscale\"|\"color\"|\"logo\", threshold: 0-255, palette: \"limited\"|\"fullTone\"|\"automatic\"|\"documentLibrary\" (color mode; limited: the `colors` best colours, fullTone: as many as the tones need, more with colorDetail, automatic: flat art with its own colours, else fullTone, documentLibrary: at most `colors` of the library's colours, as they are), colors: 2-256, colorDetail: 0-100 (fullTone, automatic), library: \"document\" (the document's swatches) or a swatch library id or name (swatch.library.list; documentLibrary), colorGroup?: name (color mode, documentLibrary with library \"document\": the colors of that document color group instead of every swatch; \"\" is every swatch), paths: 0-100, corners: 0-100, noise: px, method: \"abutting\"|\"overlapping\" (abutting with fills, not mode logo: a \"Seam Fills\" clip group under the paths holds strokes along the edges two filled paths share, 1.5 image pixels wide (VectorCraft's own width), in the color of the lower path (on an image stretched more one way than another, each stroke's outline in image pixels as a filled path), clipped to the image's box; paths that became live shapes get none; the paths are not changed), ignoreWhite (leave out white areas), ignoreColor?: \"#rrggbb\" (with ignoreWhite: the colour left out instead of white), ignoreBackground: false (with ignoreWhite: only the areas of the ignored color that reach the image's edge are left out), keepColors?: [\"#rrggbb\"…] (not mode logo: only the palette colors within about 30 levels of a listed color are traced; empty: every color), snapCurvesToLines, shapes: false (filled outlines that are a circle, an ellipse, a rectangle or a regular polygon come out as that live shape), autoGrouping: false (each path that has others inside it is grouped with them), gradients: false (grayscale and color: an area whose colour changes evenly along one direction is one path with a linear gradient fill), fills: true, strokes: false (Create: lines up to strokeWidth wide become stroked centre lines; without fills, wider areas become stroked outlines), strokeWidth: px (10), logoColors?: [\"#rrggbb\"…] (mode logo: flat-colour logos only; colours found automatically or named here, at most ten; white is its own color, and a named color with every channel 245 or more is taken as that white, except with logoColors named, logoWhite false and no ignoreWhite; noise = areas under noise/10 px ignored; edges to a fraction of a pixel, sharp corners restored, lines and circles snapped; enclosed transparent areas are painted white while white is its own color, and stay holes with ignoreWhite or without a white of its own; fills/strokes are ignored; gradients and photos are refused, judged by the image's own colors also when logoColors are named), logoWhite: true (mode logo with logoColors named; false traces the named colors only: white areas take the nearest of them, a named white is kept and enclosed transparent areas stay holes; with ignoreWhite, white areas are left out either way)}, view?: as imageTrace.setView (default: the traced object's own, else tracingResult), ids?: [id…] (instead of id)} → {id, paths, anchors, colors, warnings: [text…] (the image is over 1500 px on a side, so it traces more slowly; or it was traced scaled down; Flat Logo names only the size it traced a larger image at; or a keepColors color matches none the trace found, or nothing was traced)}", + "{id?: image or Image Trace group (default: selection), preset?: name (imageTrace.presets), savedPreset?: {settings} (a saved preset's settings, which the journal records so a replay traces with them after the preset is changed, renamed or deleted; used in place of the saved preset `preset` names), enhanced?: false (the preset's enhanced version: with Auto Grouping, and with Shapes in all but High Fidelity Photo; Flat Logo has none and is traced as it is), params?: {mode: \"blackAndWhite\"|\"grayscale\"|\"color\"|\"logo\", threshold: 0-255, palette: \"limited\"|\"fullTone\"|\"automatic\"|\"documentLibrary\" (color mode; limited: the `colors` best colours, fullTone: as many as the tones need, more with colorDetail, automatic: flat art with its own colours, else fullTone, documentLibrary: at most `colors` of the library's colours, as they are), colors: 2-256, colorDetail: 0-100 (fullTone, automatic), library: \"document\" (the document's swatches) or a swatch library id or name (swatch.library.list; documentLibrary), colorGroup?: name (color mode, documentLibrary with library \"document\": the colors of that document color group instead of every swatch; \"\" is every swatch), paths: 0-100, corners: 0-100, noise: px, method: \"abutting\"|\"overlapping\" (abutting with fills, not mode logo: a \"Seam Fills\" clip group under the paths holds strokes along the edges two filled paths share, 1.5 image pixels wide (VectorCraft's own width), in the color of the lower path (on an image stretched more one way than another, each stroke's outline in image pixels as a filled path), clipped to the image's box within the traced paths' box; paths that became live shapes get none; the paths are not changed), ignoreWhite (leave out white areas), ignoreColor?: \"#rrggbb\" (with ignoreWhite: the colour left out instead of white), ignoreBackground: false (with ignoreWhite: only the areas of the ignored color that reach the image's edge are left out), keepColors?: [\"#rrggbb\"…] (not mode logo: only the palette colors within about 30 levels of a listed color are traced; empty: every color), snapCurvesToLines, shapes: false (filled outlines that are a circle, an ellipse, a rectangle or a regular polygon come out as that live shape), autoGrouping: false (each path that has others inside it is grouped with them), gradients: false (grayscale and color: an area whose colour changes evenly along one direction is one path with a linear gradient fill), fills: true, strokes: false (Create: lines up to strokeWidth wide become stroked centre lines; without fills, wider areas become stroked outlines), strokeWidth: px (10), logoColors?: [\"#rrggbb\"…] (mode logo: flat-colour logos only; colours found automatically or named here, at most ten; white is its own color, and a named color with every channel 245 or more is taken as that white, except with logoColors named, logoWhite false and no ignoreWhite; noise = areas under noise/10 px ignored; edges to a fraction of a pixel, sharp corners restored, lines and circles snapped; enclosed transparent areas are painted white while white is its own color, and stay holes with ignoreWhite or without a white of its own; fills/strokes are ignored; gradients and photos are refused, judged by the image's own colors also when logoColors are named), logoWhite: true (mode logo with logoColors named; false traces the named colors only: white areas take the nearest of them, a named white is kept and enclosed transparent areas stay holes; with ignoreWhite, white areas are left out either way)}, view?: as imageTrace.setView (default: the traced object's own, else tracingResult), ids?: [id…] (instead of id)} → {id, paths, anchors, colors, warnings: [text…] (the image is over 1500 px on a side, so it traces more slowly; or it was traced scaled down; Flat Logo names only the size it traced a larger image at; or a keepColors color matches none the trace found, or nothing was traced)}", has_selection_or_ids, |s, p| trace_make(s, p, false) ), diff --git a/crates/engine/src/cmd/buildcmds/trace.rs b/crates/engine/src/cmd/buildcmds/trace.rs index 8e470f56cd..a2ac857903 100644 --- a/crates/engine/src/cmd/buildcmds/trace.rs +++ b/crates/engine/src/cmd/buildcmds/trace.rs @@ -723,10 +723,11 @@ fn seam_unit(img_xf: vectorcraft_geom::Affine, xf: vectorcraft_geom::Affine) -> /// the paths, the seam fills and their clip together stay within `max` anchors. With `outlined`, /// each stroke is replaced by a filled path, its outline in raster pixels ([`outline_seams`]), /// for an image stretched more one way than another ([`seam_unit`]). The strokes have at most as -/// many anchors as the paths and the clip has four, so a trace whose paths have more than half of -/// `max` less two gets none. Outlines, which have more anchors, are counted as each is made, and -/// none is made when [`SEAM_OUTLINE_ANCHORS`] times the strokes' anchors would not fit, or once -/// those made so far no longer fit. [`EngineError::Cancelled`] once `steps` answers `false`. +/// many anchors as the paths and the clip at most [`SEAM_CLIP_ANCHORS`], so a trace whose paths +/// have more than half of `max` less four gets none. Outlines, which have more anchors, are +/// counted as each is made, and none is made when [`SEAM_OUTLINE_ANCHORS`] times the strokes' +/// anchors would not fit, or once those made so far no longer fit. [`EngineError::Cancelled`] +/// once `steps` answers `false`. fn seams_within( res: &tr::TraceResult, params: &tr::TraceParams, @@ -735,17 +736,17 @@ fn seams_within( outlined: bool, steps: &(dyn Fn(u64, u64) -> bool + Sync), ) -> Result> { - if res.anchor_count().saturating_mul(2).saturating_add(4) > max { + if res.anchor_count().saturating_mul(2).saturating_add(SEAM_CLIP_ANCHORS) > max { return Ok(None); } let Some(mut seams) = tr::seam_fills(&res.paths, params, size) else { return Ok(None) }; if outlined { let strokes = seams.strokes.iter().map(|tp| tp.path.anchor_count()).sum::(); - let estimate = strokes.saturating_mul(SEAM_OUTLINE_ANCHORS).saturating_add(seams.clip.anchor_count()); + let estimate = strokes.saturating_mul(SEAM_OUTLINE_ANCHORS).saturating_add(SEAM_CLIP_ANCHORS); if res.anchor_count().saturating_add(estimate) > max { return Ok(None); } - let budget = max.saturating_sub(res.anchor_count()).saturating_sub(seams.clip.anchor_count()); + let budget = max.saturating_sub(res.anchor_count()).saturating_sub(SEAM_CLIP_ANCHORS); if !outline_seams(&mut seams.strokes, budget, steps)? { return Ok(None); } @@ -757,6 +758,10 @@ fn seams_within( Ok(Some(seams)) } +/// The most anchors the seam fills' clip has: the image's box cut to the box of the traced paths +/// ([`within_box`]), four corners and at most four more where the image is turned. +const SEAM_CLIP_ANCHORS: usize = 8; + /// How many seam strokes [`outline_seams`] outlines between asking whether to go on. const SEAM_OUTLINE_STEP: usize = 64; @@ -913,7 +918,8 @@ pub(super) fn trace_make(s: &mut Session, p: &Value, expand: bool) -> Result> = seam_fills .iter() .flat_map(|f| &f.strokes) @@ -946,16 +952,6 @@ pub(super) fn trace_make(s: &mut Session, p: &Value, expand: bool) -> Result Result = f.clip.subpaths.iter().flat_map(|sp| sp.anchors.iter().map(|a| xf * a.p)).collect(); + let inside = within_box(&corners, art); + if inside.len() >= 3 { + let mut clip = shape_node(d, vectorcraft_geom::PathData::single(vectorcraft_geom::SubPath::polyline(&inside, true)), None); + if let NodeKind::Path { clipping, .. } = &mut clip.kind { + *clipping = true; + } + let members = std::iter::once(Arc::new(clip)).chain(strokes).collect(); + let mut g = Node::new(d.alloc_id(), NodeKind::Group { children: members, clip: true }); + g.name = Some(SEAM_FILLS_NAME.into()); + children.push(Arc::new(g)); + } + } children.extend(grouped(d, traced, &res.parents)); if group_by_color { children = color_groups(c, d, children)?; @@ -1003,6 +1016,28 @@ pub(super) fn trace_make(s: &mut Session, p: &Value, expand: bool) -> Result Vec { + let sides: [&dyn Fn(Point) -> f64; 4] = [&|p| p.x - r.x0, &|p| r.x1 - p.x, &|p| p.y - r.y0, &|p| r.y1 - p.y]; + let mut out = poly.to_vec(); + for side in sides { + let corners = std::mem::take(&mut out); + for (k, &p) in corners.iter().enumerate() { + let Some(&q) = corners.get((k + 1) % corners.len()) else { continue }; + let (dp, dq) = (side(p), side(q)); + if dp >= 0.0 { + out.push(p); + } + if (dp > 0.0 && dq < 0.0) || (dp < 0.0 && dq > 0.0) { + out.push(p + (q - p) * (dp / (dp - dq))); + } + } + } + out +} + /// Images larger than this on a side are traced, but more slowly: the trace says so. pub const LARGE_TRACE_SIDE: u32 = 1500; @@ -1302,7 +1337,7 @@ mod color_group_tests { #[cfg(test)] mod trace_limit_tests { - use super::{MAX_TRACE_ANCHORS, SEAM_OUTLINE_ANCHORS, keep_warnings, outline_seams, seams_within, trace_warnings}; + use super::{MAX_TRACE_ANCHORS, SEAM_CLIP_ANCHORS, SEAM_OUTLINE_ANCHORS, keep_warnings, outline_seams, seams_within, trace_warnings}; use vectorcraft_trace as tr; #[test] @@ -1318,12 +1353,12 @@ mod trace_limit_tests { let all = tr::seam_fills(&res.paths, ¶ms, (24, 16)); assert!(all.is_some(), "{res:?}"); let anchors = res.anchor_count(); - assert!(anchors + all.as_ref().map_or(0, tr::SeamFills::anchor_count) <= 2 * anchors + 4); + assert!(anchors + all.as_ref().map_or(0, tr::SeamFills::anchor_count) <= 2 * anchors + SEAM_CLIP_ANCHORS); let go = |_: u64, _: u64| true; - // Twice the paths' anchors and the clip's four leave room for any seam fills. - assert_eq!(seams_within(&res, ¶ms, (24, 16), 2 * anchors + 4, false, &go).unwrap(), all); + // Twice the paths' anchors and the clip's eight at most leave room for any seam fills. + assert_eq!(seams_within(&res, ¶ms, (24, 16), 2 * anchors + SEAM_CLIP_ANCHORS, false, &go).unwrap(), all); // One anchor short of that: none. - assert_eq!(seams_within(&res, ¶ms, (24, 16), 2 * anchors + 3, false, &go).unwrap(), None); + assert_eq!(seams_within(&res, ¶ms, (24, 16), 2 * anchors + SEAM_CLIP_ANCHORS - 1, false, &go).unwrap(), None); // Outlined, the seam fills are filled paths, within SEAM_OUTLINE_ANCHORS of the strokes' // anchors each. let strokes = |f: &tr::SeamFills| f.strokes.iter().map(|tp| tp.path.anchor_count()).sum::(); @@ -1342,8 +1377,8 @@ mod trace_limit_tests { let outlined = seams_within(&res, ¶ms, (32, 32), MAX_TRACE_ANCHORS, true, &go).unwrap().unwrap(); assert!(strokes(&outlined) > anchors, "{} outline anchors, {anchors} in the paths", strokes(&outlined)); assert!(strokes(&outlined) <= SEAM_OUTLINE_ANCHORS * n, "{} outline anchors, {n} stroke anchors", strokes(&outlined)); - let fits = anchors + SEAM_OUTLINE_ANCHORS * n + 4; - assert!(fits > 2 * anchors + 4, "{fits}, {anchors} in the paths"); + let fits = anchors + SEAM_OUTLINE_ANCHORS * n + SEAM_CLIP_ANCHORS; + assert!(fits > 2 * anchors + SEAM_CLIP_ANCHORS, "{fits}, {anchors} in the paths"); assert_eq!(seams_within(&res, ¶ms, (32, 32), fits, true, &go).unwrap(), Some(outlined.clone())); assert_eq!(seams_within(&res, ¶ms, (32, 32), fits - 1, true, &go).unwrap(), None); assert_eq!(seams_within(&res, ¶ms, (32, 32), fits - 1, false, &go).unwrap(), Some(all.clone())); @@ -1358,6 +1393,21 @@ mod trace_limit_tests { assert!(matches!(outline_seams(&mut all.strokes.clone(), need, &stop), Err(super::EngineError::Cancelled))); } + #[test] + fn within_box_cuts_a_turned_box_to_a_box() { + use vectorcraft_geom::{Point, Rect}; + // A square turned by 45° in a smaller box: each side cuts a corner off, 8 corners. + let diamond = [Point::new(0.0, -10.0), Point::new(10.0, 0.0), Point::new(0.0, 10.0), Point::new(-10.0, 0.0)]; + let cut = super::within_box(&diamond, Rect::new(-6.0, -6.0, 6.0, 6.0)); + assert_eq!(cut.len(), 8, "{cut:?}"); + assert!(cut.iter().all(|p| p.x.abs() <= 6.0 + 1e-12 && p.y.abs() <= 6.0 + 1e-12 && p.x.abs() + p.y.abs() <= 10.0 + 1e-12), "{cut:?}"); + // A corner on a side is kept once. + let square = [Point::new(0.0, 0.0), Point::new(4.0, 0.0), Point::new(4.0, 4.0), Point::new(0.0, 4.0)]; + assert_eq!(super::within_box(&square, Rect::new(0.0, 0.0, 4.0, 4.0)), square.to_vec()); + assert_eq!(super::within_box(&square, Rect::new(1.0, 0.0, 4.0, 4.0)).len(), 4); + assert!(super::within_box(&square, Rect::new(5.0, 5.0, 6.0, 6.0)).is_empty()); + } + #[test] fn seams_are_strokes_only_where_the_image_is_scaled_alike_every_way() { use super::seam_unit; diff --git a/crates/engine/src/tests/build.rs b/crates/engine/src/tests/build.rs index d4b3d47df7..722cee04fe 100644 --- a/crates/engine/src/tests/build.rs +++ b/crates/engine/src/tests/build.rs @@ -6133,26 +6133,40 @@ fn image_trace_abutting_seam_fills_sit_under_the_paths() { // Overlapping paths are stacked: no seam fills. let (s, _, r) = made("overlapping", "imageTrace.make", false); assert!(seams(&node(&s, NodeId(r["id"].as_u64().unwrap()))).is_none()); - // White left out: the strokes are still clipped to the image's box. +} + +/// With white left out, the seam fills are clipped to the image's box within the traced paths' +/// box, so the expanded trace measures as its paths do, also on a turned image. +#[test] +fn image_trace_seam_fills_stay_within_the_traced_paths_box() { + let seams = |n: &Node| n.children().unwrap().iter().find(|c| c.name.as_deref() == Some("Seam Fills")).cloned(); let band = vectorcraft_trace::Raster::from_fn(24, 16, |x, y| match ((4..12).contains(&y), x < 12) { (false, _) => [255; 4], (true, true) => [200, 30, 30, 255], (true, false) => [30, 30, 200, 255], }); - let mut s = session(); - add_image(&mut s, &band, Affine::IDENTITY); - let r = s - .execute( - "imageTrace.make", - &json!({"params": {"mode": "color", "palette": "limited", "colors": 3, "method": "abutting", "ignoreWhite": true}}), - ) - .unwrap(); - assert_eq!(r["paths"], 2, "{r}"); - let group = seams(&node(&s, NodeId(r["id"].as_u64().unwrap()))).unwrap(); - let clip = &group.children().unwrap()[0]; - assert!(matches!(clip.kind, NodeKind::Path { .. }), "{clip:?}"); - let cb = outline(clip).0.bounds().unwrap(); - assert!([cb.x0, cb.y0, cb.x1 - 24.0, cb.y1 - 16.0].iter().all(|v| v.abs() < 1e-9), "{cb:?}"); + for xf in [Affine::IDENTITY, Affine::translate((100.0, 100.0)) * Affine::rotate(0.5)] { + let mut s = session(); + add_image(&mut s, &band, xf); + let r = s + .execute( + "imageTrace.makeAndExpand", + &json!({"params": {"mode": "color", "palette": "limited", "colors": 3, "method": "abutting", "ignoreWhite": true}}), + ) + .unwrap(); + assert_eq!(r["paths"], 2, "{r}"); + let n = node(&s, NodeId(r["id"].as_u64().unwrap())); + let group = seams(&n).unwrap(); + let clip = &group.children().unwrap()[0]; + assert!(matches!(clip.kind, NodeKind::Path { clipping: true, .. }), "{clip:?}"); + let cb = outline(clip).0.bounds().unwrap(); + let paths = n.children().unwrap()[1..].iter().filter_map(|c| c.geometric_bounds()).reduce(|a, b| a.union(b)).unwrap(); + assert_eq!(n.geometric_bounds(), Some(paths), "{xf:?}"); + assert!(cb.x0 >= paths.x0 - 1e-9 && cb.y0 >= paths.y0 - 1e-9 && cb.x1 <= paths.x1 + 1e-9 && cb.y1 <= paths.y1 + 1e-9, "{xf:?}: {cb:?}"); + if xf == Affine::IDENTITY { + assert!([cb.x0, cb.y0 - 4.0, cb.x1 - 24.0, cb.y1 - 12.0].iter().all(|v| v.abs() < 1e-9), "{cb:?}"); + } + } } /// On an image stretched more one way than another, the seam fills are the strokes' outlines in diff --git a/docs/mcp.md b/docs/mcp.md index 6d6caa3015..31536f4d6c 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3834,10 +3834,11 @@ already walks Image Trace. Short agent entry points: that color (a gradient path's stroke takes its gradient), with butt caps and round joins. The stroke is 1.5 image pixels wide, VectorCraft's own width. On an image stretched more one way than another, the group holds each stroke's outline in image pixels as a filled path instead; the outline covers 0.75 image pixels on each side of its - edge. The group clips the strokes or outlines to the image's box. Where a shared edge ends at, or runs within 0.75 - image pixels of, a transparent area or a color left out, its stroke can reach up to 0.75 image pixels into that - area. Paths that became live shapes (`shapes`) take no part. The traced paths and their shared edges are the same - with or without the group. A trace whose paths have more than about half of the trace's anchor limit (8,000,000, + edge. The group clips the strokes or outlines to the image's box within the box of the traced paths, and its + bounds lie within that box. Where a shared edge ends at, or runs within 0.75 image pixels of, a + transparent area or a color left out, its stroke can reach up to 0.75 image pixels into that area. Paths that + became live shapes (`shapes`) take no part. The traced paths and their shared edges are the same with or without + the group. A trace whose paths have more than about half of the trace's anchor limit (8,000,000, 2,000,000 on the web) has no seam fills. Both Expand commands keep the group, and `byColor` leaves it under every color's group; `byColor` refuses a trace whose seam fills' group was moved above a path. The strokes are separate objects, in a trace and after Expand: recoloring, moving or deleting a traced path leaves them as they are, and diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 217de41cd7..b52bcc7b5c 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1510,7 +1510,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Image Trace, Document Library color groups:** with Document Swatches, the panel's Colors menu and `"colorGroup"` trace with one color group's colors instead of every swatch, as the public panel documentation describes Document Library; code-drawn tests in `crates/engine` and the panel. - **Image Trace, Document Library colors:** with Document Swatches, traced fills and strokes use the displayed colors of process, global, spot and tint swatches without links, so editing a swatch leaves the trace unchanged; swatch-library colors are also unlinked; code-drawn tests in `crates/engine`. - **Image Trace, flattened slivers:** in a Color, Grayscale or Black and White trace with Fills, a traced region whose outline straightens onto one line (a single pixel, or a one-pixel row along an edge, its pieces shared with the regions beside it) is left out instead of becoming a selectable path with no area, which paints nothing. Snap Curves To Lines straightens more outlines, so it leaves out more of these. Without Fills, the region's 1 px stroke draws it, and it is kept. Code-drawn tests in `crates/trace`. -- **Image Trace, Abutting seam fills:** an Abutting trace with Fills holds a `Seam Fills` clip group under its paths, with strokes along the edges two filled paths share, in the lower path's color, 1.5 image pixels wide (VectorCraft's own width) and clipped to the image's box; on an image stretched more one way than another, each stroke's outline in image pixels is a filled path instead. The paths and their shared edges are unchanged. Tests: `seam::tests` in `crates/trace`, `image_trace_abutting_seam_fills_sit_under_the_paths` and `image_trace_seam_fills_on_a_stretched_image_stay_near_their_edge` in `crates/engine`. +- **Image Trace, Abutting seam fills:** an Abutting trace with Fills holds a `Seam Fills` clip group under its paths, with strokes along the edges two filled paths share, in the lower path's color, 1.5 image pixels wide (VectorCraft's own width) and clipped to the image's box within the traced paths' box; on an image stretched more one way than another, each stroke's outline in image pixels is a filled path instead. The paths and their shared edges are unchanged. Tests: `seam::tests` in `crates/trace`, `image_trace_abutting_seam_fills_sit_under_the_paths` and `image_trace_seam_fills_on_a_stretched_image_stay_near_their_edge` in `crates/engine`. - **Image Trace, Auto Color rare colours:** the Automatic palette keeps colours too rare for its area count when they are distinct (Oklab) and drawn as coherent regions, at most six, protected from mixed-colour merging and Noise; code-drawn stem, highlight, low-contrast and scattered-noise tests (see [quality notes](image-trace-quality.md#auto-color-keeps-rare-colours)). - **Image Trace, nearly flat dark grounds:** with a Limited palette of 9 to 16 colors (16 Colors, and Document Library without swatches), by VectorCraft's own rule, a cut whose two sides both have a dark gray mean (Oklab lightness under 0.30, chroma under 0.03) and lie less than 0.03 apart in Oklab has its gain scaled by (distance / 0.03)². A near-black ground with faint noise then traces in one color, and the color it would have taken goes to another cut. Code-drawn tests `a_nearly_flat_dark_ground_keeps_one_color`, `only_a_limited_palette_of_nine_to_sixteen_colors_weighs_alike_sides` and `a_dark_colored_figure_on_a_nearly_flat_dark_ground_keeps_its_color` in `crates/trace`. - **Image Trace, Document Library keeps neutral tones neutral:** each pixel takes the library color nearest in Oklab with differences in hue and chroma counted three times, so a gray or a muted brown traces as a neutral library color instead of a saturated one of similar lightness; a code-drawn test of gray and brown patches with a black, light and blue library in `crates/trace`.