diff --git a/AGENTS.md b/AGENTS.md index 06da9da7dd..35a2278512 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -45,7 +45,10 @@ 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, 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 bda480871d..7f79bc2ada 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)) } @@ -1868,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 { @@ -1884,7 +1895,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 +1924,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 => { @@ -2024,7 +2046,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(); @@ -2116,7 +2141,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), @@ -2129,6 +2158,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)); 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"})), ];