diff --git a/crates/engine/src/cmd/pathops.rs b/crates/engine/src/cmd/pathops.rs index 46bf4a37..fe33554f 100644 --- a/crates/engine/src/cmd/pathops.rs +++ b/crates/engine/src/cmd/pathops.rs @@ -503,6 +503,7 @@ fn offset_path(s: &mut Session, p: &Value) -> Result { let roots = selected_roots(s)?; let ids = s.edit("Offset Path", |d, sel| { let (mut out, mut above) = (vec![], vec![]); + let mut paths = false; for id in &roots { let Some(n) = d.node(*id).cloned() else { continue }; let mut lv = vec![]; @@ -510,6 +511,7 @@ fn offset_path(s: &mut Session, p: &Value) -> Result { let mut made = vec![]; for l in lv.iter().filter(|l| !matches!(l.kind, NodeKind::Text(_))) { let Some((path, rule)) = node_path(l) else { continue }; + paths = true; let base = if matches!(l.kind, NodeKind::Compound { .. }) && path.is_closed() { po::normalize(&path, rule) } else { path }; let off = po::offset_path(&base, delta, join, miter); if off.is_empty() { @@ -532,6 +534,9 @@ fn offset_path(s: &mut Session, p: &Value) -> Result { out.push(new.id); above.push((*id, vec![new])); } + if out.is_empty() && paths { + return Err(EngineError::Other("Offset Path: the offset leaves nothing of the selected paths (an inset larger than the shapes)".into())); + } if out.is_empty() { return Err(EngineError::Other("Offset Path: select paths".into())); } diff --git a/crates/engine/src/tests_pathops.rs b/crates/engine/src/tests_pathops.rs index 4f0ab4c3..9220223d 100644 --- a/crates/engine/src/tests_pathops.rs +++ b/crates/engine/src/tests_pathops.rs @@ -919,3 +919,14 @@ fn trim_merge_and_crop_remove_strokes() { } } } + +/// #1590: an inset larger than the shape leaves nothing, and the error says so rather than asking +/// for paths that are selected. +#[test] +fn offset_path_that_leaves_nothing_says_so() { + let mut s = session(); + let a = rect(&mut s, 0.0, 0.0, 10.0, 10.0); + s.execute("select.set", &json!({"ids": [a.0]})).unwrap(); + let e = s.execute("object.path.offsetPath", &json!({"offset": -20})).unwrap_err().to_string(); + assert!(e.contains("leaves nothing") && !e.contains("select paths"), "{e}"); +}