style(simulation): rustfmt trace_outer_boundary (#960)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-25 10:15:34 +02:00
co-authored by Claude Opus 4.7
parent 89596dbb87
commit c1d0d382ac
+13 -3
View File
@@ -569,7 +569,13 @@ fn build_basins(labels: &[i32], w: usize, h: usize) -> Vec<DrainageBasin> {
/// `start` (a row-major cell index), clockwise, via Moore-neighbour tracing.
/// Produces an ordered, 8-connected, non-self-crossing perimeter. The grid edge is
/// treated as background (no x-wrap) — this is for atlas visualization, not flow.
fn trace_outer_boundary(labels: &[i32], w: usize, h: usize, basin_id: i32, start: usize) -> Vec<(u16, u16)> {
fn trace_outer_boundary(
labels: &[i32],
w: usize,
h: usize,
basin_id: i32,
start: usize,
) -> Vec<(u16, u16)> {
// Moore-neighbourhood offsets in clockwise order: N, NE, E, SE, S, SW, W, NW.
const DIRS: [(i32, i32); 8] = [
(-1, 0),
@@ -588,7 +594,8 @@ fn trace_outer_boundary(labels: &[i32], w: usize, h: usize, basin_id: i32, start
&& c < w as i32
&& labels[r as usize * w + c as usize] == basin_id
};
let dir_index = |dr: i32, dc: i32| -> usize { DIRS.iter().position(|&o| o == (dr, dc)).unwrap_or(0) };
let dir_index =
|dr: i32, dc: i32| -> usize { DIRS.iter().position(|&o| o == (dr, dc)).unwrap_or(0) };
let sr = (start / w) as i32;
let sc = (start % w) as i32;
@@ -660,7 +667,10 @@ mod tests {
1, 1, 1, 1, //
];
let boundary = trace_outer_boundary(&labels, 4, 4, 1, 0);
assert!(boundary.len() >= 8, "expected a real perimeter, got {boundary:?}");
assert!(
boundary.len() >= 8,
"expected a real perimeter, got {boundary:?}"
);
// The defining property the angle-sort violated: consecutive boundary
// points are 8-adjacent (a genuine contour walk, not crossing chords).
for w in boundary.windows(2) {