diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-12-20 16:08:16 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-12-20 16:11:37 +0100 |
| commit | f5f7df7247ae29800e0290774a50942e2485beea (patch) | |
| tree | 57253ba51efdae3ac8e4eea722428924625b514c /src/geom | |
| parent | b8ffd3ad3dcaebddbc674e03494e0d818b21fa51 (diff) | |
Documentation
Diffstat (limited to 'src/geom')
| -rw-r--r-- | src/geom/em.rs | 5 | ||||
| -rw-r--r-- | src/geom/length.rs | 6 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/geom/em.rs b/src/geom/em.rs index 93dc80e4..9f5aff39 100644 --- a/src/geom/em.rs +++ b/src/geom/em.rs @@ -42,6 +42,11 @@ impl Em { (self.0).0 } + /// The absolute value of this em length. + pub fn abs(self) -> Self { + Self::new(self.get().abs()) + } + /// Convert to an absolute length at the given font size. pub fn at(self, font_size: Abs) -> Abs { let resolved = font_size * self.get(); 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() { |
