diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-06-11 11:30:18 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-06-11 11:30:18 +0200 |
| commit | 3330767c20e14a05176902a93dcefb08cb509173 (patch) | |
| tree | eb40b262d267df0e9f73bbbc4ec602183fd39dff /src/geom | |
| parent | c28708aa196eaca247cdab6b5e8af9751b4f1dad (diff) | |
Remove props in favor of using state for everything
Diffstat (limited to 'src/geom')
| -rw-r--r-- | src/geom/angle.rs | 21 | ||||
| -rw-r--r-- | src/geom/point.rs | 2 | ||||
| -rw-r--r-- | src/geom/size.rs | 2 | ||||
| -rw-r--r-- | src/geom/spec.rs | 2 |
4 files changed, 15 insertions, 12 deletions
diff --git a/src/geom/angle.rs b/src/geom/angle.rs index f1db841c..bf8bcc66 100644 --- a/src/geom/angle.rs +++ b/src/geom/angle.rs @@ -1,15 +1,18 @@ use super::*; +use decorum::N64; /// An angle. -#[derive(Default, Copy, Clone, PartialEq, PartialOrd)] +#[derive(Default, Copy, Clone, PartialEq, PartialOrd, Hash)] pub struct Angle { /// The angle in raw units. - raw: f64, + raw: N64, } impl Angle { /// The zero angle. - pub const ZERO: Self = Self { raw: 0.0 }; + pub fn zero() -> Self { + Self { raw: N64::from(0.0) } + } /// Create an angle from a number of radians. pub fn rad(rad: f64) -> Self { @@ -23,7 +26,7 @@ impl Angle { /// Create an angle from a number of raw units. pub fn raw(raw: f64) -> Self { - Self { raw } + Self { raw: N64::from(raw) } } /// Convert this to a number of radians. @@ -38,17 +41,17 @@ impl Angle { /// Get the value of this angle in raw units. pub fn to_raw(self) -> f64 { - self.raw + self.raw.into() } /// Create an angle from a value in a unit. pub fn with_unit(val: f64, unit: AngularUnit) -> Self { - Self { raw: val * unit.raw_scale() } + Self { raw: N64::from(val * unit.raw_scale()) } } /// Get the value of this length in unit. pub fn to_unit(self, unit: AngularUnit) -> f64 { - self.raw / unit.raw_scale() + self.to_raw() / unit.raw_scale() } } @@ -119,7 +122,7 @@ impl Div for Angle { type Output = f64; fn div(self, other: Self) -> f64 { - self.raw / other.raw + self.to_raw() / other.to_raw() } } @@ -130,7 +133,7 @@ assign_impl!(Angle /= f64); impl Sum for Angle { fn sum<I: Iterator<Item = Angle>>(iter: I) -> Self { - iter.fold(Angle::ZERO, Add::add) + iter.fold(Angle::zero(), Add::add) } } /// Different units of angular measurement. diff --git a/src/geom/point.rs b/src/geom/point.rs index 8982dcea..129205f1 100644 --- a/src/geom/point.rs +++ b/src/geom/point.rs @@ -3,7 +3,7 @@ use super::*; use serde::{Deserialize, Serialize}; /// A point in 2D. -#[derive(Default, Copy, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Default, Copy, Clone, PartialEq, Serialize, Deserialize, Hash)] pub struct Point { /// The x coordinate. pub x: Length, diff --git a/src/geom/size.rs b/src/geom/size.rs index b859cb80..ea522091 100644 --- a/src/geom/size.rs +++ b/src/geom/size.rs @@ -3,7 +3,7 @@ use super::*; use serde::{Deserialize, Serialize}; /// A size in 2D. -#[derive(Default, Copy, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Default, Copy, Clone, PartialEq, Serialize, Deserialize, Hash)] pub struct Size { /// The width. pub width: Length, diff --git a/src/geom/spec.rs b/src/geom/spec.rs index e7a2d056..782cf0f6 100644 --- a/src/geom/spec.rs +++ b/src/geom/spec.rs @@ -1,7 +1,7 @@ use super::*; /// A container with a horizontal and vertical component. -#[derive(Default, Copy, Clone, Eq, PartialEq)] +#[derive(Default, Copy, Clone, Eq, PartialEq, Hash)] pub struct Spec<T> { /// The horizontal component. pub horizontal: T, |
