Unify Ray and Location transforms
This commit is contained in:
parent
150f81f03b
commit
e3d068579c
|
|
@ -185,7 +185,7 @@ fn test_rect() {
|
||||||
|
|
||||||
mod coords {
|
mod coords {
|
||||||
use glam::{Mat2, Vec2, vec2};
|
use glam::{Mat2, Vec2, vec2};
|
||||||
use crate::riemann::Metric;
|
use crate::riemann::{Decomp2, Metric};
|
||||||
use crate::types::{Location, Ray};
|
use crate::types::{Location, Ray};
|
||||||
use super::{Rect, Tube};
|
use super::{Rect, Tube};
|
||||||
|
|
||||||
|
|
@ -199,40 +199,47 @@ mod coords {
|
||||||
fn distance_to_boundary(&self, _ray: Ray) -> Option<f32> { None }
|
fn distance_to_boundary(&self, _ray: Ray) -> Option<f32> { None }
|
||||||
}
|
}
|
||||||
|
|
||||||
trait MetricCS {
|
trait MetricCS: FlatCoordinateSystem<Vec2> {
|
||||||
fn global_metric(&self) -> &impl Metric;
|
fn global_metric(&self) -> &impl Metric;
|
||||||
|
fn sqrt_at_global(&self, pos: Vec2) -> Decomp2 {
|
||||||
|
self.global_metric().sqrt_at(pos)
|
||||||
|
}
|
||||||
|
fn flat_to_global_tfm_at(&self, pos: Vec2) -> Mat2 {
|
||||||
|
self.sqrt_at_global(self.flat_to_global(pos)).inverse().into()
|
||||||
|
}
|
||||||
|
fn global_to_flat_tfm_at(&self, pos: Vec2) -> Mat2 {
|
||||||
|
self.sqrt_at_global(pos).into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: FlatCoordinateSystem<Vec2> + MetricCS> FlatCoordinateSystem<Ray> for T {
|
impl<T: FlatCoordinateSystem<Vec2> + MetricCS> FlatCoordinateSystem<Ray> for T {
|
||||||
fn flat_to_global(&self, ray: Ray) -> Ray {
|
fn flat_to_global(&self, ray: Ray) -> Ray {
|
||||||
let pos = self.flat_to_global(ray.pos);
|
|
||||||
Ray {
|
Ray {
|
||||||
pos,
|
pos: self.flat_to_global(ray.pos),
|
||||||
dir: Mat2::from(self.global_metric().sqrt_at(pos).inverse()) * ray.dir,
|
dir: self.flat_to_global_tfm_at(ray.pos) * ray.dir,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn global_to_flat(&self, ray: Ray) -> Ray {
|
fn global_to_flat(&self, ray: Ray) -> Ray {
|
||||||
Ray {
|
Ray {
|
||||||
pos: self.global_to_flat(ray.pos),
|
pos: self.global_to_flat(ray.pos),
|
||||||
dir: Mat2::from(self.global_metric().sqrt_at(ray.pos)) * ray.dir,
|
dir: self.global_to_flat_tfm_at(ray.pos) * ray.dir,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: FlatCoordinateSystem<Vec2> + MetricCS> FlatCoordinateSystem<Location> for T {
|
impl<T: FlatCoordinateSystem<Vec2> + MetricCS> FlatCoordinateSystem<Location> for T {
|
||||||
fn flat_to_global(&self, loc: Location) -> Location {
|
fn flat_to_global(&self, loc: Location) -> Location {
|
||||||
let pos = self.flat_to_global(loc.pos);
|
|
||||||
Location {
|
Location {
|
||||||
pos,
|
pos: self.flat_to_global(loc.pos),
|
||||||
rot: Mat2::from(self.global_metric().sqrt_at(pos).inverse()) * loc.rot,
|
rot: self.flat_to_global_tfm_at(loc.pos) * loc.rot,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn global_to_flat(&self, loc: Location) -> Location {
|
fn global_to_flat(&self, loc: Location) -> Location {
|
||||||
Location {
|
Location {
|
||||||
pos: self.global_to_flat(loc.pos), // в плоской СК для Inner или её продолжении на Outer
|
pos: self.global_to_flat(loc.pos), // в плоской СК для Inner или её продолжении на Outer
|
||||||
rot: Mat2::from(self.global_metric().sqrt_at(loc.pos)) * loc.rot,
|
rot: self.global_to_flat_tfm_at(loc.pos) * loc.rot,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user