pub struct Angle(pub u8);Expand description
A rotation angle encoded in steps of 1/256 of a full turn.
The wire value is a single byte. Because 256 steps represent one full turn, the value wraps around and its signedness does not matter.
§Examples
use mcproto_types::{TypeCodec, basic::Angle};
let angle = Angle(64);
let mut encoded = Vec::new();
angle.encode(&mut encoded)?;
assert_eq!(encoded, [64]);
let mut input = encoded.as_slice();
assert_eq!(Angle::decode(&mut input)?, angle);
assert_eq!(angle.to_degrees(), 90.0);
assert!((angle.to_radians() - std::f64::consts::FRAC_PI_2).abs() < 1e-12);Tuple Fields§
§0: u8The raw angle step count, from 0 through 255.
Implementations§
Source§impl Angle
impl Angle
Sourcepub fn to_degrees(&self) -> f64
pub fn to_degrees(&self) -> f64
Returns the angle in degrees.
A full turn of 256 steps is equivalent to 360 degrees.
Sourcepub fn to_radians(&self) -> f64
pub fn to_radians(&self) -> f64
Returns the angle in radians.
A full turn of 256 steps is equivalent to 2π radians.
Trait Implementations§
impl Copy for Angle
impl Eq for Angle
impl StructuralPartialEq for Angle
Auto Trait Implementations§
impl Freeze for Angle
impl RefUnwindSafe for Angle
impl Send for Angle
impl Sync for Angle
impl Unpin for Angle
impl UnsafeUnpin for Angle
impl UnwindSafe for Angle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more