This commit is contained in:
numzero 2024-04-28 23:37:05 +03:00
parent a836e7f847
commit 9ce8da5f38

View File

@ -86,19 +86,39 @@ mod riemann {
pub diag: Vec2, pub diag: Vec2,
} }
impl Decomp2 {
fn square(&self) -> Self {
Self {
ortho: self.ortho,
diag: pow2(self.diag),
}
}
fn inverse(&self) -> Self {
Self {
ortho: self.ortho,
diag: Vec2::from_s(1.0) / self.diag,
}
}
}
impl From<Decomp2> for Mat2 {
fn from(value: Decomp2) -> Self {
transpose(&value.ortho) * diagonal(value.diag) * value.ortho
}
}
type Tens2 = [Mat2; 2]; type Tens2 = [Mat2; 2];
pub trait Metric { pub trait Metric {
fn halfmetric(&self, pos: Vec2) -> Decomp2; fn halfmetric(&self, pos: Vec2) -> Decomp2;
fn metric(&self, pos: Vec2) -> Mat2 { fn metric(&self, pos: Vec2) -> Mat2 {
let h = self.halfmetric(pos); self.halfmetric(pos).square().into()
transpose(&h.ortho) * diagonal(pow2(h.diag)) * h.ortho
} }
fn invmetric(&self, pos: Vec2) -> Mat2 { fn invmetric(&self, pos: Vec2) -> Mat2 {
let h = self.halfmetric(pos); self.halfmetric(pos).square().inverse().into()
transpose(&h.ortho) * diagonal(Vec2::from_s(1.0) / pow2(h.diag)) * h.ortho
} }
fn dmetric(&self, pos: Vec2) -> Tens2 { fn dmetric(&self, pos: Vec2) -> Tens2 {
@ -114,8 +134,7 @@ mod riemann {
} }
fn globalize(&self, at: Vec2, v: Vec2) -> Vec2 { fn globalize(&self, at: Vec2, v: Vec2) -> Vec2 {
let h = self.halfmetric(at); Mat2::from(self.halfmetric(at).inverse()) * v
transpose(&h.ortho) * diagonal(Vec2::from_s(1.0) / h.diag) * h.ortho * v
} }
} }