From 342341a55f230235436f1fb83aac347b826ff936 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 23:42:48 -0800 Subject: [PATCH 1/2] Smooth: path.smoothRegion and path.joinScrub refuse a radius, fidelity or tolerance outside its range path.smoothRegion read a radius below 0 as 0 and moved a fidelity into its range, and path.joinScrub read a tolerance below 0 as 0. Each now refuses a value outside its range with an error naming the key, and the document, the selection and the undo history do not change: radius and tolerance 0.001 to 1000 pt (the Path Eraser's width range), fidelity 0.000078125 to about 3195 pt (the Smooth tool's 0.05 to 100 px at the highest and the lowest zoom). A key left out or null keeps its default. The Smooth, Join and Path Eraser tools, and an Alt smoothing drag with the Pencil, Paintbrush or Blob Brush, keep what they send within these ranges at any zoom, also when the interface zoom puts the tool's zoom past the view's range. Docs: params text, docs/mcp.md, docs/target-app-parity.md. --- crates/engine/src/cmd/draw2/commands.rs | 4 +- crates/engine/src/cmd/draw2/smooth.rs | 16 ++++--- crates/engine/src/tests/draw2.rs | 60 +++++++++++++++++++++++++ crates/tools/src/draw2.rs | 5 +++ crates/tools/src/draw2/gesture.rs | 24 +++++++--- crates/tools/src/draw2/gesture/tests.rs | 39 ++++++++++++++++ docs/mcp.md | 8 ++++ docs/target-app-parity.md | 1 + 8 files changed, 144 insertions(+), 13 deletions(-) diff --git a/crates/engine/src/cmd/draw2/commands.rs b/crates/engine/src/cmd/draw2/commands.rs index e4846367b5..9c3dcbd47a 100644 --- a/crates/engine/src/cmd/draw2/commands.rs +++ b/crates/engine/src/cmd/draw2/commands.rs @@ -120,7 +120,7 @@ pub fn specs() -> Vec { "Smooth", [], None, - "{points: [[x,y]…] (pen values after x and y are checked as path.freehand checks them and do not change the smoothing), radius?: pt (12), fidelity?: pt (2.5; kept within 0.000078125 and about 3195, the Smooth tool's 0.05 to 100 px at the highest and the lowest zoom: the tool sends its Fidelity in screen pixels divided by the zoom)} smooth selected paths near the drag, keeping a corner where the path turns by more than 57.5° at the anchor and over radius and twice radius on either side → {ids, before, after}", + "{points: [[x,y]…] (pen values after x and y are checked as path.freehand checks them and do not change the smoothing), radius?: pt (12; from 0.001 to 1000), fidelity?: pt (2.5; from 0.000078125 to about 3195, the Smooth tool's 0.05 to 100 px at the highest and the lowest zoom: the tool sends its Fidelity in screen pixels divided by the zoom, kept within the range)} smooth selected paths near the drag, keeping a corner where the path turns by more than 57.5° at the anchor and over radius and twice radius on either side → {ids, before, after}. A radius or fidelity outside its range is refused with an error, and nothing changes", has_selection, smooth_region ), @@ -129,7 +129,7 @@ pub fn specs() -> Vec { "Join", [], None, - "{points: [[x,y]…] (pen values after x and y are checked as path.freehand checks them and do not change the join), tolerance?: pt (12)} join the open-path endpoints scrubbed over, or trim two crossing open paths whose overhanging ends are scrubbed and join them at the crossing → {id}", + "{points: [[x,y]…] (pen values after x and y are checked as path.freehand checks them and do not change the join), tolerance?: pt (12; from 0.001 to 1000)} join the open-path endpoints scrubbed over, or trim two crossing open paths whose overhanging ends are scrubbed and join them at the crossing → {id}. A tolerance outside 0.001 to 1000 is refused with an error, and nothing changes", has_doc, join_scrub ), diff --git a/crates/engine/src/cmd/draw2/smooth.rs b/crates/engine/src/cmd/draw2/smooth.rs index d0f480d132..52b18c3a31 100644 --- a/crates/engine/src/cmd/draw2/smooth.rs +++ b/crates/engine/src/cmd/draw2/smooth.rs @@ -1,9 +1,9 @@ use vectorcraft_pathops::addons::pathtools as pt; -use super::common::{dist_to_polyline, ids_json, path_mut, path_of, points_param, poly_bounds, subpath_len, target_paths}; +use super::common::{dist_to_polyline, ids_json, path_mut, path_of, points_param, poly_bounds, ranged, subpath_len, target_paths}; use super::{ - Anchor, BezPath, CubicBez, NodeId, ParamCurve, ParamCurveNearest, PathData, Point, Rect, Result, Session, SimplifyOptions, SubPath, Value, json, - number_or, po, + Anchor, BezPath, CubicBez, NodeId, ParamCurve, ParamCurveNearest, PathData, Point, Rect, Result, Session, SimplifyOptions, SubPath, Value, bad, + json, number_or, po, }; // ---------- Smooth ---------- @@ -733,8 +733,12 @@ fn smooth_open(anchors: &[Anchor], marked: &[bool], near: &dyn Fn(Point) -> bool pub(super) fn smooth_region(s: &mut Session, p: &Value) -> Result { const C: &str = "path.smoothRegion"; let pts = points_param(p, "points", C)?; - let radius = number_or(p, "radius", 12.0, C)?.max(0.0); - let tol = number_or(p, "fidelity", 2.5, C)?.clamp(vectorcraft_tools::draw2::SMOOTH_MIN_TOLERANCE, vectorcraft_tools::draw2::SMOOTH_MAX_TOLERANCE); + let radius = ranged(p, "radius", 12.0, vectorcraft_tools::draw2::REACH_RANGE, C)?; + let tol = number_or(p, "fidelity", 2.5, C)?; + let (lo, hi) = (vectorcraft_tools::draw2::SMOOTH_MIN_TOLERANCE, vectorcraft_tools::draw2::SMOOTH_MAX_TOLERANCE); + if !(lo..=hi).contains(&tol) { + return Err(bad(C, format!("`fidelity` must be from {lo} to {hi} pt"))); + } let sigma = radius * SMOOTH_SPREAD; let st = s.doc()?; let mut plan = vec![]; @@ -882,7 +886,7 @@ fn trim_join(d: &vectorcraft_doc::Document, ids: &[NodeId], pts: &[Point], tol: pub(super) fn join_scrub(s: &mut Session, p: &Value) -> Result { const C: &str = "path.joinScrub"; let pts = points_param(p, "points", C)?; - let tol = number_or(p, "tolerance", 12.0, C)?.max(0.0); + let tol = ranged(p, "tolerance", 12.0, vectorcraft_tools::draw2::REACH_RANGE, C)?; let st = s.doc()?; let targets = target_paths(&st.doc, &st.selection, poly_bounds(&pts, tol)); // Paths that cross with their ends scrubbed are trimmed there and joined (#5844). diff --git a/crates/engine/src/tests/draw2.rs b/crates/engine/src/tests/draw2.rs index 75d7d081d9..fe151dd7bb 100644 --- a/crates/engine/src/tests/draw2.rs +++ b/crates/engine/src/tests/draw2.rs @@ -3313,6 +3313,66 @@ fn path_eraser_width_outside_its_range_is_refused() { } } +/// `path.smoothRegion` refuses a `radius` outside 0.001 to 1000 pt and a `fidelity` outside the +/// Smooth tool's tolerance range, and `path.joinScrub` a `tolerance` outside 0.001 to 1000 pt: the +/// document, the selection and the undo history do not change. The ends of each range are taken, +/// and null is read as the key left out, which smooths or joins in one undo step. +#[test] +fn smooth_and_join_refuse_a_reach_or_fidelity_outside_its_range() { + let mut s = session(); + let anchors: Vec<_> = (0..=40).map(|i| json!({"x": 100.0 + i as f64 * 5.0, "y": if i % 2 == 0 { 200.0 } else { 203.0 }})).collect(); + let r = s.execute("path.create", &json!({"anchors": anchors})).unwrap(); + let id = NodeId(r["id"].as_u64().unwrap()); + s.execute("select.set", &json!({"ids": [id.0]})).unwrap(); + let drag = json!({"points": [[90, 200], [200, 200], [310, 200]]}); + let (lo, hi) = (vectorcraft_tools::draw2::SMOOTH_MIN_TOLERANCE, vectorcraft_tools::draw2::SMOOTH_MAX_TOLERANCE); + let reaches = [json!(0), json!(-1), json!(0.0009), json!(1e-300), json!(1000.01), json!(1e300)]; + let fidelities = [json!(0), json!(-1), json!(lo / 2.0), json!(hi * 1.01), json!(1e300)]; + let refused = reaches + .iter() + .map(|x| ("radius", x, "`radius` must be from 0.001 to 1000".to_string())) + .chain(fidelities.iter().map(|x| ("fidelity", x, format!("`fidelity` must be from {lo} to {hi} pt")))); + for (key, x, want) in refused { + let sel = s.doc().unwrap().selection.clone(); + refuses_with(&mut s, "path.smoothRegion", &with(&drag, json!({ key: x })), &want); + assert_eq!(s.doc().unwrap().selection, sel, "{key} {x} changed the selection"); + } + for extra in [json!({"radius": 0.001}), json!({"radius": 1000}), json!({"fidelity": lo}), json!({"fidelity": hi})] { + let undo = undo_steps(&s); + s.execute("path.smoothRegion", &with(&drag, extra.clone())).unwrap_or_else(|e| panic!("{extra}: {e}")); + while undo_steps(&s) > undo { + s.execute("edit.undo", &json!({})).unwrap(); + } + s.execute("select.set", &json!({"ids": [id.0]})).unwrap(); + } + let before = path(&s, id); + let undo = undo_steps(&s); + s.execute("path.smoothRegion", &with(&drag, json!({"radius": null, "fidelity": null}))).unwrap(); + assert!(path(&s, id) != before, "the default radius and fidelity smoothed nothing"); + assert_eq!(undo_steps(&s), undo + 1); + + let mut s = session(); + line(&mut s, 100.0, 100.0, 200.0, 100.0); + line(&mut s, 205.0, 100.0, 300.0, 150.0); + s.execute("select.none", &json!({})).unwrap(); + let scrub = json!({"points": [[202, 90], [202, 110]]}); + for x in &reaches { + refuses_with(&mut s, "path.joinScrub", &with(&scrub, json!({"tolerance": x})), "`tolerance` must be from 0.001 to 1000"); + assert_eq!(paths(&s).len(), 2, "tolerance {x}"); + } + s.execute("path.joinScrub", &with(&scrub, json!({"tolerance": 0.001}))).unwrap(); + assert_eq!(paths(&s).len(), 2, "0.001 pt reaches neither end"); + let undo = undo_steps(&s); + s.execute("path.joinScrub", &with(&scrub, json!({"tolerance": 1000}))).unwrap(); + while undo_steps(&s) > undo { + s.execute("edit.undo", &json!({})).unwrap(); + } + s.execute("select.none", &json!({})).unwrap(); + s.execute("path.joinScrub", &with(&scrub, json!({"tolerance": null}))).unwrap(); + assert_eq!(paths(&s).len(), 1, "the default tolerance joined nothing"); + assert_eq!(undo_steps(&s), undo + 1); +} + /// The Eraser, Path Eraser, Smooth, Join and Blob Brush commands refuse a size, angle, roundness, /// width, radius, fidelity or tolerance given as text or as another value that is not a number, and change /// nothing; null is read as the key left out. diff --git a/crates/tools/src/draw2.rs b/crates/tools/src/draw2.rs index 3c663006e5..800cda5d94 100644 --- a/crates/tools/src/draw2.rs +++ b/crates/tools/src/draw2.rs @@ -50,6 +50,11 @@ pub const SMOOTH_MIN_TOLERANCE: f64 = SMOOTH_MIN_FIDELITY / 640.0; /// pixels) at the lowest zoom (3.13 %). pub const SMOOTH_MAX_TOLERANCE: f64 = 100.0 / 0.0313; +/// The range (points) of `path.smoothRegion`'s `radius`, `path.joinScrub`'s `tolerance` and +/// `path.eraseSegments`' `width`, which the tools send as screen pixels divided by the zoom. +/// VectorCraft's own range. +pub const REACH_RANGE: (f64, f64) = (0.001, 1000.0); + /// Whether segment `i` of `sp` is straight, so the Smooth tool leaves it as it is: its handles lie /// on the line through its ends, and the segment runs from one end to the other without turning back. pub fn segment_is_straight(sp: &SubPath, i: usize) -> bool { diff --git a/crates/tools/src/draw2/gesture.rs b/crates/tools/src/draw2/gesture.rs index dc123e6cc1..ab88d16436 100644 --- a/crates/tools/src/draw2/gesture.rs +++ b/crates/tools/src/draw2/gesture.rs @@ -96,6 +96,20 @@ fn fit_tolerance(cx: &ToolContext, px: f64) -> f64 { cx.tol(px).clamp(super::MIN_FIT_TOLERANCE, super::MAX_FIT_TOLERANCE) } +/// The `fidelity` (points) the Smooth tool, and an Alt smoothing drag, send `path.smoothRegion` for +/// `px` screen pixels at the current zoom, within the range the command takes +/// ([`super::SMOOTH_MIN_TOLERANCE`]..[`super::SMOOTH_MAX_TOLERANCE`]). +fn smooth_tolerance(cx: &ToolContext, px: f64) -> f64 { + cx.tol(px).clamp(super::SMOOTH_MIN_TOLERANCE, super::SMOOTH_MAX_TOLERANCE) +} + +/// The distance (points) the Smooth, Join and Path Eraser tools send for `px` screen pixels at the +/// current zoom, within [`super::REACH_RANGE`]. +fn reach(cx: &ToolContext, px: f64) -> f64 { + let (lo, hi) = super::REACH_RANGE; + cx.tol(px).clamp(lo, hi) +} + pub struct GestureTool { /// How many points the last preview of the stroke had ([`crate::previews_at`]); 0 when it was /// fitted coarser than the stroke kept ([`PREVIEW_FIDELITY_PX`]). @@ -1550,13 +1564,13 @@ impl GestureTool { fn finish(&mut self, cx: &ToolContext, m: Mods) -> Vec { let pts = &self.points; let has_sel = !cx.selection.is_empty(); - let tol = cx.tol(self.edit_within); - let radius = cx.tol(SMOOTH_RADIUS); + let tol = reach(cx, self.edit_within); + let radius = reach(cx, SMOOTH_RADIUS); if self.smoothing { if pts.len() >= 2 && has_selected_smooth_path(cx) { return vec![Action::Exec( "path.smoothRegion".into(), - json!({"points": points_json(pts), "radius": radius, "fidelity": cx.tol(self.smooth_fidelity)}), + json!({"points": points_json(pts), "radius": radius, "fidelity": smooth_tolerance(cx, self.smooth_fidelity)}), )]; } return vec![]; @@ -1621,10 +1635,10 @@ impl GestureTool { "smooth" if pts.len() >= 2 && has_selected_smooth_path(cx) => { vec![Action::Exec( "path.smoothRegion".into(), - json!({"points": points_json(pts), "radius": radius, "fidelity": cx.tol(self.fidelity)}), + json!({"points": points_json(pts), "radius": radius, "fidelity": smooth_tolerance(cx, self.fidelity)}), )] } - "pathEraser" if has_sel => vec![Action::Exec("path.eraseSegments".into(), json!({"points": points_json(pts), "width": cx.tol(8.0)}))], + "pathEraser" if has_sel => vec![Action::Exec("path.eraseSegments".into(), json!({"points": points_json(pts), "width": reach(cx, 8.0)}))], "join" if pts.len() >= 2 => vec![Action::Exec("path.joinScrub".into(), json!({"points": points_json(pts), "tolerance": tol}))], _ => vec![], } diff --git a/crates/tools/src/draw2/gesture/tests.rs b/crates/tools/src/draw2/gesture/tests.rs index 1ffcf1c37b..dbbbb53a78 100644 --- a/crates/tools/src/draw2/gesture/tests.rs +++ b/crates/tools/src/draw2/gesture/tests.rs @@ -309,6 +309,45 @@ fn fidelity_sent_stays_within_what_path_freehand_takes() { } } +/// `path.smoothRegion`, `path.joinScrub` and `path.eraseSegments` refuse a radius, Fidelity, +/// tolerance or width outside their ranges, so at a zoom beyond the view's range the Smooth, Join +/// and Path Eraser tools, and an Alt smoothing drag, send the nearer end of each. +#[test] +fn smooth_join_and_path_eraser_send_values_their_commands_take() { + let (d, id) = doc_with_rect(); + let mut s = Selection::default(); + s.set([id]); + let p = paint(); + let mut cx = cx(&d, &s, &p); + cx.smart_guides = false; + let (reach_lo, reach_hi) = crate::draw2::REACH_RANGE; + let (tol_lo, tol_hi) = (crate::draw2::SMOOTH_MIN_TOLERANCE, crate::draw2::SMOOTH_MAX_TOLERANCE); + let alt = Mods { alt: true, ..Default::default() }; + for (zoom, fidelity, reach, tol) in [(0.001, 100.0, reach_hi, tol_hi), (100_000.0, 0.05, reach_lo, tol_lo)] { + cx.zoom = zoom; + // The same drag on screen at each zoom. + let pts: Vec<_> = [(50.0, 150.0), (150.0, 150.0), (250.0, 160.0)].iter().map(|&(x, y)| (x / zoom, y / zoom)).collect(); + let sent = |acts: &[Vec]| match acts.last().and_then(|a| a.first()) { + Some(Action::Exec(c, v)) => (c.clone(), v.clone()), + a => panic!("expected a command at {zoom}x, got: {a:?} in {acts:?}"), + }; + let mut smooth = GestureTool::new("smooth"); + smooth.set_option("fidelity", &json!(fidelity)); + let mut pencil = GestureTool::new("pencil"); + pencil.set_option("altSmooth", &json!(true)); + pencil.set_option("smoothFidelity", &json!(fidelity)); + for (what, acts) in [("smooth", drag(&mut smooth, &cx, &pts, Mods::default())), ("pencil", drag_held(&mut pencil, &cx, &pts, alt))] { + let (c, v) = sent(&acts); + assert_eq!(c, "path.smoothRegion", "{what} at {zoom}x"); + assert_eq!((v["radius"].as_f64(), v["fidelity"].as_f64()), (Some(reach), Some(tol)), "{what} at {zoom}x: {v}"); + } + let (c, v) = sent(&drag(&mut GestureTool::new("join"), &cx, &pts, Mods::default())); + assert_eq!((c.as_str(), v["tolerance"].as_f64()), ("path.joinScrub", Some(reach)), "join at {zoom}x: {v}"); + let (c, v) = sent(&drag(&mut GestureTool::new("pathEraser"), &cx, &pts, Mods::default())); + assert_eq!((c.as_str(), v["width"].as_f64()), ("path.eraseSegments", Some(reach)), "path eraser at {zoom}x: {v}"); + } +} + /// The Blob Brush's Fidelity stays in points (#5729 is the Pencil's and the Paintbrush's): its /// stroke, and another tool chosen while it is drawn, send it as set at any zoom. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index 5032690fc6..612bfb775a 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7062,6 +7062,14 @@ VectorCraft's own values. `` `width` must be from 0.001 to 1000 ``. The document and the selection do not change and no undo step is recorded. Left out or null, `width` is 8 pt. The range is VectorCraft's own value. +`path.smoothRegion` (the Smooth tool) refuses a `radius` outside 0.001 to 1000 pt with +`` `radius` must be from 0.001 to 1000 `` and a `fidelity` outside 0.000078125 to about 3195 pt (the Smooth tool's +0.05 to 100 px at the highest and the lowest zoom) with `` `fidelity` must be from 0.000078125 to 3194.8881789137376 pt ``. +`path.joinScrub` (the Join tool) refuses a `tolerance` outside 0.001 to 1000 pt with +`` `tolerance` must be from 0.001 to 1000 ``. The document and the selection do not change and no undo step is +recorded. Left out or null, `radius` is 12 pt, `fidelity` is 2.5 pt and `tolerance` is 12 pt. The tools send these in screen +pixels divided by the zoom, kept within the ranges. The `radius` and `tolerance` ranges are VectorCraft's own values. + These commands refuse a string, a number or another value that is not true or false with `` `closed` must be true or false ``, naming the key; the document does not change and no undo step is recorded: `independent` in `path.close` and `path.setHandle`; `symmetric` and `link` in `path.setHandle`; `patterns` in `path.moveAnchors`; `closed`, `keepSelected` and diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index f8a3dc84a0..c513bfcca8 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1461,6 +1461,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur Eraser Tool Options has Angle and Roundness besides Size, as [Erase paths using the Eraser tool](https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/modify-paths/erase-paths-using-eraser-tool.html) describes: the Eraser's tip is an ellipse Size across, its long axis at Angle and its short axis Roundness percent of the long one, and a drag with a tip that is not round shows the outline of the area it erases (`path.eraseRegion` `angle` and `roundness`). `path.eraseRegion` refuses an Angle outside −180° to 180° and a Roundness outside 1% to 100% with an error and leaves the document unchanged; a key left out or null takes its default (0° and 100%). The help page gives no range for the two options, so the ranges are VectorCraft's own values. `path.split` refuses a `t` outside 0 to 1 in the same way. `path.eraseSegments` (the Path Eraser) refuses a `width` outside 0.001 to 1000 pt with an error and leaves the document unchanged; left out or null, the width is 8 pt. The help page gives the Path Eraser no width option, so the range is VectorCraft's own value. + `path.smoothRegion` (the Smooth tool) refuses a `radius` outside 0.001 to 1000 pt or a `fidelity` outside 0.000078125 to about 3195 pt with an error naming the key, and `path.joinScrub` (the Join tool) refuses a `tolerance` outside 0.001 to 1000 pt the same way; the document does not change; before, a radius or tolerance below 0 was read as 0 and a fidelity was moved into its range. Left out or null, the defaults stay (12 pt, 2.5 pt and 12 pt), and the tools keep what they send within the ranges at any zoom. The radius and tolerance ranges are VectorCraft's own values (engine `smooth_and_join_refuse_a_reach_or_fidelity_outside_its_range`). Eraser Tool Options gives Angle, Roundness and Size each a menu of Fixed, Random, Pressure, Tilt, Bearing and Rotation with a Variation field, as the same page describes: the tip varies by up to the Variation either way, Random once per drag and the others with what the pen reads at each point of the drag, and the tip outline at the pointer follows the pen while it erases. The outline of the area a drag shows takes, at each step, the tip the pen's readings give halfway along it, with a Random value shown as the value itself, and a mouse drag erases at the set values (`path.eraseRegion` `angleMode`, `roundnessMode`, `sizeMode` and their variations). Eraser Tool Options show the Blob Brush's tip preview under the Roundness rows. A drag on the arrowhead turns the Angle, and a drag that starts on a black dot moves it toward the center for a flatter tip or away from it for a rounder one, as the Eraser tool options section of the [help page](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=133) describes; the fields show the new values, and OK keeps them. The drag's mapping and the Angle and Roundness sliders are the Blob Brush preview's, which are VectorCraft's own, with the Eraser's Roundness range of 1% to 100% for the drag and the keys. The preview shows the set Angle and Roundness, not a Random or pen-driven variation of them. Regression tests: `dialogs::tests::the_eraser_tip_preview_sets_the_angle_and_roundness_by_dragging`, `dialogs::freehand::tests::a_roundness_dot_keeps_the_eraser_at_one_percent_or_more`. The outline a Blob Brush or Eraser drag shows is built a bounded amount per frame, so a long stroke does not slow the canvas: each frame takes at most 256 new points of the drag and outlines again only the pieces of up to 32 segments they change, and the parts of a piece's outline inside the rest of the area are removed a limited amount at a time. While work is left, the canvas draws again with the pointer still, the points not outlined yet show as a thin line, and the tip shows at the pointer. When the tip varies with the pen (Size set to Pressure, or an Eraser mode that follows the pen), each step is its own piece and the outline also shows only the edge of the whole area. The release sends the whole stroke as before (`path.blob`, `path.eraseRegion`). From 239a7d61d0fa337f1023e8640fe651d4dbf7dfe4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 00:15:55 -0800 Subject: [PATCH 2/2] Smooth: the dashed band shows the radius its release sends at the lowest zooms The band a smoothing drag shows took the Smooth radius in points without the 1,000 pt bound the release applies, so below 1.2% zoom it drew wider than the region path.smoothRegion smooths. It now uses the same bound. --- crates/tools/src/draw2/gesture.rs | 2 +- crates/tools/src/draw2/gesture/tests.rs | 32 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/crates/tools/src/draw2/gesture.rs b/crates/tools/src/draw2/gesture.rs index ab88d16436..a34c819761 100644 --- a/crates/tools/src/draw2/gesture.rs +++ b/crates/tools/src/draw2/gesture.rs @@ -1920,7 +1920,7 @@ impl Tool for GestureTool { // release smooths. if (self.id == "smooth" || self.smoothing) && has_selected_smooth_path(cx) - && let Some(path) = self.smooth_band(cx.tol(SMOOTH_RADIUS)) + && let Some(path) = self.smooth_band(reach(cx, SMOOTH_RADIUS)) { o.push(Overlay::SharedPath { path, color: FEEDBACK, width: 1.0, dash: Some(0.0) }); } diff --git a/crates/tools/src/draw2/gesture/tests.rs b/crates/tools/src/draw2/gesture/tests.rs index dbbbb53a78..00f0ebc93e 100644 --- a/crates/tools/src/draw2/gesture/tests.rs +++ b/crates/tools/src/draw2/gesture/tests.rs @@ -1641,6 +1641,38 @@ fn smoothing_band_shows_no_seam_where_it_turns_across_a_square_side() { } } +/// Zoomed out far enough that the Smooth tool's radius in points passes the top of +/// [`crate::draw2::REACH_RANGE`], the band a smoothing drag shows has the radius its release sends. +#[test] +fn smoothing_band_at_the_lowest_zoom_has_the_radius_the_release_sends() { + let (d, id) = doc_with_rect(); + let mut s = Selection::default(); + s.set([id]); + let p = paint(); + let mut cx = cx(&d, &s, &p); + cx.smart_guides = false; + cx.zoom = 0.005; + let r = crate::draw2::REACH_RANGE.1; + assert!(cx.tol(SMOOTH_RADIUS) > r, "the radius on screen is past the range at {}x", cx.zoom); + let ends = [Point::new(1000.0, 1000.0), Point::new(5000.0, 1000.0)]; + let mut t = GestureTool::new("smooth"); + t.pointer(&cx, &PointerEvent::new(PointerKind::Down, ends[0].x, ends[0].y)); + for i in 1..=20 { + let q = ends[0].lerp(ends[1], f64::from(i) / 20.0); + t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, q.x, q.y)); + } + let mut frames = 0; + while t.overlays_pending() { + assert!(frames < 10_000, "the band reaches the whole drag"); + bands(&t, &cx); + frames += 1; + } + check_band(&t, &cx, r); + let acts = t.pointer(&cx, &PointerEvent::new(PointerKind::Up, ends[1].x, ends[1].y)); + let Some(Action::Exec(c, v)) = acts.first() else { panic!("expected a command, got {acts:?}") }; + assert_eq!((c.as_str(), v["radius"].as_f64()), ("path.smoothRegion", Some(r)), "{v}"); +} + /// One straight piece of a square's outline along a side, where the band goes on across only part /// of it, shows only the part with nothing across. #[test]