From cac060a67bfac7b4d2aba9ea459b11a5968c42a7 Mon Sep 17 00:00:00 2001 From: Paris DOUADY Date: Wed, 5 Jun 2024 21:11:16 +0200 Subject: [PATCH] inline angle --- geom/src/angle.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/geom/src/angle.rs b/geom/src/angle.rs index 5582cec0..7388beee 100644 --- a/geom/src/angle.rs +++ b/geom/src/angle.rs @@ -19,6 +19,7 @@ impl Radians { pub const TAU: Self = Radians(TAU); pub const ZERO: Self = Radians(0.0); + #[inline] pub fn vec2(self) -> Vec2 { Vec2 { x: self.0.cos(), @@ -26,56 +27,69 @@ impl Radians { } } + #[inline] pub fn from_deg(deg: f32) -> Self { Self(deg * (PI / 180.0)) } + #[inline] pub fn normalize(&mut self) { self.0 %= TAU; } + #[inline] pub fn cos(self) -> f32 { self.0.cos() } + #[inline] pub fn sin(self) -> f32 { self.0.sin() } + #[inline] pub fn min(self, other: Self) -> Self { Self(self.0.min(other.0)) } + #[inline] pub fn max(self, other: Self) -> Self { Self(self.0.max(other.0)) } + #[inline] pub fn to_degrees(self) -> Degrees { Degrees(self.0 * (180.0 / PI)) } } impl Degrees { + #[inline] pub fn vec2(self) -> Vec2 { Radians::from(self).vec2() } + #[inline] pub fn normalize(&mut self) { self.0 %= 360.0; } + #[inline] pub fn min(self, other: Self) -> Self { Self(self.0.min(other.0)) } + #[inline] pub fn max(self, other: Self) -> Self { Self(self.0.max(other.0)) } + #[inline] pub fn to_radians(self) -> Radians { Radians(self.0 * (PI / 180.0)) } + #[inline] pub fn from_rad(rad: f32) -> Self { Self(rad * (180.0 / PI)) } @@ -146,12 +160,14 @@ impl AddAssign for Radians { } impl From for Degrees { + #[inline] fn from(r: Radians) -> Self { Self(r.0 * (180.0 / PI)) } } impl From for Radians { + #[inline] fn from(r: Degrees) -> Self { Self(r.0 * (PI / 180.0)) } @@ -160,6 +176,7 @@ impl From for Radians { impl Mul for Radians { type Output = Self; + #[inline] fn mul(self, rhs: f32) -> Self::Output { Self(self.0 * rhs) } @@ -168,30 +185,35 @@ impl Mul for Radians { impl Neg for Radians { type Output = Self; + #[inline] fn neg(self) -> Self::Output { Self(-self.0) } } impl From for Radians { + #[inline] fn from(v: f32) -> Self { Self(v) } } impl From for Degrees { + #[inline] fn from(v: f32) -> Self { Self(v) } } impl From for f32 { + #[inline] fn from(d: Degrees) -> Self { d.0 } } impl From for f32 { + #[inline] fn from(r: Radians) -> Self { r.0 }