Skip to content

Commit

Permalink
Add fractional angle conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Sep 4, 2024
1 parent 81aac8c commit a1c4390
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nuit-core/src/utils/angle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ impl Angle {
Self::with_radians(degrees * PI / 180.0)
}

/// Creates an angle from the given fractional value between 0 and 1.
pub const fn with_fractional(fractional: f64) -> Self {
Self::with_radians(fractional * 2.0 * PI)
}

/// The value in radians.
pub fn radians(self) -> f64 {
self.radians
Expand All @@ -34,6 +39,11 @@ impl Angle {
pub fn degrees(self) -> f64 {
self.radians * 180.0 / PI
}

/// The fractional value between 0 and 1.
pub fn fractional(self) -> f64 {
self.radians / (2.0 * PI)
}
}

impl Add for Angle {
Expand Down

0 comments on commit a1c4390

Please sign in to comment.