summaryrefslogtreecommitdiff
path: root/src/geom/length.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/geom/length.rs')
-rw-r--r--src/geom/length.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/geom/length.rs b/src/geom/length.rs
index 230ea48b..ae615f14 100644
--- a/src/geom/length.rs
+++ b/src/geom/length.rs
@@ -18,6 +18,12 @@ impl Length {
Self { abs: Abs::zero(), em: Em::zero() }
}
+ /// Try to compute the absolute value of the length.
+ pub fn try_abs(self) -> Option<Self> {
+ (self.abs.is_zero() || self.em.is_zero())
+ .then(|| Self { abs: self.abs.abs(), em: self.em.abs() })
+ }
+
/// Try to divide two lengths.
pub fn try_div(self, other: Self) -> Option<f64> {
if self.abs.is_zero() && other.abs.is_zero() {