@@ -40,14 +40,14 @@ impl<'hist> MBox<'hist> {
40
40
let mut avg_color = weighed_average_color ( hist) ;
41
41
// It's possible that an average color will end up being bad for every entry,
42
42
// so prefer picking actual colors so that at least one histogram entry will be satisfied.
43
- if ( hist. len ( ) < 500 && hist. len ( ) > 2 ) || Self :: is_useless_color ( & avg_color, hist, other_boxes) {
43
+ if ( hist. len ( ) < 500 && hist. len ( ) > 2 ) || Self :: is_useless_color ( avg_color, hist, other_boxes) {
44
44
avg_color = hist. iter ( ) . min_by_key ( |a| OrdFloat :: new ( avg_color. diff ( & a. color ) ) ) . map ( |a| a. color ) . unwrap_or_default ( ) ;
45
45
}
46
46
Self :: new_c ( hist, adjusted_weight_sum, avg_color)
47
47
}
48
48
49
49
fn new_c ( hist : & ' hist mut [ HistItem ] , adjusted_weight_sum : f64 , avg_color : f_pixel ) -> Self {
50
- let ( variance, max_error) = Self :: box_stats ( hist, & avg_color) ;
50
+ let ( variance, max_error) = Self :: box_stats ( hist, avg_color) ;
51
51
Self {
52
52
variance,
53
53
max_error,
@@ -59,7 +59,7 @@ impl<'hist> MBox<'hist> {
59
59
}
60
60
61
61
/// It's possible that the average color is useless
62
- fn is_useless_color ( new_avg_color : & f_pixel , colors : & [ HistItem ] , other_boxes : & [ MBox < ' _ > ] ) -> bool {
62
+ fn is_useless_color ( new_avg_color : f_pixel , colors : & [ HistItem ] , other_boxes : & [ MBox < ' _ > ] ) -> bool {
63
63
colors. iter ( ) . all ( move |c| {
64
64
let own_box_diff = new_avg_color. diff ( & c. color ) ;
65
65
let other_box_is_better = other_boxes. iter ( )
@@ -69,7 +69,7 @@ impl<'hist> MBox<'hist> {
69
69
} )
70
70
}
71
71
72
- fn box_stats ( hist : & [ HistItem ] , avg_color : & f_pixel ) -> ( ARGBF , f32 ) {
72
+ fn box_stats ( hist : & [ HistItem ] , avg_color : f_pixel ) -> ( ARGBF , f32 ) {
73
73
let mut variance = ARGBF :: default ( ) ;
74
74
let mut max_error = 0. ;
75
75
for a in hist {
@@ -278,9 +278,8 @@ impl<'hist> MedianCutter<'hist> {
278
278
// later raises the limit to allow large smooth areas/gradients get colors.
279
279
let fraction_done = self . boxes . len ( ) as f64 / f64:: from ( self . target_colors ) ;
280
280
let current_max_mse = ( fraction_done * 16. ) . mul_add ( max_mse, max_mse) ;
281
- let bi = match self . take_best_splittable_box ( current_max_mse) {
282
- Some ( bi) => bi,
283
- None => break ,
281
+ let Some ( bi) = self . take_best_splittable_box ( current_max_mse) else {
282
+ break
284
283
} ;
285
284
286
285
self . boxes . extend ( bi. split ( & self . boxes ) ) ;
0 commit comments