summaryrefslogtreecommitdiff
path: root/src/geom
diff options
context:
space:
mode:
Diffstat (limited to 'src/geom')
-rw-r--r--src/geom/em.rs2
-rw-r--r--src/geom/linear.rs15
2 files changed, 12 insertions, 5 deletions
diff --git a/src/geom/em.rs b/src/geom/em.rs
index 05d1d7d5..1868222f 100644
--- a/src/geom/em.rs
+++ b/src/geom/em.rs
@@ -29,7 +29,7 @@ impl Em {
}
/// Convert to a length at the given font size.
- pub fn to_length(self, font_size: Length) -> Length {
+ pub fn resolve(self, font_size: Length) -> Length {
self.get() * font_size
}
diff --git a/src/geom/linear.rs b/src/geom/linear.rs
index 77923c43..78602d8b 100644
--- a/src/geom/linear.rs
+++ b/src/geom/linear.rs
@@ -36,6 +36,16 @@ impl Linear {
self.rel.resolve(length) + self.abs
}
+ /// Compose with another linear.
+ ///
+ /// The resulting linear is (self ∘ inner)(x) = self(inner(x)).
+ pub fn compose(self, inner: Self) -> Self {
+ Self {
+ rel: self.rel * inner.rel,
+ abs: self.rel.resolve(inner.abs) + self.abs,
+ }
+ }
+
/// Whether both parts are zero.
pub fn is_zero(self) -> bool {
self.rel.is_zero() && self.abs.is_zero()
@@ -155,10 +165,7 @@ impl Mul<Linear> for f64 {
type Output = Linear;
fn mul(self, other: Linear) -> Linear {
- Linear {
- rel: self * other.rel,
- abs: self * other.abs,
- }
+ other * self
}
}