Skip to content
Merged
4 changes: 4 additions & 0 deletions .github/scripts/ratchet-limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def compare(path, base_text, head_text):
try:
base = parse(base_text, path == ROWS_FILE)
except ValueError as error:
# A deletion is approved as a deletion, whatever the base held: an approval for an
# unreadable base would otherwise approve a deletion it doesn't name.
if head_text is None:
return [(f"{path}: deleted, and its base can't be read ({error}) to count its limits", f"{path} deleted")]
# The limits can't be compared, so a raise could hide behind this: it needs a maintainer's say,
# for the head as it is (its digest is in the token), not for whatever is pushed next.
digest = hashlib.sha256((head_text or "").encode("utf-8")).hexdigest()[:12]
Expand Down
6 changes: 6 additions & 0 deletions .github/scripts/test_ratchet_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def test_a_deleted_file_is_refused_and_a_new_one_is_fine(self):
self.assertEqual(len(self.problems(ROWS, None)), 1)
self.assertEqual(self.problems(None, ROWS), [])

def test_a_deleted_file_with_an_unreadable_base_is_approved_as_a_deletion(self):
[token] = self.tokens("count = many\n", None)
self.assertTrue(token.endswith("deleted"), token)
[message] = self.problems("count = many\n", None)
self.assertIn("deleted", message)

def test_the_first_line_of_a_name_is_the_limit_as_xtask_reads_it(self):
self.assertEqual(MODULE.parse("count = 5\ncount = 9\n")["count"][0], 5)
self.assertEqual(len(self.problems(ROWS, "count = 782\ncount = 999\n")), 0)
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ on:

permissions: {}

env:
# The body of the approval automerge posts, by which it later finds the approvals it may dismiss.
APPROVAL_BODY: Approved via automerge.

# `automerge` label and unlabel runs share a queue, so a pending revoke run isn't replaced; GitHub
# doesn't guarantee their order, so each run checks the label as it is now rather than relying on
# it. `synchronize` and unrelated labels get their own groups.
Expand Down Expand Up @@ -45,9 +49,13 @@ jobs:
# anyway, so each call is attempted and its own failure ignored.
refuse() {
echo "::error::$1"
gh pr merge "$PR" --disable-auto || true
# Disabled when armed (or when that can't be read); a failure to disable is said.
armed=$(gh pr view "$PR" --json autoMergeRequest --jq '.autoMergeRequest != null') || armed=unknown
if [ "$armed" != false ]; then
gh pr merge "$PR" --disable-auto || echo "::error::auto-merge may still be armed: disabling it failed"
fi
if me=$(gh api user --jq .login) && ids=$(gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews?per_page=100" \
| jq -r --arg owner "$me" '.[] | select((.user.login // "") == $owner and .state == "APPROVED" and (.body // "") == "Approved via automerge.") | .id'); then
| jq -r --arg owner "$me" --arg body "$APPROVAL_BODY" '.[] | select((.user.login // "") == $owner and .state == "APPROVED" and (.body // "") == $body) | .id'); then
for review_id in $ids; do
gh api -X PUT "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews/$review_id/dismissals" \
-f message="automerge label refused" --silent || true
Expand Down Expand Up @@ -79,7 +87,7 @@ jobs:
# The token owner can't approve their own pull requests, and needn't: they bypass the review.
if [ "$AUTHOR" != "$owner" ]; then
gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews" -f commit_id="$SHA" -f event=APPROVE \
-f body="Approved via automerge." --silent || { gh pr merge "$PR" --disable-auto; exit 1; }
-f body="$APPROVAL_BODY" --silent || { gh pr merge "$PR" --disable-auto; exit 1; }
fi

revoke:
Expand Down Expand Up @@ -121,7 +129,7 @@ jobs:
# Dismiss on both actions, so a push doesn't depend on the label removal succeeding.
# Reads in an if condition, where set -e doesn't stop the step; a failed read counts.
if owner=$(gh api user --jq .login) && ids=$(gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews?per_page=100" \
| jq -r --arg owner "$owner" '.[] | select((.user.login // "") == $owner and .state == "APPROVED" and (.body // "") == "Approved via automerge.") | .id'); then
| jq -r --arg owner "$owner" --arg body "$APPROVAL_BODY" '.[] | select((.user.login // "") == $owner and .state == "APPROVED" and (.body // "") == $body) | .id'); then
for review_id in $ids; do
gh api -X PUT "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews/$review_id/dismissals" \
-f message="Automerge label removed" --silent || failed=1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mobile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ jobs:
sdk="$(xcrun --sdk iphoneos --show-sdk-version)"
echo "::notice::$(xcodebuild -version | head -1), iOS SDK $sdk"
# App Store Connect requires the iOS 27 SDK from April 2027 (ITMS-90725).
[ "${sdk%%.*}" -ge 27 ] || { echo "::error::$(basename "$newest") has the iOS $sdk SDK; App Store uploads need iOS 27 or later."; exit 1; }
[ "${sdk%%.*}" -ge 27 ] || { echo "::error::$(basename "$newest") has the iOS $sdk SDK; App Store uploads need the iOS 27 SDK from April 2027 (ITMS-90725)."; exit 1; }

# The whole bundle, unsigned: any failure on the way fails the step.
- name: Build the app
Expand Down
17 changes: 6 additions & 11 deletions crates/analysis/src/neural.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,9 @@ pub struct Classified {
}

/// Classifies every pixel: class numbers (1-based, `nodata` where a band has no data) and each
/// pixel's probability of that class. Rows go on several threads when the work is large, except in
/// the browser, which uses one (#1252).
pub fn classify(r: &Raster, model: &Mlp, nodata: f32) -> Result<(Vec<f32>, Vec<f32>), String> {
let out = classify_on(r, model, nodata, None)?;
Ok((out.class, out.prob))
}

/// Like [`classify`], and also counts valid pixels whose values overflowed the network to
/// non-finite probabilities and were left as `nodata`.
/// pixel's probability of that class, and counts valid pixels whose values overflowed the network
/// to non-finite probabilities and were left as `nodata`, for the caller to report. Rows go on
/// several threads when the work is large, except in the browser, which uses one (#1252).
pub fn classify_reporting(r: &Raster, model: &Mlp, nodata: f32) -> Result<Classified, String> {
classify_on(r, model, nodata, None)
}
Expand Down Expand Up @@ -661,8 +655,9 @@ mod tests {
let bits = |v: &[f32]| v.iter().map(|x| x.to_bits()).collect::<Vec<_>>();
assert_eq!((bits(&c), bits(&p)), (bits(&c1), bits(&p1)), "{threads} threads");
}
// As many threads as pay off, which `classify` picks, give the same.
let (c, p) = classify(&r, &model, -1.0).unwrap();
// As many threads as pay off, which `classify_reporting` picks, give the same.
let Classified { class: c, prob: p, overflowed: ov } = classify_reporting(&r, &model, -1.0).unwrap();
assert_eq!(ov, 0);
assert_eq!((c, p), (c1, p1));
}

Expand Down
4 changes: 2 additions & 2 deletions crates/analysis/src/rasterops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ const BYTE_COUNT_CHUNK: usize = 1 << 20;
fn byte_stats(cells: &[f32]) -> Result<Option<BandStats>, String> {
let chunks: Vec<&[f32]> = cells.chunks(BYTE_COUNT_CHUNK).collect();
crate::control::begin(chunks.len());
// Two chunks, two million cells, before threads pay off; each thread takes one at a time, as
// there are few of them.
// Two chunks (more than a million cells) before threads pay off; each thread takes one at a
// time, as there are few of them.
let threads = crate::parallel::threads_for_each(chunks.len(), 2, 0);
let counted = crate::parallel::try_map_each_on(
&chunks,
Expand Down
43 changes: 31 additions & 12 deletions crates/analysis/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ pub static TOOLS: &[ToolSpec] = &[
id: "splitLineAtVertices",
name: "Split Line At Vertices",
toolbox: "Data Management › Features",
summary: "Writes a separate two-vertex line for each consecutive vertex pair.",
summary: "Writes a separate two-vertex line for each consecutive vertex pair of a line layer.",
params: &[
P { name: "input", label: "Input Features", kind: K::Layer, required: true, default: "", help: "" },
P { name: "input", label: "Input Line Features", kind: K::Layer, required: true, default: "", help: "" },
Comment thread
giswqs marked this conversation as resolved.
Resolved
P { name: "output", label: "Output Name", kind: K::Text, required: false, default: "", help: "" },
],
run: split_line_at_vertices,
Expand All @@ -82,9 +82,9 @@ pub static TOOLS: &[ToolSpec] = &[
id: "unsplitLine",
name: "Unsplit Line",
toolbox: "Data Management › Features",
summary: "Joins exact endpoint matches through degree-two nodes when all attributes agree. Branches stay separate.",
summary: "Joins a line layer's lines at exact endpoint matches through degree-two nodes when all attributes agree. Branches stay separate.",
params: &[
P { name: "input", label: "Input Features", kind: K::Layer, required: true, default: "", help: "" },
P { name: "input", label: "Input Line Features", kind: K::Layer, required: true, default: "", help: "" },
P { name: "output", label: "Output Name", kind: K::Text, required: false, default: "", help: "" },
],
run: geometry::unsplit,
Expand Down Expand Up @@ -1727,8 +1727,10 @@ fn geo_union_all<'a>(polys: impl IntoIterator<Item = &'a geo::Polygon<f64>>) ->
/// missing and nearly coincident vertices there can leave wrong. At exactly zero (a collapsed
/// ring, or lobes that cancel out) it keeps geo's direction, and the positive fill keeps only what
/// it goes around counterclockwise. An exterior that encloses nothing is taken without its holes.
/// A group uses Geo's union if any coordinate is outside the finite range ±2^500 (about
/// ±3.27e150). The i_overlay 9 stopgap uses its serial build on desktop and in the browser. Its
/// A group uses Geo's union if any coordinate of the rings the union reads is outside the finite
/// range ±2^500 (about ±3.27e150); the holes of an exterior that encloses nothing are left out
/// unread, unless any ring the union reads is out of range (Geo's union then reads every ring).
/// The i_overlay 9 stopgap uses its serial build on desktop and in the browser. Its
/// optional parallel build would require integrating the sort and split workers with RustGIS's
/// thread setting. The union is one step with no Cancel check inside it.
fn dissolve_union<'a, P>(polys: P) -> MultiPolygon<f64>
Expand Down Expand Up @@ -5081,8 +5083,9 @@ fn simplify_checked(g: &Geometry, tol_m: f64) -> Simplified {
}
if matches!(g, Geometry::Line(_) | Geometry::Polygon(_)) {
let mut broken = false;
// Beyond 1e150 plane meters (a longitude past about 1e143°), the squares in a distance
// overflow; no place on Earth is within a hair of it.
// Beyond 1e150 plane units (in longitude/latitude, a longitude past about 9e144°; in a
// projected system, its own units), the squares in a distance overflow; no place on Earth
// is within a hair of it.
const PLANE_LIMIT: f64 = 1e150;
g.for_each_coord(|c| {
let p = crate::convert::to_plane(c);
Expand Down Expand Up @@ -5353,9 +5356,10 @@ fn idw_interpolation(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
let mut pts: Vec<(Coord, f64)> = Vec::new();
let mut left_out = PointsLeftOut::default();
let picked = rows(inp, p, "input", ds);
let total = picked.len();
// Cancel is looked at between features; one feature with millions of vertices is read through
// `for_each_coord` without a look inside it.
for (n, r) in picked.iter().copied().enumerate() {
for (n, r) in picked.into_iter().enumerate() {
if n % LOOK_EVERY == 0 {
crate::control::check()?;
}
Expand Down Expand Up @@ -5423,7 +5427,7 @@ fn idw_interpolation(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
let msg = format!("IDW Interpolation: {} × {} cells from {} points", r.width, r.height, pts.len());
Ok(ToolResult {
losses: left_out
.losses("IDW Interpolation", picked.len(), field, "a coordinate is not a finite number")
.losses("IDW Interpolation", total, field, "a coordinate is not a finite number")
.into_iter()
.chain(raster_losses(&r))
.collect(),
Expand Down Expand Up @@ -5459,7 +5463,8 @@ fn kriging_interpolation(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, Strin
let mut raw_pts: Vec<(Coord, f64)> = Vec::new();
let mut left_out = PointsLeftOut::default();
let picked = rows(inp, p, "input", ds);
for (n, r) in picked.iter().copied().enumerate() {
let total = picked.len();
for (n, r) in picked.into_iter().enumerate() {
if n % LOOK_EVERY == 0 {
crate::control::check()?;
}
Expand Down Expand Up @@ -5582,7 +5587,7 @@ fn kriging_interpolation(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, Strin
let msg = format!("Ordinary Kriging ({}): {} × {} cells from {} points", model.as_str(), r.width, r.height, pts.len());
Ok(ToolResult {
losses: left_out
.losses("Ordinary Kriging", picked.len(), field, "a coordinate (or, for a line or polygon, its centre) is not a finite number")
.losses("Ordinary Kriging", total, field, "a coordinate (or, for a line or polygon, its centre) is not a finite number")
.into_iter()
.chain(raster_losses(&r))
.collect(),
Expand Down Expand Up @@ -10277,6 +10282,20 @@ mod tests {
});
}

/// The holes of an exterior that encloses nothing are never read, so one out of range there
/// doesn't send the group to Geo's union: the square beside it comes back alone.
#[test]
fn dissolve_union_leaves_unread_holes_out_of_the_range_check() {
finishes(|| {
let wide = geo::LineString::from(vec![(0.0, 0.0), (1e160, 1.0), (1.0, 1.0), (0.0, 1.0)]);
let collapsed = geo::Polygon::new(vec![(0.0, 0.0), (1.0, 0.0), (2.0, 0.0)].into(), vec![wide]);
let square = geo::Rect::new((5.0, 0.0), (6.0, 1.0)).to_polygon();
let union = dissolve_union([&collapsed, &square]);
assert_eq!(union, dissolve_union([&square]), "{union:?}");
assert_ne!(union, geo_union_all([&collapsed, &square]), "{union:?}");
});
}

/// Dissolve says how many features it left out for having no polygon: a point and a line in a
/// polygon layer (as Minimum Bounding Geometry's flat hulls are), an empty polygon and a
/// feature without geometry. Those in a group add nothing to its count or statistics. A layer
Expand Down
26 changes: 13 additions & 13 deletions crates/analysis/src/warp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,12 +948,11 @@ impl Aggregate<'_> {
// and its east corners near the west end: going east along an edge, the column drops by
// half the image or more. The pixels between are the far side of the globe. Its
// corners in the west go on past the east edge instead (by one turn of longitude, not
// always the image's width), and the pixels past it are the west's again. A westward cell
// that takes in the whole image (its span reaches from column 0 to the image's width, not a
// turn) is not across the seam, nor is a cell whose columns grow eastward as they do in
// an ordinary one. (An
// output that runs east to west, or a cell over half the globe wide in one, cannot be
// told from one across it and is read as before.)
// always the image's width), and the pixels past it are the west's again. A westward
// cell that takes in the whole image (its span reaches from column 0 to the image's
// width, not a turn) is not across the seam, nor is a cell whose columns grow eastward
// as they do in an ordinary one. (An output that runs east to west, or a cell over half
// the globe wide in one, cannot be told from one across it and is read as before.)
let mut wrapped = false;
let drop = |from: &(f64, f64), to: &(f64, f64)| from.0 - to.0;
if let Some(turn) = self.wrap.filter(|turn| {
Expand Down Expand Up @@ -991,8 +990,8 @@ impl Aggregate<'_> {
let (j0, j1) = (first(r0), past(r1, h));
// The columns of the image the cell takes: its own, and for a wrapped one the west's
// again, `turn` columns on.
let columns: Vec<(usize, usize, f64)> =
[0.0, turn].into_iter().take(if wrapped { 2 } else { 1 }).map(|off| (first(c0 - off), past(c1 - off, w), off)).collect();
let columns = [(first(c0), past(c1, w), 0.0), (first(c0 - turn), past(c1 - turn, w), turn)];
let columns = columns.get(..if wrapped { 2 } else { 1 }).unwrap_or_default();
values.iter_mut().for_each(Vec::clear);
weights.iter_mut().for_each(Vec::clear);
// The mean is summed as the pixels come (no copy of the cell's values); mode keeps them.
Expand All @@ -1003,7 +1002,7 @@ impl Aggregate<'_> {
if pace.stop(columns.iter().map(|(a, b, _)| b.saturating_sub(*a)).sum()) {
return;
}
for &(i0, i1, off) in &columns {
for &(i0, i1, off) in columns {
for i in i0..i1 {
if !holds(&quad, (i as f64 + 0.5 + off, j as f64 + 0.5)) {
continue;
Expand Down Expand Up @@ -1879,11 +1878,12 @@ mod tests {
}
}

/// A source whose columns stop short of a whole turn (8 of 44° end at 172°) isn't wrapped: a
/// cell across ±180° keeps its corners' columns, and takes nothing from the far side for the part
/// of the globe the source doesn't cover.
/// A source whose columns stop a pixel or less short of a whole turn (8 of 44° end at 172°)
/// still wraps, one turn of longitude being a little more than the image's width. A cell
/// across ±180° centred in the part of the globe the source doesn't cover (172°..180°) holds
/// no pixel's centre (column 7's is at 150°, column 0's at -158°), so it is empty.
#[test]
fn a_source_short_of_a_whole_turn_does_not_wrap() {
fn a_cell_centred_where_the_source_has_no_columns_is_empty() {
let r = globe(352.0);
// Longitudes folded into -180..180, as the output system centred on 180° gives them.
let folded = |x: f64, y: f64| Some((((x + 180.0).rem_euclid(360.0)) / 44.0, (90.0 - y) / 90.0));
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/cmd/design.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3248,7 +3248,7 @@ fn topology_validate(s: &mut Session, p: &Json) -> CmdResult {
}
if !skipped.is_empty() {
s.warn(format!(
"Polygons left out of the check at a pole (a coordinate missing or infinite, or a million turns around), so its result there may be wrong: {}",
"Features not checked completely (a coordinate missing or infinite, or, at a pole, a polygon a million turns around), so their results may be wrong: {}",
skipped.join("; ")
));
}
Expand Down
Loading
Loading