Eraser: Stylus Wheel follows the pen's finger wheel

path.eraseRegion now lists stylusWheel among the Angle, Roundness and Size
variation modes in its error message, params text and docs/mcp.md, and its
points take the wheel seventh, as path.freehand does. The engine test that
refused stylusWheel as a mode now checks that an Eraser value on Stylus
Wheel follows the recorded wheel and stays at the value without one, and
a tools test checks the same for the Eraser's tip outline and the points
its release sends.
This commit is contained in:
dotCooCoo
2026-11-14 22:36:15 -08:00
parent 45670e04bb
commit 708ec144a4
7 changed files with 63 additions and 21 deletions
+1 -1
View File
@@ -92,7 +92,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Eraser",
[],
None,
"{points: [[x,y]…] or [[x,y,pressure]…] or [[x,y,pressure,tiltX,tiltY,rotation]…] (pen pressure 0..1, tilt −90..90°, barrel rotation ° clockwise, as path.freehand), size?: pt (10), angle?: ° (0: the tip's long axis counter-clockwise from level), roundness?: % (100, kept within 1–100), angleMode?, roundnessMode?, sizeMode?: \"fixed\" (default) | \"random\" | \"pressure\" | \"tilt\" | \"bearing\" | \"rotation\" (Eraser Tool Options' variation menus; a varied angle turns either way, clockwise or counter-clockwise), angleVariation?: ° (0–180, default 0, either way: clockwise or counter-clockwise), roundnessVariation?: % (0–100, default 0), sizeVariation?: pt (0 or more, default 0)} erase the stroke of an elliptical tip from paths (selected, or all) → {ids}. The tip is `size` across its long axis, which runs at `angle` counter-clockwise from horizontal; its short axis is `roundness` percent of the long one. A value whose mode is not fixed varies by up to its variation either way: random draws one value for the drag; pressure goes from the value less the variation where the pen presses lightest to the value plus it where it presses hardest (size on pressure as path.blob); tilt from less with the pen lying flat to more with it upright; bearing and rotation from less at −180° to more at 180° of the pen's lean direction or barrel turn. A drag without that pen reading (a mouse) erases at the value itself. An unknown mode, or a variation below 0 or past its range, is an error and erases nothing",
"{points: [[x,y]…] or [[x,y,pressure]…] or [[x,y,pressure,tiltX,tiltY,rotation]…] or [[x,y,pressure,tiltX,tiltY,rotation,wheel]…] (pen pressure 0..1, tilt −90..90°, barrel rotation ° clockwise, finger wheel 0..1, as path.freehand), size?: pt (10), angle?: ° (0: the tip's long axis counter-clockwise from level), roundness?: % (100, kept within 1–100), angleMode?, roundnessMode?, sizeMode?: \"fixed\" (default) | \"random\" | \"pressure\" | \"tilt\" | \"bearing\" | \"rotation\" | \"stylusWheel\" (Eraser Tool Options' variation menus; a varied angle turns either way, clockwise or counter-clockwise), angleVariation?: ° (0–180, default 0, either way: clockwise or counter-clockwise), roundnessVariation?: % (0–100, default 0), sizeVariation?: pt (0 or more, default 0)} erase the stroke of an elliptical tip from paths (selected, or all) → {ids}. The tip is `size` across its long axis, which runs at `angle` counter-clockwise from horizontal; its short axis is `roundness` percent of the long one. A value whose mode is not fixed varies by up to its variation either way: random draws one value for the drag; pressure goes from the value less the variation where the pen presses lightest to the value plus it where it presses hardest (size on pressure as path.blob); tilt from less with the pen lying flat to more with it upright; bearing and rotation from less at −180° to more at 180° of the pen's lean direction or barrel turn; stylusWheel from less at one end of an airbrush pen's finger wheel travel to more at the other. A drag without that pen reading (a mouse) erases at the value itself. An unknown mode, or a variation below 0 or past its range, is an error and erases nothing",
has_doc,
erase_region
),
+1 -1
View File
@@ -327,7 +327,7 @@ pub(super) fn erase_region(s: &mut Session, p: &Value) -> Result<Value> {
/// The variation modes `path.eraseRegion` takes for each of `angleMode`, `roundnessMode` and
/// `sizeMode`.
const ERASER_MODES: &str = "\"fixed\", \"random\", \"pressure\", \"tilt\", \"bearing\" or \"rotation\"";
const ERASER_MODES: &str = "\"fixed\", \"random\", \"pressure\", \"tilt\", \"bearing\", \"rotation\" or \"stylusWheel\"";
/// Eraser Tool Options' Angle, Roundness and Size variations: for each of angle (`angleMode` with
/// `angleVariation` in degrees, at most 180), roundness (`roundnessMode` with `roundnessVariation`
+9 -5
View File
@@ -612,14 +612,14 @@ fn eraser_size_follows_the_pen_pressure() {
assert!(err.to_string().contains("sizeMode"), "{err}");
}
/// Eraser Tool Options' Angle, Roundness and Size variation menus: a value on Rotation, Bearing,
/// Tilt or Pressure takes what the pen read along the drag, Random stays within its Variation, a
/// Eraser Tool Options' Angle, Roundness and Size variation menus: a value on Stylus Wheel, Rotation,
/// Bearing, Tilt or Pressure takes what the pen read along the drag, Random stays within its Variation, a
/// drag without the reading erases at the value itself, an open path is cut where the varied tip
/// covers it, and an unknown mode or a variation out of its range is refused with nothing erased.
#[test]
fn the_eraser_tip_varies_with_its_modes() {
// Which of `probes` a level drag through the middle of a 400 by 200 rectangle erases, each of
// its points `[x, 100]` followed by `pen` ([pressure, tiltX, tiltY, rotation]).
// its points `[x, 100]` followed by `pen` ([pressure, tiltX, tiltY, rotation, wheel]).
let erased = |tip: serde_json::Value, pen: serde_json::Value, probes: &[(f64, f64)]| -> Vec<bool> {
let mut s = session();
rect(&mut s, 0.0, 0.0, 400.0, 200.0);
@@ -646,6 +646,10 @@ fn the_eraser_tip_varies_with_its_modes() {
// The barrel turned half way round reads the most, which turns the tip upright.
assert_eq!(erased(on_rotation.clone(), json!([none, none, none, 180]), &probes), [true, true], "Rotation");
assert_eq!(erased(on_rotation.clone(), json!([]), &probes), [true, false], "Rotation without a reading");
// The finger wheel at the far end of its travel reads the most; without a wheel the tip lies level.
let on_wheel = with(&level, json!({"angleMode": "stylusWheel", "angleVariation": 90}));
assert_eq!(erased(on_wheel.clone(), json!([none, none, none, none, 1.0]), &probes), [true, true], "Stylus Wheel");
assert_eq!(erased(on_wheel, json!([none, none, none, none, none]), &probes), [true, false], "Stylus Wheel without a reading");
// Leaning to the left (a bearing of 180°) reads the most too.
let on_bearing = with(&level, json!({"angleMode": "bearing", "angleVariation": 90}));
assert_eq!(erased(on_bearing.clone(), json!([none, -45, 0, none]), &probes), [true, true], "Bearing");
@@ -692,11 +696,11 @@ fn the_eraser_tip_varies_with_its_modes() {
let id = rect(&mut s, 0.0, 0.0, 100.0, 100.0);
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
let stroke = json!({"points": [[-10, 50], [110, 50]]});
let modes = "\"fixed\", \"random\", \"pressure\", \"tilt\", \"bearing\" or \"rotation\"";
let modes = "\"fixed\", \"random\", \"pressure\", \"tilt\", \"bearing\", \"rotation\" or \"stylusWheel\"";
for (extra, want) in [
(json!({"angleMode": "wheel"}), format!("angleMode is one of {modes}, not `wheel`")),
(json!({"roundnessMode": 3}), format!("roundnessMode is one of {modes}, not 3")),
(json!({"sizeMode": "stylusWheel"}), format!("sizeMode is one of {modes}, not `stylusWheel`")),
(json!({"sizeMode": "Pressure"}), format!("sizeMode is one of {modes}, not `Pressure`")),
(json!({"angleVariation": 181}), "angleVariation must be at most 180".to_string()),
(json!({"roundnessVariation": 101}), "roundnessVariation must be at most 100".to_string()),
(json!({"roundnessVariation": -1}), "roundnessVariation must be 0 or more".to_string()),
+6 -6
View File
@@ -102,12 +102,12 @@ pub(crate) fn pen_bearing(q: PenPose) -> Option<f64> {
(from_upright >= 1.0).then(|| (-y).atan2(x).to_degrees())
}
/// The 0..1 that each of the Eraser's variation modes Pressure, Tilt, Bearing and Rotation reads
/// from a pen at `pressure` (0..1) held as `pose`, leaning toward `bearing` (degrees, from
/// [`pen_bearing`]): 0 gives the value less its variation and 1 the value plus it, as
/// `path.eraseRegion` reads a stroke's points. Tilt reads 1 upright and 0 lying flat; Bearing and
/// Rotation read ½ plus the angle over 360°, the rotation turned counter-clockwise. What the pen
/// does not give reads ½, the value itself.
/// The 0..1 that each of the Eraser's variation modes Pressure, Tilt, Bearing, Rotation and Stylus
/// Wheel reads, in that order, from a pen at `pressure` (0..1) held as `pose`, leaning toward
/// `bearing` (degrees, from [`pen_bearing`]): 0 gives the value less its variation and 1 the value
/// plus it, as `path.eraseRegion` reads a stroke's points. Tilt reads 1 upright and 0 lying flat;
/// Bearing and Rotation read ½ plus the angle over 360°, the rotation turned counter-clockwise;
/// Stylus Wheel reads the pen's wheel (0..1). What the pen does not give reads ½, the value itself.
pub(crate) fn pen_controls(pressure: f64, pose: Option<PenPose>, bearing: Option<f64>) -> [f64; 5] {
let tilt = pose.and_then(|q| q.tilt).map_or(0.5, |t| 1.0 - pen_lean(t).1 / 90.0);
let rotation = pose.and_then(|q| q.rotation).map_or(0.5, |r| 0.5 + vectorcraft_geom::normalize_deg(-f64::from(r)) / 360.0);
+1 -1
View File
@@ -1136,7 +1136,7 @@ impl GestureTool {
/// The Eraser's angle, roundness and size where its tip outline shows: while it erases, each
/// value on a mode that follows the pen goes from the value less its Variation to the value
/// plus it as the pen reads now (the pressure once the pen has pressed less than fully, the
/// tilt and rotation of the last point, and the bearing of the last point the pen leaned 1° or
/// tilt, rotation and wheel of the last point, and the bearing of the last point the pen leaned 1° or
/// more at), as `path.eraseRegion` reads the stroke; before a press, and for Random, Fixed and a
/// pen that gives no reading, the values themselves. The Blob Brush's are its own values.
fn tip_now(&self) -> [f64; 3] {
+37
View File
@@ -2875,6 +2875,43 @@ fn the_eraser_tip_follows_its_variation_modes() {
assert_eq!(b.options()["sizeMode"], json!("pressure"));
}
/// An Eraser value on Stylus Wheel follows the wheel the pen recorded, in the tip outline while it
/// erases and in the points the release sends; a pen that gives no wheel reads half way, the value
/// itself.
#[test]
fn the_eraser_tip_follows_the_stylus_wheel() {
let (d, _) = doc_with_rect();
let s = Selection::default();
let p = paint();
let cx = cx(&d, &s, &p);
let tip = |t: &GestureTool| match &t.overlays(&cx)[..] {
[.., Overlay::Path { path, color: [0, 0, 0], width: 1.0, .. }] => vectorcraft_geom::Shape::bounding_box(path),
o => panic!("{o:?}"),
};
let near = |b: vectorcraft_geom::Rect, want: (f64, f64, f64, f64)| {
assert!([b.x0 - want.0, b.y0 - want.1, b.x1 - want.2, b.y1 - want.3].iter().all(|e| e.abs() < 0.01), "{b:?} vs {want:?}");
};
let mut t = GestureTool::new("eraser");
for (k, v) in [("size", json!(20)), ("roundness", json!(25)), ("angleMode", json!("stylusWheel")), ("angleVariation", json!(90))] {
t.set_option(k, &v);
}
assert_eq!(t.options()["angleMode"], json!("stylusWheel"));
// The wheel at the far end of its travel turns the 20 by 5 pt tip upright.
let wheel = |w: Option<f32>| Some(PenPose { tilt: None, rotation: None, wheel: w });
t.pointer(&cx, &PointerEvent { pen: wheel(Some(1.0)), ..PointerEvent::new(PointerKind::Down, 100.0, 50.0) });
t.pointer(&cx, &PointerEvent { pen: wheel(Some(1.0)), ..PointerEvent::new(PointerKind::Drag, 200.0, 50.0) });
near(tip(&t), (197.5, 40.0, 202.5, 60.0));
let acts = t.pointer(&cx, &PointerEvent { pen: wheel(Some(1.0)), ..PointerEvent::new(PointerKind::Up, 200.0, 50.0) });
let Some(Action::Exec(c, v)) = acts.first() else { panic!("{acts:?}") };
assert_eq!((c.as_str(), &v["angleMode"]), ("path.eraseRegion", &json!("stylusWheel")));
assert_eq!(v["points"], json!([[100.0, 50.0, null, null, null, null, 1.0], [200.0, 50.0, null, null, null, null, 1.0]]));
// A pen without a wheel keeps the tip lying level.
t.pointer(&cx, &PointerEvent { pen: wheel(None), ..PointerEvent::new(PointerKind::Down, 100.0, 50.0) });
t.pointer(&cx, &PointerEvent { pen: wheel(None), ..PointerEvent::new(PointerKind::Drag, 200.0, 50.0) });
near(tip(&t), (190.0, 47.5, 210.0, 52.5));
t.pointer(&cx, &PointerEvent { pen: wheel(None), ..PointerEvent::new(PointerKind::Up, 200.0, 50.0) });
}
/// The Eraser's tip outline follows a pen turned in place, which adds no stroke point, and the
/// release erases with that reading; and its size passes 1296 pt as `path.eraseRegion` sweeps it.
#[test]
+8 -7
View File
@@ -5589,13 +5589,14 @@ Eraser Tool Options set them ([Erase paths using the Eraser
tool](https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/modify-paths/erase-paths-using-eraser-tool.html)):
`angleMode` with `angleVariation` (degrees, 0 to 180), `roundnessMode` with `roundnessVariation` (percent, 0 to 100)
and `sizeMode` with `sizeVariation` (points, 0 or more), each `"fixed"` (the default), `"random"`, `"pressure"`,
`"tilt"`, `"bearing"` or `"rotation"`. A value that varies takes up to its variation either way. Random draws one
value for the drag. Pressure goes from the value less the variation where the pen presses lightest to the value plus
it where the pen presses hardest. Tilt goes from less with the pen lying flat to more with it upright. Bearing and
Rotation go from less at −180° to more at 180° of the way the pen leans or its barrel turns. The tip at each point of
the drag takes what the pen read there (the points' pressure, tilt and rotation, as `path.freehand` takes them); a
drag without that reading, such as a mouse drag, erases at the value itself. One Random value per drag, which way
Tilt, Bearing and Rotation run, and the value itself without a reading are VectorCraft's own rules.
`"tilt"`, `"bearing"`, `"rotation"` or `"stylusWheel"`. A value that varies takes up to its variation either way.
Random draws one value for the drag. Pressure goes from the value less the variation where the pen presses lightest to
the value plus it where the pen presses hardest. Tilt goes from less with the pen lying flat to more with it upright.
Bearing and Rotation go from less at −180° to more at 180° of the way the pen leans or its barrel turns. Stylus Wheel
goes from less at 0 to more at 1 of an airbrush pen's finger wheel. The tip at each point of the drag takes what the
pen read there (the points' pressure, tilt, rotation and wheel, as `path.freehand` takes them); a drag without that
reading, such as a mouse drag, erases at the value itself. One Random value per drag, which way Tilt, Bearing,
Rotation and Stylus Wheel run, and the value itself without a reading are VectorCraft's own rules.
The command refuses another mode, and a variation below 0 or past its range, and erases nothing. In the desktop app
the Eraser's tip outline at the pointer takes the angle, roundness and size the pen gives while it erases.
`tool.setOption {tool: "eraser"}` takes the same keys.