36 lines
840 B
Rust
36 lines
840 B
Rust
|
use std::f32::consts::PI;
|
||
|
|
||
|
/// Convert degrees to radians
|
||
|
pub fn degrees_to_radians(degrees: f32) -> f32 {
|
||
|
degrees * PI / 180.0
|
||
|
}
|
||
|
|
||
|
/// Convert radians to degrees
|
||
|
pub fn radians_to_degrees(radians: f32) -> f32 {
|
||
|
radians * 180.0 / PI
|
||
|
}
|
||
|
|
||
|
pub enum Angle {
|
||
|
Degrees(f32),
|
||
|
Radians(f32),
|
||
|
}
|
||
|
|
||
|
impl Angle {
|
||
|
/// Converts Angle to radians.
|
||
|
/// (conversion is only done if the Angle is in degrees).
|
||
|
pub fn to_radians(&self) -> f32 {
|
||
|
match *self {
|
||
|
Self::Degrees(d) => degrees_to_radians(d),
|
||
|
Self::Radians(r) => r,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// Converts Angle to degrees.
|
||
|
/// (conversion is only done if the Angle is in radians).
|
||
|
pub fn to_degrees(&self) -> f32 {
|
||
|
match *self {
|
||
|
Self::Degrees(d) => d,
|
||
|
Self::Radians(r) => radians_to_degrees(r),
|
||
|
}
|
||
|
}
|
||
|
}
|