From d41bf487384e2df97dc8c24e0fef6158204ee885 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 2 Dec 2026 06:19:35 -0800 Subject: [PATCH] Vector Halftone: round dots inside the cell keep four anchors Circle and Ellipse dots that fit inside their cell use the four-anchor ellipse path again; the quadrant builder is kept for dots that need clipping. The style tests use a gray fill, so an explicit shape that is ignored changes the result. docs/control-protocol.md lists the dialog's style field. --- crates/effects/src/addons/halftone.rs | 17 +++++++++++++++++ crates/engine/src/tests/halftone.rs | 5 +++-- docs/control-protocol.md | 6 ++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/crates/effects/src/addons/halftone.rs b/crates/effects/src/addons/halftone.rs index 264c66a9f1..dce8b9dea6 100644 --- a/crates/effects/src/addons/halftone.rs +++ b/crates/effects/src/addons/halftone.rs @@ -433,6 +433,12 @@ fn cell_dot(t: f64, h: f64, kind: CellKind) -> PathData { let i = (x.floor() as usize).min(SIZE_STEPS - 1); let (lo, hi) = (sizes.get(i).copied().unwrap_or(0.0), sizes.get(i + 1).copied().unwrap_or(0.0)); let r = lo + (hi - lo) * (x - i as f64); + if matches!(kind, CellKind::Circle | CellKind::Ellipse) { + let (a, b) = if matches!(kind, CellKind::Circle) { (r, r) } else { (1.3 * r, r / 1.3) }; + if t > 0.0 && a <= 1.0 && b <= 1.0 { + return shapes::ellipse(Rect::new(-a * h, -b * h, a * h, b * h)); + } + } let q1 = mapped(&kind.quadrant(r), |p| Point::new(p.x * h, p.y * h)); PathData::from_bezpath(&four_quadrants(&q1)) } @@ -809,6 +815,17 @@ mod tests { assert_eq!(h.color, Color::BLACK); } + #[test] + fn round_dots_inside_the_cell_have_four_anchors() { + for (shape, tone) in [(DotShape::Circle, 0.5), (DotShape::Ellipse, 0.3)] { + let dot = shape.path(tone, 10.0); + assert_eq!(dot.subpaths.len(), 1, "{shape:?}"); + let sp = &dot.subpaths[0]; + assert!(sp.closed, "{shape:?}"); + assert_eq!(sp.anchors.len(), 4, "{shape:?}: {:?}", sp.anchors); + } + } + /// Dots whose quadrants meet on the axes have no extra anchors at the joins: a Circle dot small /// enough to stay inside its cell has the anchors of its arcs only, all distinct. #[test] diff --git a/crates/engine/src/tests/halftone.rs b/crates/engine/src/tests/halftone.rs index abe6dec60d..c7ec58549c 100644 --- a/crates/engine/src/tests/halftone.rs +++ b/crates/engine/src/tests/halftone.rs @@ -66,11 +66,11 @@ fn halftone_options() { } } -/// The dot path Vector Halftone makes from a black square with `params`. +/// The dot path Vector Halftone makes from a gray square with `params`. fn dots_of(params: serde_json::Value) -> vectorcraft_geom::PathData { let mut s = session(); red_rect(&mut s); - s.execute("paint.setFill", &json!({"color": "#000000"})).unwrap(); + s.execute("paint.setFill", &json!({"color": "#808080"})).unwrap(); let r = s.execute("object.vectorHalftone", ¶ms).unwrap(); let g = node(&s, NodeId(r["id"].as_u64().unwrap())); g.children().unwrap()[0].path_data().unwrap().clone() @@ -83,6 +83,7 @@ fn halftone_styles_set_the_shape_and_angle_unless_given() { assert_ne!(dots_of(json!({"frequency": 18, "style": "grid"})), dots_of(json!({"frequency": 18}))); // A given shape or angle wins over the style's. assert_eq!(dots_of(json!({"frequency": 18, "style": "grid", "shape": "circle"})), dots_of(json!({"frequency": 18, "angle": 0}))); + assert_ne!(dots_of(json!({"frequency": 18, "style": "grid", "shape": "circle"})), dots_of(json!({"frequency": 18, "style": "grid"}))); assert_eq!(dots_of(json!({"frequency": 18, "style": "gridDots", "angle": 45})), dots_of(json!({"frequency": 18, "style": "gridDotsAngle"}))); // An unknown style is refused and leaves the document as it was. let mut s = session(); diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 0e9daff967..29b8c9a250 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -1077,8 +1077,10 @@ Colour adjustment effects (Effect → Color Adjustments) open the `effect` dialo `channel` for Curves and Levels, `points` for Curves, `color` for Shift to Color) and they preview live; set them with `ui.dialog.set` and `ui.dialog.confirm` to apply (Curves also has a graph: drag its points). Object → Vector Halftone… (`engine.execute {command: "ui.menuDialog", params: {command: "object.vectorHalftone"}}`) opens the -`object.vectorHalftone` dialog (fields `shape`, `frequency`, `angle`, `mode`, `color`, `invert`, `clip`, `keepOriginal`, -`preview`): it previews live and `ui.dialog.confirm` keeps the halftone as one undo step. +`object.vectorHalftone` dialog (fields `style`, `shape`, `frequency`, `angle`, `mode`, `color`, `invert`, `clip`, +`keepOriginal`, `preview`): it previews live and `ui.dialog.confirm` keeps the halftone as one undo step. +The `style` field accepts `custom`, `grid`, `gridAngle`, `gridDots`, and `gridDotsAngle`. A named style hides +Shape and Angle, which apply only with Custom. Tool options last: `tool.setOption {key, value}` or `{values: {…}}` (and `tool` to set another tool's) sets them, and the options a tool keeps (Liquify brush and tool options, Mirror & Cut, Puppet Warp, Symbolism, drawing tools) stay