summaryrefslogtreecommitdiff
path: root/src/geom/linear.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-12-15 11:11:57 +0100
committerLaurenz <laurmaedje@gmail.com>2021-12-15 11:11:57 +0100
commitae38be9097bbb32142ef776e77e627ac12379000 (patch)
treef365a348d4c77d2d607d37fee3bc65a601d00a64 /src/geom/linear.rs
parentfe21c4d399d291e75165b664762f0aa8bdc4724a (diff)
Set Rules Episode IV: A New Fold
Diffstat (limited to 'src/geom/linear.rs')
-rw-r--r--src/geom/linear.rs15
1 files changed, 11 insertions, 4 deletions
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
}
}