Extract Decomp2 to mathx
This commit is contained in:
parent
43b0eb5836
commit
f57ef1c141
|
|
@ -1,43 +1,5 @@
|
|||
use glam::*;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub struct Decomp2 {
|
||||
pub ortho: Mat2,
|
||||
pub diag: Vec2,
|
||||
}
|
||||
|
||||
impl Decomp2 {
|
||||
fn square(&self) -> Self {
|
||||
Self {
|
||||
ortho: self.ortho,
|
||||
diag: self.diag * self.diag,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inverse(&self) -> Self {
|
||||
Self {
|
||||
ortho: self.ortho,
|
||||
diag: Vec2::splat(1.0) / self.diag,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
fn from(value: Decomp2) -> Self {
|
||||
value.ortho.transpose() * Mat2::from_diagonal(value.diag) * value.ortho
|
||||
}
|
||||
}
|
||||
use refraction::mathx::Decomp2;
|
||||
|
||||
pub type Tens2 = [Mat2; 2];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use glam::{f32, vec2, Mat2, Vec2};
|
||||
use refraction::mathx::Decomp2;
|
||||
|
||||
use crate::fns::{self, Limiter};
|
||||
use crate::riemann::{Decomp2, Metric, Tens2};
|
||||
use crate::riemann::{Metric, Tens2};
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct Tube {
|
||||
|
|
@ -74,9 +75,10 @@ mod test {
|
|||
use glam::{vec2, Vec2};
|
||||
use itertools_num::linspace;
|
||||
|
||||
use crate::riemann::{Decomp2, Metric};
|
||||
use crate::riemann::Metric;
|
||||
use crate::tube::Space;
|
||||
use crate::types::Ray;
|
||||
use refraction::mathx::Decomp2;
|
||||
|
||||
use super::Tube;
|
||||
|
||||
|
|
|
|||
41
src/mathx.rs
41
src/mathx.rs
|
|
@ -1,4 +1,4 @@
|
|||
use glam::{FloatExt, Mat2, Mat3};
|
||||
use glam::{FloatExt, Mat2, Mat3, Vec2};
|
||||
|
||||
mod bounds {
|
||||
pub trait Pair<T> {}
|
||||
|
|
@ -44,6 +44,45 @@ impl MatExt for Mat3 {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub struct Decomp2 {
|
||||
pub ortho: Mat2,
|
||||
pub diag: Vec2,
|
||||
}
|
||||
|
||||
impl Decomp2 {
|
||||
pub fn square(&self) -> Self {
|
||||
Self {
|
||||
ortho: self.ortho,
|
||||
diag: self.diag * self.diag,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inverse(&self) -> Self {
|
||||
Self {
|
||||
ortho: self.ortho,
|
||||
diag: Vec2::splat(1.0) / self.diag,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Decomp2> for Mat2 {
|
||||
fn from(value: Decomp2) -> Self {
|
||||
value.ortho.transpose() * Mat2::from_diagonal(value.diag) * value.ortho
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user