From 88da1aa58233fccea3a6f18bc45f29583db4b32b Mon Sep 17 00:00:00 2001 From: numzero Date: Sat, 14 Sep 2024 22:50:42 +0300 Subject: [PATCH] Allow using Decomp2 like a matrix --- src/bin/flat/main.rs | 4 ++-- src/bin/flat/riemann.rs | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/bin/flat/main.rs b/src/bin/flat/main.rs index 283f2f9..abfe156 100644 --- a/src/bin/flat/main.rs +++ b/src/bin/flat/main.rs @@ -153,8 +153,8 @@ fn rel_to_abs(space: &impl Metric, base: &Location, rel: Vec2, steps: usize) -> /// Converts a position and a rotation to a [Location]. Only the X direction is preserved from `rot` to ensure the resulting Location describes an orthonormal coordinate system. fn put_object(space: &impl Metric, pos: Vec2, rot: Mat2) -> Location { - let metric_sqrt = Mat2::from(space.sqrt_at(pos)); - let metric_inv_sqrt = Mat2::from(space.sqrt_at(pos).inverse()); + let metric_sqrt = space.sqrt_at(pos); + let metric_inv_sqrt = space.sqrt_at(pos).inverse(); let rot = metric_inv_sqrt * (metric_sqrt * rot).orthonormalize(); Location { pos, rot } } diff --git a/src/bin/flat/riemann.rs b/src/bin/flat/riemann.rs index bb8fe76..f8b232c 100644 --- a/src/bin/flat/riemann.rs +++ b/src/bin/flat/riemann.rs @@ -22,6 +22,17 @@ impl Decomp2 { } } +impl std::ops::Mul for Decomp2 +where + Mat2: std::ops::Mul, +{ + type Output = >::Output; + + fn mul(self, rhs: T) -> Self::Output { + Mat2::from(self) * rhs + } +} + impl From for Mat2 { fn from(value: Decomp2) -> Self { value.ortho.transpose() * Mat2::from_diagonal(value.diag) * value.ortho