mirror of
https://github.com/italicsjenga/valence.git
synced 2025-01-27 05:56:33 +11:00
Implement radians conversions for ByteAngle (#149)
Adds `from_radians` function and `to_radians` method for `ByteAngle`.
This commit is contained in:
parent
ff136c2a4a
commit
bb43856c9e
1 changed files with 9 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue