Offset Path: an empty result says the offset leaves nothing

With paths selected but every offset empty (an inset larger than the
shape), Offset Path failed with "select paths", sending the user to
look for a selection problem. It now says the offset leaves nothing of
the selected paths; "select paths" stays for selections without paths.

Fixes #1590
This commit is contained in:
Gert Pellin authored and bflatastic committed 2026-10-13 10:52:38 +07:00
1 parent 7b0164e4e7
commit 5366cf689e
2 files changed
+16

No files matched your search

+5
View File
@@ -503,6 +503,7 @@ fn offset_path(s: &mut Session, p: &Value) -> Result<Value> {
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<Value> {
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<Value> {
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()));
}
+11
View File
@@ -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}");
}