Skip to content

Commit 9c88493

Browse files
committed
Assertions
1 parent df8c8ea commit 9c88493

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

src/kmeans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ impl Kmeans {
9494
if adjust_weight {
9595
let remapped = colors[matched as usize];
9696
let (_, new_diff) = n.search(&f_pixel(px.0 + px.0 - remapped.0), matched);
97+
debug_assert!(new_diff.is_finite());
9798
diff = new_diff;
9899
item.adjusted_weight = 2.0f32.mul_add(item.adjusted_weight, item.perceptual_weight) * (0.5 + diff);
99100
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,15 @@ impl Ord for OrdFloat<f64> {
311311
}
312312

313313
impl OrdFloat<f32> {
314+
#[cfg_attr(debug_assertions, track_caller)]
314315
pub fn new(v: f32) -> Self {
315316
debug_assert!(v.is_finite());
316317
Self(v)
317318
}
318319
}
319320

320321
impl OrdFloat<f64> {
322+
#[cfg_attr(debug_assertions, track_caller)]
321323
pub fn new64(v: f64) -> Self {
322324
debug_assert!(v.is_finite());
323325
Self(v)

src/mediancut.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl<'hist> MBox<'hist> {
4242

4343
fn new_inner(hist: &'hist mut [HistItem], adjusted_weight_sum: f64, avg_color: f_pixel) -> Self {
4444
let (variance, max_error) = Self::box_stats(hist, avg_color);
45+
debug_assert!(adjusted_weight_sum.is_finite());
4546
Self {
4647
variance,
4748
max_error,
@@ -311,6 +312,7 @@ fn weighed_average_color(hist: &[HistItem]) -> f_pixel {
311312
sum += c.adjusted_weight;
312313
t.0 += c.color.0 * c.adjusted_weight;
313314
}
315+
debug_assert!(sum.is_finite());
314316
if sum != 0. {
315317
t.0 /= sum;
316318
}

0 commit comments

Comments
 (0)