diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-12-15 11:11:57 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-12-15 11:11:57 +0100 |
| commit | ae38be9097bbb32142ef776e77e627ac12379000 (patch) | |
| tree | f365a348d4c77d2d607d37fee3bc65a601d00a64 /src/geom | |
| parent | fe21c4d399d291e75165b664762f0aa8bdc4724a (diff) | |
Set Rules Episode IV: A New Fold
Diffstat (limited to 'src/geom')
| -rw-r--r-- | src/geom/em.rs | 2 | ||||
| -rw-r--r-- | src/geom/linear.rs | 15 |
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 } } |
