diff --git a/src/bin/flat/tube/mod.rs b/src/bin/flat/tube/mod.rs index ba970ed..0b8e523 100644 --- a/src/bin/flat/tube/mod.rs +++ b/src/bin/flat/tube/mod.rs @@ -67,8 +67,8 @@ impl Space { let inner = Rect { size: vec2(self.tube.inner_radius, self.tube.internal_halflength) }; let ray = self.tube.global_to_inner(ray); assert!(inner.is_inside(ray.pos)); - let objs = self.list_objects_inner(); let dist = inner.trace_out_of(ray).expect("Can't get outta here!"); + let objs = self.list_objects(|loc| self.tube.global_to_inner(loc)); FlatTraceResult { end: Some(self.tube.inner_to_global(ray.forward(dist))), objects: Self::hit_objects(objs.as_slice(), ray, Some(dist), |pos| self.tube.inner_to_global(pos)), @@ -77,12 +77,12 @@ impl Space { pub fn trace_outer(&self, ray: Ray) -> FlatTraceResult { assert_eq!(self.which_subspace(ray.pos), Outer); - let cell = Rect { size: vec2(self.tube.outer_radius, self.tube.external_halflength) }; - let objs = self.list_objects_outer(); - let lim = cell.trace_into(ray); + let outer = Rect { size: vec2(self.tube.outer_radius, self.tube.external_halflength) }; + let dist = outer.trace_into(ray); + let objs = self.list_objects(|loc| self.tube.global_to_outer(loc)); FlatTraceResult { - end: lim.map(|dist| ray.forward(dist)), - objects: Self::hit_objects(objs.as_slice(), ray, lim, |pos| pos), + end: dist.map(|dist| ray.forward(dist)), + objects: Self::hit_objects(objs.as_slice(), ray, dist, |pos| pos), } } @@ -97,22 +97,6 @@ impl Space { self.objs.iter().map(|&Object { id, loc, r }| Object { id, loc: tfm(loc), r }).collect() } - fn list_objects_outer(&self) -> Vec { - self.list_objects(|loc| - match self.which_subspace(loc.pos) { - Inner | Outer => self.tube.global_to_outer(loc), - Boundary => panic!("Object at {} was destroyed by the space curvature", loc.pos), - }) - } - - fn list_objects_inner(&self) -> Vec { - self.list_objects(|loc| - match self.which_subspace(loc.pos) { - Inner | Outer => self.tube.global_to_inner(loc), - Boundary => panic!("Object at {} was destroyed by the space curvature", loc.pos), - }) - } - fn hit_objects(objs: &[Object], ray: Ray, limit: Option, globalize: impl Fn(Vec2) -> Vec2) -> Vec { let limit = limit.unwrap_or(f32::INFINITY); objs.iter()