diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-08-30 16:59:09 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-08-30 16:59:09 +0200 |
| commit | ee84bf74083f5b9cc88a2a0a968dc905b1eef22c (patch) | |
| tree | d2756f462ee242c328c526d2a65de4105830cb27 /src/geom | |
| parent | ff25573224400673d08b31e576d5a0d87751dbe1 (diff) | |
Add abs() function
Diffstat (limited to 'src/geom')
| -rw-r--r-- | src/geom/angle.rs | 5 | ||||
| -rw-r--r-- | src/geom/fr.rs | 5 | ||||
| -rw-r--r-- | src/geom/length.rs | 5 | ||||
| -rw-r--r-- | src/geom/relative.rs | 5 |
4 files changed, 20 insertions, 0 deletions
diff --git a/src/geom/angle.rs b/src/geom/angle.rs index 023b1d98..b6fa3f41 100644 --- a/src/geom/angle.rs +++ b/src/geom/angle.rs @@ -50,6 +50,11 @@ impl Angle { pub fn to_unit(self, unit: AngularUnit) -> f64 { self.to_raw() / unit.raw_scale() } + + /// The absolute value of the this angle. + pub fn abs(self) -> Self { + Self::raw(self.to_raw().abs()) + } } impl Debug for Angle { diff --git a/src/geom/fr.rs b/src/geom/fr.rs index ed0c8329..5f3e5534 100644 --- a/src/geom/fr.rs +++ b/src/geom/fr.rs @@ -29,6 +29,11 @@ impl Fractional { pub fn is_zero(self) -> bool { self.0 == 0.0 } + + /// The absolute value of the this fractional. + pub fn abs(self) -> Self { + Self::new(self.get().abs()) + } } impl Debug for Fractional { diff --git a/src/geom/length.rs b/src/geom/length.rs index f8484f75..b9eb7b75 100644 --- a/src/geom/length.rs +++ b/src/geom/length.rs @@ -92,6 +92,11 @@ impl Length { self.0.into_inner().is_infinite() } + /// The absolute value of the this length. + pub fn abs(self) -> Self { + Self::raw(self.to_raw().abs()) + } + /// The minimum of this and another length. pub fn min(self, other: Self) -> Self { Self(self.0.min(other.0)) diff --git a/src/geom/relative.rs b/src/geom/relative.rs index 056af206..9122af84 100644 --- a/src/geom/relative.rs +++ b/src/geom/relative.rs @@ -42,6 +42,11 @@ impl Relative { pub fn is_zero(self) -> bool { self.0 == 0.0 } + + /// The absolute value of the this relative. + pub fn abs(self) -> Self { + Self::new(self.get().abs()) + } } impl Debug for Relative { |
