From 4dbac6c100dffffb8e1df9aaa96dda7322e4a162 Mon Sep 17 00:00:00 2001 From: Dominik Strebel Date: Mon, 9 Nov 2026 15:37:43 +0100 Subject: [PATCH 1/3] fix(analysis): the overlay tools look at Cancel and count their progress; the test runs them (#1562) Erase, Intersect, Identity, Union, Symmetrical Difference, Update and Split never looked at Cancel: their zones (one union each when a polygon has several parts), their input features, Union's and Symmetrical Difference's remaining zones and Split's layers now check and count. The Cancel test runs all seven, and AGENTS.md names the long tools it covers. --- AGENTS.md | 4 ++- crates/analysis/src/tools.rs | 48 +++++++++++++++++++++++++++--------- crates/engine/src/tests.rs | 12 +++++++-- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 06da9da7dd..c0e5c4826d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -45,7 +45,9 @@ is out of scope. - A command that must run on the UI thread says why in its doc comment. - `crates/engine/src/tests.rs::long_commands_stop_when_cancelled_while_they_run` cancels each background command as its work starts and fails one that never looks; its lists must match the - background registries, so a new background command is added there. Passing shows the work looks + background registries, so a new background command is added there. It also runs the long tools + (Buffer, Dissolve, Spatial Join, Clip, the overlay tools, Kernel Density, Kriging); a new tool + whose work grows with its input is added to that list. Passing shows the work looks at Cancel, not that it looks often: a long step without a check (one union, one read) is said in its doc comment. diff --git a/crates/analysis/src/tools.rs b/crates/analysis/src/tools.rs index bda480871d..b1ee991471 100644 --- a/crates/analysis/src/tools.rs +++ b/crates/analysis/src/tools.rs @@ -1671,7 +1671,11 @@ fn erase(inp: &dyn Inputs, p: &Json) -> Result { let at_poles = AtPoles::new(zones.iter().map(|z| poles(&z.ext))); let mut out = copy_schema(ds, out_name(p, format!("{}_Erase", ds.name)), ds.geometry_type); keep_source_crs(&mut out, ds, er); - for r in rows(inp, p, "input", ds) { + let input_rows = rows(inp, p, "input", ds); + crate::control::begin(input_rows.len()); + for (done, r) in input_rows.into_iter().enumerate() { + crate::control::check()?; + crate::control::reached(done); let Some(f) = ds.features.get(r) else { continue }; if let Some(rest) = f.geometry.as_ref().and_then(|g| outside(g, &zones, (&index, &at_poles))) { out.push_next(Some(rest), f.attrs.clone()); @@ -1703,13 +1707,18 @@ fn overlay_zones<'a>(inp: &'a dyn Inputs, p: &Json, k: &str) -> Result<(&'a Data if ov.geometry_type != GeometryType::Polygon { return Err(format!("'{}' is not a polygon layer", ov.name)); } - let zones = rows(inp, p, k, ov) - .into_iter() - .filter_map(|row| { - let g = ov.features.get(row)?.geometry.as_ref()?; - Some(Zone { row, ext: g.extent(), poly: mask_of(to_multipolygon(g)?) }) - }) - .collect(); + // A zone of several parts is a union: Cancel is looked at, and progress counted, before each. + let zone_rows = rows(inp, p, k, ov); + crate::control::begin(zone_rows.len()); + let mut zones = Vec::with_capacity(zone_rows.len()); + for (done, row) in zone_rows.into_iter().enumerate() { + crate::control::check()?; + crate::control::reached(done); + let Some(g) = ov.features.get(row).and_then(|f| f.geometry.as_ref()) else { continue }; + if let Some(poly) = to_multipolygon(g).map(mask_of) { + zones.push(Zone { row, ext: g.extent(), poly }); + } + } Ok((ov, zones)) } @@ -1884,7 +1893,11 @@ fn overlay(inp: &dyn Inputs, p: &Json, op: Overlay) -> Result> = vec![Vec::new(); zones.len()]; - for r in rows(inp, p, "input", ds) { + let input_rows = rows(inp, p, "input", ds); + crate::control::begin(input_rows.len()); + for (done, r) in input_rows.into_iter().enumerate() { + crate::control::check()?; + crate::control::reached(done); let Some(f) = ds.features.get(r) else { continue }; let Some(g) = &f.geometry else { // All but Intersect keep every input feature: one without geometry, as it is. @@ -1909,7 +1922,10 @@ fn overlay(inp: &dyn Inputs, p: &Json, op: Overlay) -> Result Result { let at_poles = AtPoles::new(zones.iter().map(|z| poles(&z.ext))); let mut out = copy_schema(ds, out_name(p, format!("{}_Update", ds.name)), GeometryType::Polygon); keep_source_crs(&mut out, ds, up); - for r in rows(inp, p, "input", ds) { + let input_rows = rows(inp, p, "input", ds); + crate::control::begin(input_rows.len()); + for (done, r) in input_rows.into_iter().enumerate() { + crate::control::check()?; + crate::control::reached(done); let Some(f) = ds.features.get(r) else { continue }; let rest = match &f.geometry { None => { @@ -2116,7 +2136,11 @@ fn split(inp: &dyn Inputs, p: &Json) -> Result { let mut layers = Vec::new(); let mut empty = 0usize; let mut cand_buf = Vec::new(); - for (name, members) in groups { + // A layer each: Cancel is looked at, and progress counted, layer by layer. + crate::control::begin(groups.len()); + for (done, (name, members)) in groups.into_iter().enumerate() { + crate::control::check()?; + crate::control::reached(done); let polys: Vec<&Zone> = members.iter().filter_map(|zi| zones.get(*zi)).collect(); let mask = match polys.as_slice() { [only] => std::borrow::Cow::Borrowed(&only.poly), diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 4ec48ae7de..f5b11003f0 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -35429,13 +35429,21 @@ fn long_commands_stop_when_cancelled_while_they_run() { note(command, run.run(&control).map(|_| ()), &control); } - // The tools whose work grows past a second or two on real data (and whose work caps follow - // the threads): run in the background as the Analysis pane runs them. + // The tools whose work grows past a second or two on real data: buffers, overlays, joins, + // densities and interpolation. Run in the background as the Analysis pane runs them; a new + // long tool is added here (AGENTS.md › Never hold the window). let tools = [ ("buffer", json!({"input": "Cities", "distance": 100})), ("dissolve", json!({"input": "Countries"})), ("spatialJoin", json!({"target": "Cities", "join": "Countries"})), ("clip", json!({"input": "Rivers", "clip": "Countries"})), + ("erase", json!({"input": "Rivers", "erase": "Countries"})), + ("intersect", json!({"input": "Rivers", "overlay": "Countries"})), + ("identity", json!({"input": "Rivers", "overlay": "Countries"})), + ("union", json!({"input": "Lakes", "overlay": "Countries"})), + ("symmetricalDifference", json!({"input": "Lakes", "overlay": "Countries"})), + ("update", json!({"input": "Countries", "update": "Lakes"})), + ("split", json!({"input": "Rivers", "split": "Countries"})), ("kernelDensity", json!({"input": "Cities", "crs": "EPSG:3857"})), ("kriging", json!({"input": "Cities", "field": "pop_max"})), ]; From be258a37856af79662a53247e78f8a4423e81ef6 Mon Sep 17 00:00:00 2001 From: Dominik Strebel Date: Mon, 9 Nov 2026 16:22:09 +0100 Subject: [PATCH 2/3] fix(analysis): Update looks at Cancel while it adds its polygons, Split between candidates; AGENTS.md names the tools (#1562) --- AGENTS.md | 3 ++- crates/analysis/src/tools.rs | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index c0e5c4826d..35a2278512 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -46,7 +46,8 @@ is out of scope. - `crates/engine/src/tests.rs::long_commands_stop_when_cancelled_while_they_run` cancels each background command as its work starts and fails one that never looks; its lists must match the background registries, so a new background command is added there. It also runs the long tools - (Buffer, Dissolve, Spatial Join, Clip, the overlay tools, Kernel Density, Kriging); a new tool + (Buffer, Dissolve, Spatial Join, Clip, Erase, Intersect, Identity, Union, Symmetrical + Difference, Update, Split, Kernel Density, Kriging); a new tool whose work grows with its input is added to that list. Passing shows the work looks at Cancel, not that it looks often: a long step without a check (one union, one read) is said in its doc comment. diff --git a/crates/analysis/src/tools.rs b/crates/analysis/src/tools.rs index b1ee991471..c4f1b75723 100644 --- a/crates/analysis/src/tools.rs +++ b/crates/analysis/src/tools.rs @@ -2044,7 +2044,10 @@ fn update(inp: &dyn Inputs, p: &Json) -> Result { } } let kept = out.features.len(); - for z in &zones { + crate::control::begin(zones.len()); + for (done, z) in zones.iter().enumerate() { + crate::control::check()?; + crate::control::reached(done); let Some(u) = up.features.get(z.row) else { continue }; let attrs = ds.fields.iter().zip(&from).map(|(f, i)| i.and_then(|i| u.attrs.get(i)).map_or(Value::Null, |v| converted(v, f.ty))).collect(); @@ -2153,6 +2156,8 @@ fn split(inp: &dyn Inputs, p: &Json) -> Result { index.candidates_into(&ext, &mut cand_buf); points_at_poles.add_to(reached, &mut cand_buf); for &li in &cand_buf { + // A layer can take most of the input: Cancel is looked at feature by feature too. + crate::control::check()?; let Some((r, e)) = located.get(li) else { continue }; let Some(f) = ds.features.get(*r) else { continue }; let meets = e.intersects(&ext) || (point(*r) && meet_at_a_pole(poles(e), reached)); From dd1cd4766a63fe8de2051df6483ccb0e824da2a1 Mon Sep 17 00:00:00 2001 From: Dominik Strebel Date: Mon, 9 Nov 2026 17:08:32 +0100 Subject: [PATCH 3/3] docs(analysis): an overlay polygon's rest is one step Cancel doesn't stop (#1562) --- crates/analysis/src/tools.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/analysis/src/tools.rs b/crates/analysis/src/tools.rs index c4f1b75723..7f79bc2ada 100644 --- a/crates/analysis/src/tools.rs +++ b/crates/analysis/src/tools.rs @@ -1877,7 +1877,9 @@ fn outside(g: &Geometry, zones: &[Zone], index: (&ExtentIndex, &AtPoles)) -> Opt /// layer that overlap each other are not split against each other. Intersect leaves out input /// features without geometry; the others keep them, as they are, and an input feature no overlay /// polygon meets too, coordinates untouched (a feature that is cut comes out rebuilt, its -/// overlapping parts unioned). +/// overlapping parts unioned). Cancel is looked at per overlay polygon, input feature and +/// remaining zone; the rest of an overlay polygon is one difference against the union of the +/// input polygons covering it, and Cancel isn't looked at inside that step (#1562). fn overlay(inp: &dyn Inputs, p: &Json, op: Overlay) -> Result { let ds = input(inp, p, "input")?; if ds.geometry_type == GeometryType::None {