mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 03:08:00 +00:00
Path Eraser: path.eraseSegments refuses a width outside 0.001 to 1000 pt
path.eraseSegments checked only that `width` was a positive number, so a width such as 1e300 erased every selected path and a width such as 1e-300 sampled the path too coarsely to find the band. It now refuses a width outside 0.001 to 1000 pt with "`width` must be from 0.001 to 1000" before reading the document; nothing changes and no undo step is recorded. Left out or null, the width is still 8 pt. The range is VectorCraft's own: it holds every width the Path Eraser tool sends across the view zoom and UI Scaling limits, and its top matches the Eraser's largest Size.
This commit is contained in:
@@ -101,7 +101,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Path Eraser",
|
||||
[],
|
||||
None,
|
||||
"{points: [[x,y]…] (pen values after x and y are checked as path.freehand checks them and do not change what is erased), width?: pt (8)} erase the parts of selected paths under the drag → {ids}",
|
||||
"{points: [[x,y]…] (pen values after x and y are checked as path.freehand checks them and do not change what is erased), width?: pt (8; from 0.001 to 1000)} erase the parts of selected paths under the drag → {ids}. A width outside 0.001 to 1000 is refused with an error, and nothing changes",
|
||||
has_selection,
|
||||
erase_segments
|
||||
),
|
||||
|
||||
@@ -518,13 +518,13 @@ fn apply_plan(s: &mut Session, label: &str, plan: Vec<(NodeId, Vec<PathData>)>)
|
||||
Ok(ids_json(&ids))
|
||||
}
|
||||
|
||||
/// The Path Eraser's band width, in points (VectorCraft's own range).
|
||||
const PATH_ERASER_WIDTHS: (f64, f64) = (0.001, 1000.0);
|
||||
|
||||
pub(super) fn erase_segments(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const C: &str = "path.eraseSegments";
|
||||
let pts = points_param(p, "points", C)?;
|
||||
let w = number_or(p, "width", 8.0, C)?;
|
||||
if !(w.is_finite() && w > 0.0) {
|
||||
return Err(bad(C, "width must be positive"));
|
||||
}
|
||||
let w = ranged(p, "width", 8.0, PATH_ERASER_WIDTHS, C)?;
|
||||
let st = s.doc()?;
|
||||
let mut plan = vec![];
|
||||
for id in target_paths(&st.doc, &st.selection, poly_bounds(&pts, w)) {
|
||||
|
||||
@@ -3059,6 +3059,30 @@ fn blob_and_eraser_size_and_variation_outside_their_ranges_are_refused() {
|
||||
}
|
||||
}
|
||||
|
||||
/// `path.eraseSegments` refuses a `width` outside 0.001 to 1000 pt, and nothing changes. The ends of
|
||||
/// the range and null still erase.
|
||||
#[test]
|
||||
fn path_eraser_width_outside_its_range_is_refused() {
|
||||
let mut s = session();
|
||||
let id = rect(&mut s, 100.0, 100.0, 100.0, 100.0);
|
||||
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
|
||||
let drag = json!({"points": [[150, 90], [150, 110]]});
|
||||
for x in [json!(0), json!(-1), json!(0.0009), json!(1e-300), json!(1000.01), json!(1e300)] {
|
||||
let sel = s.doc().unwrap().selection.clone();
|
||||
refuses_with(&mut s, "path.eraseSegments", &with(&drag, json!({"width": x})), "`width` must be from 0.001 to 1000");
|
||||
assert_eq!(s.doc().unwrap().selection, sel, "width {x} changed the selection");
|
||||
}
|
||||
for x in [json!(0.001), json!(1000), json!(null)] {
|
||||
let before = s.doc().unwrap().doc.clone();
|
||||
let undo = undo_steps(&s);
|
||||
s.execute("path.eraseSegments", &with(&drag, json!({"width": x}))).unwrap_or_else(|e| panic!("width {x}: {e}"));
|
||||
assert!(s.doc().unwrap().doc != before, "width {x} erased nothing");
|
||||
assert_eq!(undo_steps(&s), undo + 1, "width {x}");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// 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.
|
||||
|
||||
@@ -2851,9 +2851,9 @@ fn three_d_refusals_are_translated_in_every_complete_catalog() {
|
||||
assert!(missing.is_empty(), "{} 3D messages have no @msg row:\n{}", missing.len(), missing.join("\n"));
|
||||
}
|
||||
|
||||
/// The Eraser's range refusals (`path.eraseRegion` `angle` and `roundness`) and the Scissors' (`path.split`
|
||||
/// `t`) show in every complete-message language with the key and the range numbers as given; the
|
||||
/// error the command returns stays English.
|
||||
/// The Eraser's range refusals (`path.eraseRegion` `angle` and `roundness`), the Path Eraser's
|
||||
/// (`path.eraseSegments` `width`) and the Scissors' (`path.split` `t`) show in every complete-message
|
||||
/// language with the key and the range numbers as given; the error the command returns stays English.
|
||||
#[test]
|
||||
fn eraser_and_scissors_range_refusals_translate_with_their_values() {
|
||||
use serde_json::json;
|
||||
@@ -2863,6 +2863,7 @@ fn eraser_and_scissors_range_refusals_translate_with_their_values() {
|
||||
let refusals = [
|
||||
("path.eraseRegion", json!({"points": [[10, 10], [60, 10]], "angle": 200}), "`angle`", ["-180", "180"]),
|
||||
("path.eraseRegion", json!({"points": [[10, 10], [60, 10]], "roundness": 0}), "`roundness`", ["1", "100"]),
|
||||
("path.eraseSegments", json!({"points": [[30, 0], [30, 70]], "width": 2000}), "`width`", ["0.001", "1000"]),
|
||||
("path.split", json!({"id": id, "segment": 0, "t": 1.5}), "`t`", ["0", "1"]),
|
||||
];
|
||||
for (cmd, p, key, numbers) in &refusals {
|
||||
|
||||
@@ -5959,6 +5959,10 @@ with `` `t` must be from 0 to 1 ``, with `segment` or with `anchor`. The documen
|
||||
recorded. Left out or null, `angle` is 0° and `roundness` is 100%; left out, `t` is 0.5. The Eraser's ranges are
|
||||
VectorCraft's own values.
|
||||
|
||||
`path.eraseSegments` (the Path Eraser) refuses a `width` outside 0.001 to 1000 pt with
|
||||
`` `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.
|
||||
|
||||
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`; `patterns` in `path.moveAnchors`; `closed`, `keepSelected` and
|
||||
|
||||
@@ -1204,6 +1204,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
With Smart Guides on, a straight Knife cut snaps to anchor points and paths: [Cut objects using the Knife and Scissors tools](https://helpx.adobe.com/illustrator/desktop/manage-objects/edit-objects/cut-objects.html) describes the Knife snapping to anchor points and paths while Smart Guides are on. Its ends snap as the ends of the Pencil's straight line do, to anchor points and path segments of art that is shown: the press, and the release of an Alt-drag. Shift+Alt steps 45° from the snapped press, and its release stays on that step. With Smart Guides off, or with Snap to Pixel or Snap to Grid on, the cut is not snapped. The dashed line and `path.knife` use the snapped points.
|
||||
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.
|
||||
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).
|
||||
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`).
|
||||
The settled part of that outline is kept in paths of up to 64 pieces each. A path is shared from one frame to the next until a piece in it changes, and the canvas keeps the triangles it drew the path with while the view stays the same, so a frame does not copy, flatten or tessellate a settled path again; a pan, zoom or rotation draws each one once more. This is VectorCraft's own rule. The line that a drag of more than 64 segments shows with a round Eraser tip, the Knife, the Path Eraser or the Pencil with Live preview off is kept the same way, in pieces of 64 segments: a frame builds again only the last piece, and the Knife's dashes run on from one piece to the next. With the Eraser's Size set to a mode that follows the pen, each step of such a drag is kept as its own path and a frame builds only a new step. A smoothing drag's band is kept until it changes. The canvas still copies the kept triangles of every piece into each frame.
|
||||
|
||||
Reference in New Issue
Block a user