Allow using Decomp2 like a matrix

This commit is contained in:
numzero 2024-09-14 22:50:42 +03:00
parent 529d4ac7db
commit 88da1aa582
2 changed files with 13 additions and 2 deletions

View File

@ -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. /// 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 { fn put_object(space: &impl Metric, pos: Vec2, rot: Mat2) -> Location {
let metric_sqrt = Mat2::from(space.sqrt_at(pos)); let metric_sqrt = space.sqrt_at(pos);
let metric_inv_sqrt = Mat2::from(space.sqrt_at(pos).inverse()); let metric_inv_sqrt = space.sqrt_at(pos).inverse();
let rot = metric_inv_sqrt * (metric_sqrt * rot).orthonormalize(); let rot = metric_inv_sqrt * (metric_sqrt * rot).orthonormalize();
Location { pos, rot } Location { pos, rot }
} }

View File

@ -22,6 +22,17 @@ impl Decomp2 {
} }
} }
impl<T> std::ops::Mul<T> for Decomp2
where
Mat2: std::ops::Mul<T>,
{
type Output = <Mat2 as std::ops::Mul<T>>::Output;
fn mul(self, rhs: T) -> Self::Output {
Mat2::from(self) * rhs
}
}
impl From<Decomp2> for Mat2 { impl From<Decomp2> for Mat2 {
fn from(value: Decomp2) -> Self { fn from(value: Decomp2) -> Self {
value.ortho.transpose() * Mat2::from_diagonal(value.diag) * value.ortho value.ortho.transpose() * Mat2::from_diagonal(value.diag) * value.ortho