File tree 1 file changed +20
-1
lines changed
1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -163,7 +163,7 @@ macro_rules! impl_from_angle_u8 {
163
163
#[ inline]
164
164
fn from_angle( angle: $float_ty) -> Self {
165
165
let normalized = angle. normalize_unsigned_angle( ) / $float_ty:: full_rotation( ) ;
166
- let rounded = normalized. round( ) ;
166
+ let rounded = ( normalized * 256.0 ) . round( ) ;
167
167
168
168
if rounded > 255.5 {
169
169
0
@@ -201,3 +201,22 @@ impl UnsignedAngle for u8 {
201
201
self
202
202
}
203
203
}
204
+
205
+ #[ cfg( test) ]
206
+ mod test {
207
+ use crate :: RgbHue ;
208
+
209
+ #[ test]
210
+ fn f32_to_u8 ( ) {
211
+ let hue_f32 = RgbHue :: new ( 180.0f32 ) ;
212
+ let hue_u8 = hue_f32. into_format :: < u8 > ( ) ;
213
+ assert_eq ! ( hue_u8, RgbHue :: new( 128u8 ) ) ;
214
+ }
215
+
216
+ #[ test]
217
+ fn u8_to_f32 ( ) {
218
+ let hue_f32 = RgbHue :: new ( 128u8 ) ;
219
+ let hue_u8 = hue_f32. into_format :: < f32 > ( ) ;
220
+ assert_eq ! ( hue_u8, RgbHue :: new( 180.0f32 ) ) ;
221
+ }
222
+ }
You can’t perform that action at this time.
0 commit comments