Extract Decomp2 to mathx

This commit is contained in:
numzero 2024-09-15 10:03:38 +03:00
parent 43b0eb5836
commit f57ef1c141
3 changed files with 45 additions and 42 deletions

View File

@ -1,43 +1,5 @@
use glam::*; use glam::*;
use refraction::mathx::Decomp2;
#[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
}
}
pub type Tens2 = [Mat2; 2]; pub type Tens2 = [Mat2; 2];

View File

@ -1,7 +1,8 @@
use glam::{f32, vec2, Mat2, Vec2}; use glam::{f32, vec2, Mat2, Vec2};
use refraction::mathx::Decomp2;
use crate::fns::{self, Limiter}; use crate::fns::{self, Limiter};
use crate::riemann::{Decomp2, Metric, Tens2}; use crate::riemann::{Metric, Tens2};
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub struct Tube { pub struct Tube {
@ -74,9 +75,10 @@ mod test {
use glam::{vec2, Vec2}; use glam::{vec2, Vec2};
use itertools_num::linspace; use itertools_num::linspace;
use crate::riemann::{Decomp2, Metric}; use crate::riemann::Metric;
use crate::tube::Space; use crate::tube::Space;
use crate::types::Ray; use crate::types::Ray;
use refraction::mathx::Decomp2;
use super::Tube; use super::Tube;

View File

@ -1,4 +1,4 @@
use glam::{FloatExt, Mat2, Mat3}; use glam::{FloatExt, Mat2, Mat3, Vec2};
mod bounds { mod bounds {
pub trait Pair<T> {} 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)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;