From 7c9a4540043fac014c3f96b43f7c761a30823436 Mon Sep 17 00:00:00 2001 From: Cory Douglas Martin <4108748+flight1973@users.noreply.github.com> Date: Mon, 9 Nov 2026 19:23:21 -0600 Subject: [PATCH 1/4] fix(analysis): Minimum Bounding Geometry looks at Cancel with Group: All With Group: All, Minimum Bounding Geometry gathered every feature's points without looking at Cancel or counting progress, so a large layer couldn't be stopped until the hull was made. It now looks per feature, as the one-hull-each path already did through parallel::try_map; the single hull of all the points is one step without a look, said in its doc comment. Both groupings join the long tools in the cancel test, each named with its parameters, and AGENTS.md lists the tool. The buffer progress test used Minimum Bounding Geometry as a tool that counts no progress; it now uses Feature Vertices To Points. Rows are taken once each through each_once, as other tools do. --- AGENTS.md | 2 +- crates/analysis/src/tools.rs | 15 +++++++++++---- crates/engine/src/tests.rs | 9 ++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 35a2278512..a6d1b7a65a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -47,7 +47,7 @@ is out of scope. 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, Erase, Intersect, Identity, Union, Symmetrical - Difference, Update, Split, Kernel Density, Kriging); a new tool + Difference, Update, Split, Minimum Bounding Geometry, 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 f27de24531..2f234b4d94 100644 --- a/crates/analysis/src/tools.rs +++ b/crates/analysis/src/tools.rs @@ -2278,6 +2278,9 @@ fn dissolve(inp: &dyn Inputs, p: &Json) -> Result { /// latitude past ±90° is taken as the pole.) const HULL_LIMIT_M: f64 = 1e12; +/// Minimum Bounding Geometry. Cancel is looked at per feature, as each one's points are gathered +/// (and its hull made, one hull each); the one hull of all features' points, with `group` All, is +/// a single step without a look. fn convex_hull(inp: &dyn Inputs, p: &Json) -> Result { let ds = input(inp, p, "input")?; let each = s(p, "group") == "None"; @@ -2306,8 +2309,7 @@ fn convex_hull(inp: &dyn Inputs, p: &Json) -> Result { (these, gaps, poles) }; // Each row once, however often a selection lists it, in the selection's order. - let mut seen = std::collections::HashSet::new(); - let picked: Vec = rows(inp, p, "input", ds).into_iter().filter(|r| seen.insert(*r)).collect(); + let picked = each_once(rows(inp, p, "input", ds)); // The features with a geometry, each with it; the rest are left out, and counted. let features: Vec<(&Feature, &Geometry)> = picked.iter().filter_map(|&r| ds.features.get(r).and_then(|f| Some((f, f.geometry.as_ref()?)))).collect(); @@ -2364,8 +2366,13 @@ fn convex_hull(inp: &dyn Inputs, p: &Json) -> Result { } else { // All together; `count` is the features hulled, those with a point to give. With none, // no hull is written, as one feature each. + // Cancel is looked at, and progress counted, per feature; the one hull of all their + // points is a single step without a look. let (mut pts, mut hulled) = (Vec::new(), 0usize); - for (_, g) in &features { + crate::control::begin(features.len()); + for (done, (_, g)) in features.iter().enumerate() { + crate::control::check()?; + crate::control::reached(done); let (these, passed, past) = points(g); gaps += passed; poles += past; @@ -8982,7 +8989,7 @@ mod tests { crate::run_with("buffer", &m, &serde_json::json!({"input": "pts", "distance": 100.0}), &control).unwrap_or_else(|e| panic!("{e}")); assert_eq!(control.progress(), Some((40, 40))); // The same control for a tool that doesn't count shows no count, not the buffers'. - crate::run_with("convexHull", &m, &serde_json::json!({"input": "pts"}), &control).unwrap_or_else(|e| panic!("{e}")); + crate::run_with("featureVerticesToPoints", &m, &serde_json::json!({"input": "pts"}), &control).unwrap_or_else(|e| panic!("{e}")); assert_eq!(control.progress(), None); // Dissolved, the union after the buffers isn't counted: the buffers' count ends before it. let dissolve = serde_json::json!({"input": "pts", "distance": 100.0, "dissolve": "All"}); diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index c1d9ec20e5..dd4e64b803 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -37084,8 +37084,8 @@ fn long_commands_stop_when_cancelled_while_they_run() { } // 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). + // hulls, 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"})), @@ -37098,6 +37098,8 @@ fn long_commands_stop_when_cancelled_while_they_run() { ("symmetricalDifference", json!({"input": "Lakes", "overlay": "Countries"})), ("update", json!({"input": "Countries", "update": "Lakes"})), ("split", json!({"input": "Rivers", "split": "Countries"})), + ("convexHull", json!({"input": "Countries", "group": "None"})), + ("convexHull", json!({"input": "Countries", "group": "All"})), ("kernelDensity", json!({"input": "Cities", "crs": "EPSG:3857"})), ("kriging", json!({"input": "Cities", "field": "pop_max"})), ]; @@ -37110,7 +37112,8 @@ fn long_commands_stop_when_cancelled_while_they_run() { let done = run.run(&control); // The result is kept, then `gp.finish` applies it (or says why it can't), as in the app. let finished = crate::cmd::gp::tool_complete(&mut s, id, done).and_then(|()| s.run("gp.finish", &json!({"id": id})).map(|_| ())); - note(tool, finished, &control); + // With its parameters: a tool listed twice (convexHull) is told apart. + note(&format!("{tool} {params}"), finished, &control); } assert!(kept_going.is_empty(), "these ran on after Cancel:\n{}", kept_going.join("\n")); } From b7bc86c0582aaf3f17630d836bdf95cfdc099234 Mon Sep 17 00:00:00 2001 From: Cory Douglas Martin <4108748+flight1973@users.noreply.github.com> Date: Mon, 9 Nov 2026 19:47:26 -0600 Subject: [PATCH 2/4] fix(analysis): Group: All gathers points through try_map; its count ends before the hull Review follow-up. With Group: All, each feature's points are gathered through parallel::try_map, as the one-hull-each path does: Cancel is looked at and progress counted per feature, on several cores for many, the points placed in order so the hull is the same. Cancel is looked at again before the one hull of all the points, and the count ends there, so a Cancel during it isn't said to come near the end. The doc comment names each step without a look, and the cancel test gives the two runs outputs of their own. --- crates/analysis/src/tools.rs | 23 ++++++++++++----------- crates/engine/src/tests.rs | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/crates/analysis/src/tools.rs b/crates/analysis/src/tools.rs index 2f234b4d94..78fd6e4b71 100644 --- a/crates/analysis/src/tools.rs +++ b/crates/analysis/src/tools.rs @@ -2278,9 +2278,9 @@ fn dissolve(inp: &dyn Inputs, p: &Json) -> Result { /// latitude past ±90° is taken as the pole.) const HULL_LIMIT_M: f64 = 1e12; -/// Minimum Bounding Geometry. Cancel is looked at per feature, as each one's points are gathered -/// (and its hull made, one hull each); the one hull of all features' points, with `group` All, is -/// a single step without a look. +/// Minimum Bounding Geometry. Cancel is looked at per feature, before its points are gathered (and +/// its hull made, one hull each); gathering one feature's points, and making its hull, are steps +/// without a look, as is the one hull of all features' points with `group` All. fn convex_hull(inp: &dyn Inputs, p: &Json) -> Result { let ds = input(inp, p, "input")?; let each = s(p, "group") == "None"; @@ -2365,15 +2365,12 @@ fn convex_hull(inp: &dyn Inputs, p: &Json) -> Result { } } else { // All together; `count` is the features hulled, those with a point to give. With none, - // no hull is written, as one feature each. - // Cancel is looked at, and progress counted, per feature; the one hull of all their - // points is a single step without a look. - let (mut pts, mut hulled) = (Vec::new(), 0usize); + // no hull is written, as one feature each. Each feature's points gathered on several + // cores for many, Cancel looked at and progress counted per feature, placed in order. crate::control::begin(features.len()); - for (done, (_, g)) in features.iter().enumerate() { - crate::control::check()?; - crate::control::reached(done); - let (these, passed, past) = points(g); + let gathered = crate::parallel::try_map(&features, PARALLEL_FEATURES, || (), |_, _, (_, g)| Ok::<_, String>(points(g)))?; + let (mut pts, mut hulled) = (Vec::new(), 0usize); + for (these, passed, past) in gathered { gaps += passed; poles += past; if these.is_empty() { @@ -2383,6 +2380,10 @@ fn convex_hull(inp: &dyn Inputs, p: &Json) -> Result { } pts.extend(these); } + // The one hull of all the points isn't counted, nor looked at inside: Cancel is looked at + // before it, and the count ends, so a Cancel during it isn't said to come near the end. + crate::control::check()?; + crate::control::begin(0); if hulled > 0 { match shape(geo::MultiPoint::new(pts).convex_hull(), &mut flat) { Some(g) => out.push(Some(g), vec![Value::Int(i64::try_from(hulled).unwrap_or(i64::MAX))]), diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index dd4e64b803..16ed8d4312 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -37098,8 +37098,8 @@ fn long_commands_stop_when_cancelled_while_they_run() { ("symmetricalDifference", json!({"input": "Lakes", "overlay": "Countries"})), ("update", json!({"input": "Countries", "update": "Lakes"})), ("split", json!({"input": "Rivers", "split": "Countries"})), - ("convexHull", json!({"input": "Countries", "group": "None"})), - ("convexHull", json!({"input": "Countries", "group": "All"})), + ("convexHull", json!({"input": "Countries", "group": "None", "output": "Hulls_each"})), + ("convexHull", json!({"input": "Countries", "group": "All", "output": "Hulls_all"})), ("kernelDensity", json!({"input": "Cities", "crs": "EPSG:3857"})), ("kriging", json!({"input": "Cities", "field": "pop_max"})), ]; From 88d35e291c8ade9824ef5e2c661a71395ea8f898 Mon Sep 17 00:00:00 2001 From: Cory Douglas Martin <4108748+flight1973@users.noreply.github.com> Date: Tue, 10 Nov 2026 14:52:40 -0600 Subject: [PATCH 3/4] fix(analysis): Group: All hulls each feature, then hulls their hull points Review follow-up. Group: All kept every feature's points and then copied them into one list for the hull, up to twice the memory of main. Each feature is now hulled apart in the try_map and only its hull's points are kept; the hull of those is the hull of all the points (a corner of the whole hull is a corner of its own feature's hull), from far fewer points, so the one step without a look is much shorter. Its ring can start at another corner than before, and a flat hull's line can run the other way. A test checks the corners match exactly over 200 sets of random, collinear, repeated and single points. The count ends before the hull points are put together, and Cancel is looked at per feature there and again before the final hull. --- crates/analysis/src/tools.rs | 89 ++++++++++++++++++++++++++++++++---- 1 file changed, 80 insertions(+), 9 deletions(-) diff --git a/crates/analysis/src/tools.rs b/crates/analysis/src/tools.rs index 78fd6e4b71..a6be828b2b 100644 --- a/crates/analysis/src/tools.rs +++ b/crates/analysis/src/tools.rs @@ -2278,9 +2278,20 @@ fn dissolve(inp: &dyn Inputs, p: &Json) -> Result { /// latitude past ±90° is taken as the pole.) const HULL_LIMIT_M: f64 = 1e12; -/// Minimum Bounding Geometry. Cancel is looked at per feature, before its points are gathered (and -/// its hull made, one hull each); gathering one feature's points, and making its hull, are steps -/// without a look, as is the one hull of all features' points with `group` All. +/// Minimum Bounding Geometry. Cancel is looked at per feature, before its points are gathered and +/// its hull made; gathering one feature's points, and making its hull, are steps without a look, +/// as is, with `group` All, the one hull of the features' hull points. +/// The points of the convex hull of `pts`: its ring's, none for none. The hull of several sets' +/// hull points is the hull of all their points, as a point that is a corner of the whole hull is +/// one of its own set's hull too; Minimum Bounding Geometry with `group` All hulls each feature +/// apart and keeps only these. +fn hull_points(pts: Vec>) -> Vec> { + if pts.is_empty() { + return pts; + } + geo::MultiPoint::new(pts).convex_hull().exterior().points().collect() +} + fn convex_hull(inp: &dyn Inputs, p: &Json) -> Result { let ds = input(inp, p, "input")?; let each = s(p, "group") == "None"; @@ -2365,12 +2376,26 @@ fn convex_hull(inp: &dyn Inputs, p: &Json) -> Result { } } else { // All together; `count` is the features hulled, those with a point to give. With none, - // no hull is written, as one feature each. Each feature's points gathered on several - // cores for many, Cancel looked at and progress counted per feature, placed in order. + // no hull is written, as one feature each. Each feature hulled apart on several cores for + // many, Cancel looked at and progress counted per feature, keeping only its hull's points + // ([`hull_points`]): the hull of those is the hull of all, from far fewer points. crate::control::begin(features.len()); - let gathered = crate::parallel::try_map(&features, PARALLEL_FEATURES, || (), |_, _, (_, g)| Ok::<_, String>(points(g)))?; + let gathered = crate::parallel::try_map( + &features, + PARALLEL_FEATURES, + || (), + |_, _, (_, g)| { + let (these, passed, past) = points(g); + Ok::<_, String>((hull_points(these), passed, past)) + }, + )?; + // The rest isn't counted: the count ends, so a Cancel in it isn't said to come near the + // end. Cancel is looked at per feature as their points are put together, then before the + // one hull, which is a step without a look. + crate::control::begin(0); let (mut pts, mut hulled) = (Vec::new(), 0usize); for (these, passed, past) in gathered { + crate::control::check()?; gaps += passed; poles += past; if these.is_empty() { @@ -2380,10 +2405,7 @@ fn convex_hull(inp: &dyn Inputs, p: &Json) -> Result { } pts.extend(these); } - // The one hull of all the points isn't counted, nor looked at inside: Cancel is looked at - // before it, and the count ends, so a Cancel during it isn't said to come near the end. crate::control::check()?; - crate::control::begin(0); if hulled > 0 { match shape(geo::MultiPoint::new(pts).convex_hull(), &mut flat) { Some(g) => out.push(Some(g), vec![Value::Int(i64::try_from(hulled).unwrap_or(i64::MAX))]), @@ -10179,6 +10201,55 @@ mod tests { } } + /// The hull of each set's hull points is the hull of all the points, exactly: the same corners, + /// in the same direction (its ring may start at another corner), for random clouds, points on a + /// line, repeated points and single points, in sets of every size. + #[test] + fn the_hull_of_hull_points_is_the_hull_of_all() { + let mut seed = 0x2545_f491_4f6c_dd1d_u64; + let mut next = move || { + seed ^= seed << 13; + seed ^= seed >> 7; + seed ^= seed << 17; + // A value in [-1e7, 1e7), on a coarse grid so points repeat and fall on lines. + f64::from(u32::try_from(seed >> 44).unwrap_or(0) % 2001) * 1e4 - 1e7 + }; + for round in 0..200 { + let sets: Vec>> = (0..1 + round % 7) + .map(|k| { + let n = (round * 3 + k) % 12; + (0..n) + .map(|i| match (round + k) % 4 { + // On one line, or one point over and over. + 0 => geo::Point::new(f64::from(u32::try_from(i).unwrap_or(0)) * 5.0, 7.0), + 1 => geo::Point::new(3.0, -2.0), + _ => geo::Point::new(next(), next()), + }) + .collect() + }) + .collect(); + let all: Vec> = sets.iter().flatten().copied().collect(); + if all.is_empty() { + continue; + } + let hulls: Vec> = sets.into_iter().flat_map(hull_points).collect(); + // A ring's corners from its least one, the closing repeat left off. + let corners = |hull: geo::Polygon| { + let mut ring: Vec<(f64, f64)> = hull.exterior().0.iter().map(|c| (c.x, c.y)).collect(); + ring.pop(); + let start = + ring.iter().enumerate().min_by(|a, b| a.1.partial_cmp(b.1).unwrap_or(std::cmp::Ordering::Equal)).map_or(0, |(i, _)| i); + ring.rotate_left(start); + ring + }; + assert_eq!( + corners(geo::MultiPoint::new(hulls).convex_hull()), + corners(geo::MultiPoint::new(all).convex_hull()), + "round {round}" + ); + } + } + #[test] fn indexed_clip_matches_the_whole_mask() { let m = indexed_overlay_inputs(); From 8ab213dec144200d1d08f89899a8cf0193123c80 Mon Sep 17 00:00:00 2001 From: Cory Douglas Martin <4108748+flight1973@users.noreply.github.com> Date: Tue, 10 Nov 2026 17:00:49 -0600 Subject: [PATCH 4/4] fix(analysis): convex_hull keeps its doc comment; test the Group: All line's ends Review follow-up. Adding hull_points put it between convex_hull and its doc comment, which names the steps without a Cancel look; the comment is back on convex_hull. A new test runs Group: All on points of several features along one parallel and checks the line runs between the two farthest apart, in either direction, with a count of 5. --- crates/analysis/src/tools.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/crates/analysis/src/tools.rs b/crates/analysis/src/tools.rs index a6be828b2b..1ad6b8c052 100644 --- a/crates/analysis/src/tools.rs +++ b/crates/analysis/src/tools.rs @@ -2278,9 +2278,6 @@ fn dissolve(inp: &dyn Inputs, p: &Json) -> Result { /// latitude past ±90° is taken as the pole.) const HULL_LIMIT_M: f64 = 1e12; -/// Minimum Bounding Geometry. Cancel is looked at per feature, before its points are gathered and -/// its hull made; gathering one feature's points, and making its hull, are steps without a look, -/// as is, with `group` All, the one hull of the features' hull points. /// The points of the convex hull of `pts`: its ring's, none for none. The hull of several sets' /// hull points is the hull of all their points, as a point that is a corner of the whole hull is /// one of its own set's hull too; Minimum Bounding Geometry with `group` All hulls each feature @@ -2292,6 +2289,9 @@ fn hull_points(pts: Vec>) -> Vec> { geo::MultiPoint::new(pts).convex_hull().exterior().points().collect() } +/// Minimum Bounding Geometry. Cancel is looked at per feature, before its points are gathered and +/// its hull made; gathering one feature's points, and making its hull, are steps without a look, +/// as is, with `group` All, the one hull of the features' hull points. fn convex_hull(inp: &dyn Inputs, p: &Json) -> Result { let ds = input(inp, p, "input")?; let each = s(p, "group") == "None"; @@ -8876,6 +8876,26 @@ mod tests { assert!(each.get(1).map_or(0, ring_len) >= 4, "{each:?}"); } + /// With Group: All, points of several features on one parallel make one line, between the two + /// farthest apart, whichever feature each comes from and in either direction. + #[test] + fn grouped_hull_of_points_on_a_line_is_the_line_between_the_ends() { + let mut pts = Dataset::new("pts", GeometryType::Point, vec![]); + for lon in [20.0, 10.0, 30.0, 25.0, 15.0] { + pts.push(Some(Geometry::Point(Coord::new(lon, 0.0))), vec![]); + } + let m = Map(HashMap::from([("pts".to_string(), pts)])); + let res = crate::run("convexHull", &m, &serde_json::json!({"input": "pts", "group": "All"})).unwrap_or_else(|e| panic!("{e}")); + let out = layer(res); + let Some(Some(Geometry::Line(parts))) = out.features.first().map(|f| f.geometry.clone()) else { panic!("{:?}", out.features) }; + let mut ends: Vec<(f64, f64)> = parts.iter().flatten().map(|c| (c.x, c.y)).collect(); + ends.sort_by(|a, b| a.0.total_cmp(&b.0)); + assert_eq!(ends.len(), 2, "{parts:?}"); + let near = |a: (f64, f64), b: (f64, f64)| (a.0 - b.0).abs() < 1e-9 && (a.1 - b.1).abs() < 1e-9; + assert!(near(ends[0], (10.0, 0.0)) && near(ends[1], (30.0, 0.0)), "{ends:?}"); + assert_eq!(out.value(0, 0), &Value::Int(5)); + } + /// Minimum Bounding Geometry passes over a vertex with a coordinate missing or infinite, which /// the hull can't order (it failed on one before), or so far out that its arithmetic would /// overflow, and skips a feature without geometry or with no point it can use (writing no hull