Unify FCS<Ray>
This commit is contained in:
parent
1c96c87173
commit
d515054281
|
|
@ -203,6 +203,23 @@ mod coords {
|
|||
fn global_metric(&self) -> &impl Metric;
|
||||
}
|
||||
|
||||
impl<T: FlatCoordinateSystem<Vec2> + MetricCS> FlatCoordinateSystem<Ray> for T {
|
||||
fn flat_to_global(&self, ray: Ray) -> Ray {
|
||||
let pos = self.flat_to_global(ray.pos);
|
||||
Ray {
|
||||
pos,
|
||||
dir: Mat2::from(self.global_metric().sqrt_at(pos).inverse()) * ray.dir,
|
||||
}
|
||||
}
|
||||
|
||||
fn global_to_flat(&self, ray: Ray) -> Ray {
|
||||
Ray {
|
||||
pos: self.global_to_flat(ray.pos),
|
||||
dir: Mat2::from(self.global_metric().sqrt_at(ray.pos)) * ray.dir,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FlatCoordinateSystem<Vec2> + MetricCS> FlatCoordinateSystem<Location> for T {
|
||||
fn flat_to_global(&self, loc: Location) -> Location {
|
||||
let pos = self.flat_to_global(loc.pos);
|
||||
|
|
@ -235,22 +252,6 @@ mod coords {
|
|||
}
|
||||
}
|
||||
|
||||
impl FlatCoordinateSystem<Ray> for InnerCS {
|
||||
fn flat_to_global(&self, ray: Ray) -> Ray {
|
||||
Ray {
|
||||
pos: self.flat_to_global(ray.pos),
|
||||
dir: vec2(ray.dir.x, self.0.dy(ray.pos.y) * ray.dir.y),
|
||||
}
|
||||
}
|
||||
|
||||
fn global_to_flat(&self, ray: Ray) -> Ray {
|
||||
Ray {
|
||||
pos: self.global_to_flat(ray.pos),
|
||||
dir: vec2(ray.dir.x, self.0.dv(ray.pos.y) * ray.dir.y),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FlatRegion for InnerCS {
|
||||
fn distance_to_boundary(&self, ray: Ray) -> Option<f32> {
|
||||
Rect { size: vec2(self.0.inner_radius, self.0.internal_halflength) }.trace_out_of(ray)
|
||||
|
|
@ -285,8 +286,6 @@ mod coords {
|
|||
}
|
||||
}
|
||||
|
||||
impl FlatCoordinateSystem<Ray> for OuterCS {}
|
||||
|
||||
impl FlatRegion for OuterCS {
|
||||
fn distance_to_boundary(&self, ray: Ray) -> Option<f32> {
|
||||
Rect { size: vec2(self.0.outer_radius, self.0.external_halflength) }.trace_into(ray)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user