diff --git a/src/protocol/byte_angle.rs b/src/protocol/byte_angle.rs index 41a7d12..26df73e 100644 --- a/src/protocol/byte_angle.rs +++ b/src/protocol/byte_angle.rs @@ -1,3 +1,4 @@ +use std::f32::consts::TAU; use std::io::Write; use crate::protocol::{Decode, Encode}; @@ -11,9 +12,17 @@ impl ByteAngle { ByteAngle((f.rem_euclid(360.0) / 360.0 * 256.0).round() as u8) } + pub fn from_radians(f: f32) -> ByteAngle { + ByteAngle((f.rem_euclid(TAU) / TAU * 256.0).round() as u8) + } + pub fn to_degrees(self) -> f32 { self.0 as f32 / 256.0 * 360.0 } + + pub fn to_radians(self) -> f32 { + self.0 as f32 / 256.0 * TAU + } } impl Encode for ByteAngle {