Format the tree the way the gate asks for it
`cargo fmt --check` is a required step and had drifted across 45 files. Most of it arrived this week: several operations were written in parallel worktrees and merged by hand, and a hand-merge resolves conflicts without ever running the formatter over the result. No behaviour changes — this is `cargo fmt --all` and nothing else, kept as its own commit so the next reader can skip it wholesale rather than search it for one that matters. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -346,8 +346,8 @@ impl Shaped {
|
||||
radius_px: f32,
|
||||
) -> Self {
|
||||
let distance = signed_distance(coverage, width, height, threshold);
|
||||
let distance = apply_morphology(&distance, width, height, morphology, radius_px)
|
||||
.unwrap_or(distance);
|
||||
let distance =
|
||||
apply_morphology(&distance, width, height, morphology, radius_px).unwrap_or(distance);
|
||||
Self {
|
||||
distance,
|
||||
width,
|
||||
@@ -403,7 +403,11 @@ mod tests {
|
||||
// Distance from the boundary, so the half-pixel comes back off to
|
||||
// compare against the centre-to-centre figures.
|
||||
let at = |x: usize, y: usize| -d[y * 5 + x] + 0.5;
|
||||
assert!((at(1, 1) - std::f32::consts::SQRT_2).abs() < 1e-4, "{}", at(1, 1));
|
||||
assert!(
|
||||
(at(1, 1) - std::f32::consts::SQRT_2).abs() < 1e-4,
|
||||
"{}",
|
||||
at(1, 1)
|
||||
);
|
||||
assert!((at(0, 0) - (8.0f32).sqrt()).abs() < 1e-4, "{}", at(0, 0));
|
||||
assert_eq!(at(2, 0), 2.0, "straight up is exactly two");
|
||||
}
|
||||
@@ -489,7 +493,10 @@ mod tests {
|
||||
m[10 * w + 10] = 0;
|
||||
|
||||
let before = signed_distance(&m, w, h, 128);
|
||||
assert!(before[10 * w + 10] < 0.0, "the hole starts outside the mask");
|
||||
assert!(
|
||||
before[10 * w + 10] < 0.0,
|
||||
"the hole starts outside the mask"
|
||||
);
|
||||
|
||||
let after = apply_morphology(&before, w, h, Morphology::Close, 2.0).expect("recomputed");
|
||||
assert!(after[10 * w + 10] >= 0.0, "closing should have filled it");
|
||||
|
||||
@@ -142,7 +142,11 @@ impl Membership {
|
||||
|
||||
/// The instance a region belongs to, if any.
|
||||
pub fn instance_of(&self, region: u32) -> Option<usize> {
|
||||
self.of.get(region as usize).copied().flatten().map(|(i, _)| i)
|
||||
self.of
|
||||
.get(region as usize)
|
||||
.copied()
|
||||
.flatten()
|
||||
.map(|(i, _)| i)
|
||||
}
|
||||
|
||||
/// How two regions relate semantically, in `-1.0..=1.0`.
|
||||
@@ -233,11 +237,7 @@ pub fn apply_semantic_prior(
|
||||
///
|
||||
/// The returned ids are sorted, so the same click always produces the same
|
||||
/// mask — which is what lets it be a cache key.
|
||||
pub fn regions_for_instance(
|
||||
field: &RegionField,
|
||||
mask: &[f32],
|
||||
options: &PriorOptions,
|
||||
) -> Vec<u32> {
|
||||
pub fn regions_for_instance(field: &RegionField, mask: &[f32], options: &PriorOptions) -> Vec<u32> {
|
||||
let mut coverage = vec![0.0f32; field.region_count];
|
||||
let mut sizes = vec![0u32; field.region_count];
|
||||
|
||||
@@ -278,10 +278,26 @@ mod tests {
|
||||
labels: vec![0, 0, 2, 2, 1, 1, 3, 3],
|
||||
region_count: 4,
|
||||
adjacency: vec![
|
||||
Edge { a: 0, b: 1, saddle: 1.0 },
|
||||
Edge { a: 0, b: 2, saddle: 1.0 },
|
||||
Edge { a: 1, b: 3, saddle: 1.0 },
|
||||
Edge { a: 2, b: 3, saddle: 1.0 },
|
||||
Edge {
|
||||
a: 0,
|
||||
b: 1,
|
||||
saddle: 1.0,
|
||||
},
|
||||
Edge {
|
||||
a: 0,
|
||||
b: 2,
|
||||
saddle: 1.0,
|
||||
},
|
||||
Edge {
|
||||
a: 1,
|
||||
b: 3,
|
||||
saddle: 1.0,
|
||||
},
|
||||
Edge {
|
||||
a: 2,
|
||||
b: 3,
|
||||
saddle: 1.0,
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
@@ -361,7 +377,10 @@ mod tests {
|
||||
#[test]
|
||||
fn zero_strength_is_arm_a_exactly() {
|
||||
let f = field();
|
||||
let opts = PriorOptions { strength: 0.0, ..PriorOptions::default() };
|
||||
let opts = PriorOptions {
|
||||
strength: 0.0,
|
||||
..PriorOptions::default()
|
||||
};
|
||||
let m = Membership::compute(&f, &[&left_half()], &opts).unwrap();
|
||||
assert_eq!(apply_semantic_prior(&f, &m, &opts).adjacency, f.adjacency);
|
||||
}
|
||||
@@ -394,7 +413,11 @@ mod tests {
|
||||
let err = Membership::compute(&f, &[&vec![0.0; 3]], &PriorOptions::default()).unwrap_err();
|
||||
assert_eq!(
|
||||
err,
|
||||
MembershipError::MaskSize { instance: 0, expected: 8, got: 3 }
|
||||
MembershipError::MaskSize {
|
||||
instance: 0,
|
||||
expected: 8,
|
||||
got: 3
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -403,12 +426,8 @@ mod tests {
|
||||
fn different_instances_repel() {
|
||||
let f = field();
|
||||
let right_half = vec![0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0];
|
||||
let m = Membership::compute(
|
||||
&f,
|
||||
&[&left_half(), &right_half],
|
||||
&PriorOptions::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let m = Membership::compute(&f, &[&left_half(), &right_half], &PriorOptions::default())
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(m.instance_of(0), Some(0));
|
||||
assert_eq!(m.instance_of(2), Some(1));
|
||||
|
||||
@@ -357,7 +357,6 @@ impl SemanticModel {
|
||||
options,
|
||||
))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Turn one forward pass into instances in source-image space.
|
||||
@@ -543,7 +542,11 @@ fn assemble_mask(
|
||||
let (gx1, gy1) = ((gx0 + 1).min(pw - 1), (gy0 + 1).min(ph - 1));
|
||||
|
||||
let mut acc = 0.0;
|
||||
for (k, &c) in coeffs.iter().enumerate().take(PROTOTYPES.min(protos.shape()[0])) {
|
||||
for (k, &c) in coeffs
|
||||
.iter()
|
||||
.enumerate()
|
||||
.take(PROTOTYPES.min(protos.shape()[0]))
|
||||
{
|
||||
if c == 0.0 {
|
||||
continue;
|
||||
}
|
||||
@@ -643,7 +646,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn letterbox_round_trips_a_landscape_window() {
|
||||
let window = Window { x: 0.0, y: 0.0, w: 1600.0, h: 1067.0 };
|
||||
let window = Window {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
w: 1600.0,
|
||||
h: 1067.0,
|
||||
};
|
||||
let lb = Letterbox::fit(window.w, window.h);
|
||||
|
||||
// A source point maps into the input and back to where it started.
|
||||
|
||||
Reference in New Issue
Block a user