Reject zero distance in JSON offset command (#2190)

Found while testing crates/engine/src/cmd/modify.rs:791 (run_offset)

Co-authored-by: Claude Haiku 5.5 <noreply@anthropic.com>
Co-authored-by: Brandon Thomas <echelon@gmail.com>
This commit is contained in:
NetterSilver
2026-10-29 21:31:09 -04:00
committed by GitHub
co-authored by Claude Haiku 5.5 Brandon Thomas
parent 303bc97f9a
commit 3243271d4e
2 changed files with 12 additions and 0 deletions
+3
View File
@@ -197,6 +197,9 @@ fn join_point(a: &Segment, b: &Segment) -> Option<Vec2> {
pub(super) fn run_offset(s: &mut Session, p: &Value) -> Result<Value> {
let h = targets(s, p)?.first().copied().ok_or_else(|| bad("offset", "`handle` is required"))?;
let dist = f64_req("offset", p, "distance")?;
if dist == 0.0 {
return Err(bad("offset", "Requires a positive distance."));
}
let side = point_req("offset", p, "side")?;
let e = s.doc()?.entity(h).map(|e| (**e).clone()).ok_or_else(|| bad("offset", "no such object"))?;
let k = offset_kind(&e.kind, dist.abs(), side).ok_or_else(|| bad("offset", "cannot offset that object"))?;
+9
View File
@@ -344,6 +344,15 @@ fn fillet_two_lines() {
assert!(g.iter().any(|p| p.near(Vec2::new(2.0, 0.0), 1e-9)));
}
#[test]
fn offset_zero_distance_is_rejected() {
let mut s = Session::new();
s.execute("line", &json!({"points": [[0, 0], [10, 0]]})).unwrap();
let r = s.execute("offset", &json!({"handle": "100", "distance": 0, "side": [1, 1]}));
assert!(r.is_err(), "offset distance 0 made a coincident copy: {r:?}");
assert_eq!(s.doc().unwrap().model.len(), 1);
}
#[test]
fn offset_circle_and_polyline() {
let mut s = Session::new();