Skip to content

Commit e37a385

Browse files
PeterHatchOgeon
authored andcommitted
Round to nearest instead of down when converting components to integers.
1 parent 435b06d commit e37a385

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

palette/src/convert.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ use encoding::Linear;
204204
/// assert_eq!(
205205
/// css_color,
206206
/// CssRgb {
207-
/// red: 187,
207+
/// red: 188,
208208
/// green: 0,
209-
/// blue: 254,
209+
/// blue: 255,
210210
/// alpha: 0.3,
211211
/// }
212212
/// );
@@ -338,7 +338,7 @@ where
338338
/// // Convert the color to sRGB.
339339
/// let rgb: Srgb = xyz.into();
340340
///
341-
/// assert_eq!(rgb.into_format(), Srgb::new(195u8, 237, 154));
341+
/// assert_eq!(rgb.into_format(), Srgb::new(196u8, 238, 154));
342342
/// }
343343
/// ```
344344
///

palette/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl Component for f32 {
550550
let scaled = *self * cast::<f32, _>(T::max_intensity());
551551

552552
if T::LIMITED {
553-
cast(clamp(scaled, 0.0, cast(T::max_intensity())))
553+
cast(clamp(scaled.round(), 0.0, cast(T::max_intensity())))
554554
} else {
555555
cast(scaled)
556556
}
@@ -568,7 +568,7 @@ impl Component for f64 {
568568
let scaled = *self * cast::<f64, _>(T::max_intensity());
569569

570570
if T::LIMITED {
571-
cast(clamp(scaled, 0.0, cast(T::max_intensity())))
571+
cast(clamp(scaled.round(), 0.0, cast(T::max_intensity())))
572572
} else {
573573
cast(scaled)
574574
}
@@ -587,7 +587,7 @@ impl Component for u8 {
587587
* (cast::<f64, _>(*self) / cast::<f64, _>(Self::max_intensity()));
588588

589589
if T::LIMITED {
590-
cast(clamp(scaled, 0.0, cast(T::max_intensity())))
590+
cast(clamp(scaled.round(), 0.0, cast(T::max_intensity())))
591591
} else {
592592
cast(scaled)
593593
}
@@ -606,7 +606,7 @@ impl Component for u16 {
606606
* (cast::<f64, _>(*self) / cast::<f64, _>(Self::max_intensity()));
607607

608608
if T::LIMITED {
609-
cast(clamp(scaled, 0.0, cast(T::max_intensity())))
609+
cast(clamp(scaled.round(), 0.0, cast(T::max_intensity())))
610610
} else {
611611
cast(scaled)
612612
}
@@ -625,7 +625,7 @@ impl Component for u32 {
625625
* (cast::<f64, _>(*self) / cast::<f64, _>(Self::max_intensity()));
626626

627627
if T::LIMITED {
628-
cast(clamp(scaled, 0.0, cast(T::max_intensity())))
628+
cast(clamp(scaled.round(), 0.0, cast(T::max_intensity())))
629629
} else {
630630
cast(scaled)
631631
}
@@ -644,7 +644,7 @@ impl Component for u64 {
644644
* (cast::<f64, _>(*self) / cast::<f64, _>(Self::max_intensity()));
645645

646646
if T::LIMITED {
647-
cast(clamp(scaled, 0.0, cast(T::max_intensity())))
647+
cast(clamp(scaled.round(), 0.0, cast(T::max_intensity())))
648648
} else {
649649
cast(scaled)
650650
}

0 commit comments

Comments
 (0)