From 70df1ff5b3347b56427e1cf618f690bfcbff9413 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 11:08:30 -0800 Subject: [PATCH] Eraser: Shift keeps the drag on a horizontal, vertical or diagonal line With Shift held, an Eraser drag stays on the line from the press point at the 45 degree step from the Constrain Angle that the pointer lies nearest to. The step is taken once the pointer is 3 screen pixels from the press and holds until Shift is released; the tip outline follows the line. Released, the drag goes on freehand from the last point on the line, and Shift again takes a new step from the press point. --- crates/tools/src/draw2/gesture.rs | 41 ++++++++++++--- crates/tools/src/draw2/gesture/tests.rs | 70 +++++++++++++++++++++++++ docs/ui-parity.md | 1 + 3 files changed, 105 insertions(+), 7 deletions(-) diff --git a/crates/tools/src/draw2/gesture.rs b/crates/tools/src/draw2/gesture.rs index a1f1785923..a497c8e9ea 100644 --- a/crates/tools/src/draw2/gesture.rs +++ b/crates/tools/src/draw2/gesture.rs @@ -18,7 +18,8 @@ //! gives there. The other tools //! collect the drag polyline (shown as an overlay) and run one command on release. With Shift //! held, the Blob Brush's points stay on the horizontal or -//! vertical line through the press point. Alt held at the press, or before the Blob Brush's drag +//! vertical line through the press point, and the Eraser's on the line from the press point at the +//! nearest 45° step from the Constrain Angle. Alt held at the press, or before the Blob Brush's drag //! has moved, switches the Blob Brush to the Smooth tool: the drag smooths the selected paths. //! Alt held at a Paintbrush press with a selected path also smooths; Alt pressed after its stroke //! begins closes the path on release. @@ -78,6 +79,9 @@ const BAND_WORK_PER_CALL: usize = 20_000; const PREVIEW_FIDELITY_PX: f64 = 0.5; /// The Smooth tool's Fidelity (screen pixels) until Smooth Tool Options sets another. const SMOOTH_FIDELITY: f64 = 2.5; +/// How far the pointer goes from the press point, in screen pixels, before a Shift-drag of the +/// Eraser takes the 45° step it lies nearest to. +const ERASER_SHIFT_PX: f64 = 3.0; /// The `fidelity` (points) the Pencil and the Paintbrush send `path.freehand` for `px` screen pixels /// at the current zoom, within the range the command takes @@ -169,7 +173,8 @@ pub struct GestureTool { /// The straight line is not constrained to 45° steps: the Pencil's Alt line, whose end snaps to /// Smart Guides as a stroke's end does, or the Knife's line while Shift is up. unconstrained: bool, - /// Axis selected during the current uninterrupted Shift interval, in degrees. + /// Axis selected during the current uninterrupted Shift interval, in degrees: the Blob Brush's + /// horizontal or vertical, or the Eraser's 45° step. shift_line: Option, /// "Merge only with selection": a Blob Brush stroke merges only with selected paths. pub merge_only_selection: bool, @@ -989,9 +994,10 @@ impl GestureTool { } /// Constrain a straight Pencil line from the Constrain Angle, a straight Knife cut from the - /// canvas axes, or the current Blob Brush sample. Blob Brush chooses an - /// axis once per uninterrupted Shift interval; samples already drawn never move. - /// A smoothing drag follows the pointer without a Shift constraint. + /// canvas axes, or the current Blob Brush or Eraser sample. The Blob Brush chooses an axis, + /// and the Eraser a 45° step from the Constrain Angle, once per uninterrupted Shift interval; + /// samples already drawn never move. A smoothing drag follows the pointer without a Shift + /// constraint. fn constrained(&mut self, cx: &ToolContext, p: Point, m: Mods) -> Point { if self.straight && self.unconstrained { return p; @@ -1002,10 +1008,21 @@ impl GestureTool { let origin = if self.id == "knife" { 0.0 } else { cx.constrain_angle }; return start + vectorcraft_geom::constrain_angle_from(p - start, 45.0, origin); } - let Some(&start) = self.points.first().filter(|_| self.id == "blobBrush" && m.shift && !self.smoothing) else { + let shifts = (self.id == "blobBrush" && !self.smoothing) || self.id == "eraser"; + let Some(&start) = self.points.first().filter(|_| shifts && m.shift) else { self.shift_line = None; return p; }; + if self.id == "eraser" && self.shift_line.is_none() { + // The step is taken once the pointer is clear of the press point, in screen pixels at + // any zoom; until then the stroke waits at its last sample. + let v = p - start; + if v.hypot() * cx.zoom < ERASER_SHIFT_PX { + return self.points.last().copied().unwrap_or(start); + } + let c = vectorcraft_geom::constrain_angle_from(v, 45.0, cx.constrain_angle); + self.shift_line = Some(-c.y.atan2(c.x).to_degrees()); + } if self.shift_line.is_none() { // Raw press-to-pointer displacement in logical screen pixels along the constraint // axes. Zoom changes the document distance, not the activation tolerance. @@ -1025,6 +1042,16 @@ impl GestureTool { start + vectorcraft_geom::constrain_angle_from(p - start, 180.0, self.shift_line.unwrap_or(cx.constrain_angle)) } + /// [`Self::constrained`] for a drag to `p`: the Eraser's tip outline shows where its stroke + /// is, on the line of a Shift-drag. + fn constrained_drag(&mut self, cx: &ToolContext, p: Point, m: Mods) -> Point { + let p = self.constrained(cx, p, m); + if self.id == "eraser" && self.tip_at.is_some() { + self.tip_at = Some(p); + } + p + } + /// The Blob Brush's or the Eraser's tip at the pointer, before and while painting: its outline /// `size` across at its angle and roundness (the Eraser's as the pen varies them while it /// erases, [`Self::tip_now`]), at the zoom, black on a white halo so it reads on @@ -1455,7 +1482,7 @@ impl Tool for GestureTool { } self.knife_shift(ev.mods); self.moved |= self.points.first().is_some_and(|start| p.distance(*start) > vectorcraft_geom::EPS); - let p = self.constrained(cx, p, ev.mods); + let p = self.constrained_drag(cx, p, ev.mods); let mut end = p; if self.grid_snaps(cx) && !self.smoothing && !self.straight { // Where the stroke would end on the grid or a pixel: taken on release. diff --git a/crates/tools/src/draw2/gesture/tests.rs b/crates/tools/src/draw2/gesture/tests.rs index 9dfbdba2de..bf182d8d7b 100644 --- a/crates/tools/src/draw2/gesture/tests.rs +++ b/crates/tools/src/draw2/gesture/tests.rs @@ -2032,6 +2032,76 @@ fn eraser_and_knife_exec_on_release() { assert!(matches!(&a[0], Action::Exec(c, v) if c == "path.knife" && v["points"].as_array().unwrap().len() == 3)); } +/// With Shift held the Eraser's stroke stays on the line from the press point at the 45° step, +/// from the Constrain Angle, that the pointer lies nearest to once it is 3 screen pixels away: +/// horizontal, vertical or diagonal. The step holds until Shift is released, the tip outline shows +/// on the line, and the drag goes on freehand from the last sample on the line without moving it. +#[test] +fn eraser_shift_keeps_the_stroke_on_a_45_degree_line() { + let (d, _) = doc_with_rect(); + let s = Selection::default(); + let p = paint(); + let mut cx = cx(&d, &s, &p); + let shift = Mods { shift: true, ..Default::default() }; + let mut t = GestureTool::new("eraser"); + let ev = |k, x, y, m| PointerEvent::new(k, x, y).with_mods(m); + let on_line = |q: Point, deg: f64| (q.x * deg.to_radians().sin() + q.y * deg.to_radians().cos()).abs() < 1e-9; + for zoom in [0.5, 1.0, 4.0] { + cx.zoom = zoom; + t.pointer(&cx, &ev(PointerKind::Down, 0.0, 0.0, shift)); + // Within 3 screen pixels of the press the stroke waits there, and so does its tip. + t.pointer(&cx, &ev(PointerKind::Drag, 2.0 / zoom, 2.0 / zoom, shift)); + assert_eq!(t.points, vec![Point::ZERO]); + assert_eq!(t.tip_at, Some(Point::ZERO)); + // 22° below the horizontal: the horizontal step, at the pointer's distance. + t.pointer(&cx, &ev(PointerKind::Drag, 10.0 / zoom, 4.0 / zoom, shift)); + let first = t.points[1]; + assert!((first.x - 116f64.sqrt() / zoom).abs() < 1e-9 && first.y.abs() < 1e-9, "{first:?}"); + assert_eq!(t.tip_at, Some(first)); + // The step holds while Shift stays down. + t.pointer(&cx, &ev(PointerKind::Drag, 3.0 / zoom, 20.0 / zoom, shift)); + assert!(t.points.iter().all(|q| q.y.abs() < 1e-9), "{:?}", t.points); + // Released, the drag goes on freehand from there. + t.pointer(&cx, &ev(PointerKind::Drag, 30.0 / zoom, 25.0 / zoom, Mods::default())); + assert_eq!(t.points.last(), Some(&Point::new(30.0 / zoom, 25.0 / zoom))); + assert_eq!(t.tip_at, Some(Point::new(30.0 / zoom, 25.0 / zoom))); + assert_eq!(t.points[1], first); + // Shift again takes a new step from the press point: the diagonal down and to the right. + t.pointer(&cx, &ev(PointerKind::Drag, 40.0 / zoom, 36.0 / zoom, shift)); + let q = *t.points.last().unwrap(); + assert!((q.x - q.y).abs() < 1e-9 && q.x > 0.0, "{q:?}"); + let acts = t.pointer(&cx, &ev(PointerKind::Up, 50.0 / zoom, 44.0 / zoom, shift)); + let Some(Action::Exec(c, v)) = acts.first() else { panic!("{acts:?}") }; + assert_eq!(c, "path.eraseRegion"); + let last = v["points"].as_array().unwrap().last().unwrap().clone(); + let (x, y) = (last[0].as_f64().unwrap(), last[1].as_f64().unwrap()); + assert!((x - y).abs() < 1e-9 && x > 0.0, "{last}"); + } + // The steps go from the Constrain Angle, counter-clockwise on the page: at 30°, a drag at 70° + // takes the 75° step and one at 105° the 120° step, either way from the press. + cx.zoom = 1.0; + cx.constrain_angle = 30.0; + for (drag, step) in [(70.0_f64, 75.0), (105.0, 120.0), (-150.0, -150.0), (40.0, 30.0)] { + t.pointer(&cx, &ev(PointerKind::Down, 100.0, 100.0, shift)); + let r = drag.to_radians(); + t.pointer(&cx, &ev(PointerKind::Drag, 100.0 + 20.0 * r.cos(), 100.0 - 20.0 * r.sin(), shift)); + let q = t.points[1] - Point::new(100.0, 100.0); + assert!(on_line(Point::new(q.x, q.y), step), "drag {drag}: {q:?}"); + assert!((q.hypot() - 20.0).abs() < 1e-9); + // Along the step's line both ways: back past the press stays on it. + let r = (step + 180.0).to_radians(); + t.pointer(&cx, &ev(PointerKind::Drag, 100.0 + 5.0 * r.cos() + 3.0, 100.0 - 5.0 * r.sin(), shift)); + let q = *t.points.last().unwrap() - Point::new(100.0, 100.0); + assert!(on_line(Point::new(q.x, q.y), step), "drag {drag} back: {q:?}"); + t.pointer(&cx, &ev(PointerKind::Up, 100.0, 100.0, Mods::default())); + } + // A Shift-drag released within 3 pixels of the press erases at the press. + cx.constrain_angle = 0.0; + t.pointer(&cx, &ev(PointerKind::Down, 20.0, 20.0, shift)); + let acts = t.pointer(&cx, &ev(PointerKind::Up, 22.0, 21.0, shift)); + assert!(matches!(&acts[0], Action::Exec(c, v) if c == "path.eraseRegion" && v["points"] == json!([[20.0, 20.0]])), "{acts:?}"); +} + /// The points of the Knife's release command. fn knife_points(acts: &[Action]) -> Vec<(f64, f64)> { let Some(Action::Exec(c, v)) = acts.first() else { panic!("{acts:?}") }; diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 071c8d4719..30f668bed2 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -343,6 +343,7 @@ tools, never checked side by side) isn't captured row by row. | View › Hide Artboards (Ctrl/Cmd+Shift+H) hides the artboards' edges, bleeds, marks and names and shows the whole canvas as paper (white, or Simulate Colored Paper's colour); the Artboard tool still shows them | done | #4038, `canvas::tests::hidden_artboards_leave_a_paper_canvas_without_edges` | | Artboard Options › Display: Show Video Safe Areas and Video Ruler Pixel Aspect Ratio ([public source](https://helpx.adobe.com/illustrator/desktop/create-manage-artboards/organize-manage-artboards/set-video-display-options-for-artboards.html)) | done | #2849; per artboard (`artboard.setProps`/`artboard.new` `showVideoSafeAreas`, `videoRulerPixelAspectRatio` 0.1–10, default 1; one undo step; native format). The page gives no safe-area numbers: our choice is [EBU R 95](https://tech.ebu.ch/docs/r/r095.pdf)'s, the action-safe area 3.5% and the title-safe area 5% in from each edge, outlined 1 point wide on the canvas and turned with the view; exports and print leave them out. Tests `an_artboard_shows_its_video_safe_areas`, `artboard_options_show_video_display_options`, `artboard_video_display_options_*` | | Shape tools: Shift constrains, Alt from centre, Space moves while dragging, arrows change sides/points/rows | done | | +| Eraser: Shift-drag erases along a horizontal, vertical or diagonal line ([public source](https://help.adobe.com/archive/en_US/illustrator/cs3/illustrator_cs3_help.pdf#page=67)) | done | the line runs from the press point at the 45° step from the Constrain Angle nearest the pointer, taken once the pointer is 3 screen pixels from the press and kept until Shift is released; the tip outline follows the line; released, the drag goes on freehand from the last point on the line, and Shift again takes a new step from the press point (VectorCraft's own rules); `eraser_shift_keeps_the_stroke_on_a_45_degree_line` in `crates/tools/src/draw2/gesture/tests.rs` | | Polygon/Star exact-size placement remembers the chosen sides/points for later drags and dialog openings; Cancel preserves the previous count | done | Session tool options; existing dialog-opening gestures retained; regression in `toolbar.rs` | | Tool double-click opens its options | done | | | Per-platform mapping (Cmd ↔ Ctrl, Option ↔ Alt) | done | |