Skip to content

Commit

Permalink
Split angle into separate mod
Browse files Browse the repository at this point in the history
  • Loading branch information
bitshifter committed Mar 31, 2019
1 parent c2e914b commit c1510d0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 40 deletions.
42 changes: 42 additions & 0 deletions src/f32/angle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use crate::f32::scalar_sin_cos;

#[derive(Copy, Clone, Debug)]
pub struct Angle(f32);

impl Angle {
#[inline]
pub fn from_radians(a: f32) -> Angle {
Angle(a)
}

#[inline]
pub fn from_degrees(a: f32) -> Angle {
Angle(a.to_radians())
}

#[inline]
pub fn as_radians(self) -> f32 {
self.0
}

#[inline]
pub fn as_degrees(self) -> f32 {
self.0.to_degrees()
}

#[inline]
pub fn sin_cos(self) -> (f32, f32) {
scalar_sin_cos(self.0)
}
}

#[inline]
pub fn rad(a: f32) -> Angle {
Angle::from_radians(a)
}

#[inline]
pub fn deg(a: f32) -> Angle {
Angle::from_degrees(a)
}

43 changes: 3 additions & 40 deletions src/f32/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
mod angle;
pub use angle::*;

#[cfg(all(target_feature = "sse2", not(feature = "no-simd")))]
mod vec3_f32x4;
#[cfg(all(target_feature = "sse2", not(feature = "no-simd")))]
Expand Down Expand Up @@ -37,46 +40,6 @@ pub use glam_serde::*;

use std::mem;

#[derive(Copy, Clone, Debug)]
pub struct Angle(f32);

impl Angle {
#[inline]
pub fn from_radians(a: f32) -> Angle {
Angle(a)
}

#[inline]
pub fn from_degrees(a: f32) -> Angle {
Angle(a.to_radians())
}

#[inline]
pub fn as_radians(self) -> f32 {
self.0
}

#[inline]
pub fn as_degrees(self) -> f32 {
self.0.to_degrees()
}

#[inline]
pub fn sin_cos(self) -> (f32, f32) {
scalar_sin_cos(self.0)
}
}

#[inline]
pub fn rad(a: f32) -> Angle {
Angle::from_radians(a)
}

#[inline]
pub fn deg(a: f32) -> Angle {
Angle::from_degrees(a)
}

impl AsRef<[f32; 2]> for Vec2 {
#[inline]
fn as_ref(&self) -> &[f32; 2] {
Expand Down

0 comments on commit c1510d0

Please sign in to comment.