Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
59 changes: 45 additions & 14 deletions crates/analysis/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,11 @@ fn erase(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
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());
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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<ToolResult, String> {
let ds = input(inp, p, "input")?;
if ds.geometry_type == GeometryType::None {
Expand All @@ -1884,7 +1895,11 @@ fn overlay(inp: &dyn Inputs, p: &Json, op: Overlay) -> Result<ToolResult, String
let zone_attrs = |z: &Zone| ov.features.get(z.row).map(|o| o.attrs.as_slice());
// For Union and Symmetrical Difference, the rows of the input polygons that overlap each zone.
let mut covering: Vec<Vec<usize>> = 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.
Expand All @@ -1909,7 +1924,10 @@ fn overlay(inp: &dyn Inputs, p: &Json, op: Overlay) -> Result<ToolResult, String
}
}
if op.keeps_overlay_rest() {
for (z, inputs) in zones.iter().zip(&covering) {
crate::control::begin(zones.len());
for (done, (z, inputs)) in zones.iter().zip(&covering).enumerate() {
Comment thread
pick2510 marked this conversation as resolved.
Resolved
crate::control::check()?;
crate::control::reached(done);
let rest = if inputs.is_empty() {
from_multipolygon(&z.poly)
} else {
Expand Down Expand Up @@ -2010,7 +2028,11 @@ fn update(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
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);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
let Some(f) = ds.features.get(r) else { continue };
let rest = match &f.geometry {
None => {
Expand All @@ -2024,7 +2046,10 @@ fn update(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
}
}
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);
Comment thread
pick2510 marked this conversation as resolved.
Resolved
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();
Expand Down Expand Up @@ -2116,7 +2141,11 @@ fn split(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
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()?;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
crate::control::reached(done);
Comment thread
pick2510 marked this conversation as resolved.
Resolved
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),
Expand All @@ -2129,6 +2158,8 @@ fn split(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
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()?;
Comment thread
pick2510 marked this conversation as resolved.
Resolved
Comment thread
pick2510 marked this conversation as resolved.
Resolved
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));
Expand Down
12 changes: 10 additions & 2 deletions crates/engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Comment thread
pick2510 marked this conversation as resolved.
Resolved
("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"})),
Comment thread
pick2510 marked this conversation as resolved.
Resolved
("split", json!({"input": "Rivers", "split": "Countries"})),
("kernelDensity", json!({"input": "Cities", "crs": "EPSG:3857"})),
("kriging", json!({"input": "Cities", "field": "pop_max"})),
];
Expand Down
Loading