This commit is contained in:
numzero 2024-05-27 19:24:12 +03:00
parent a82441677d
commit 23cddeb940

View File

@ -96,6 +96,10 @@ impl Space {
Location { pos: p, rot: corr * loc.rot } Location { pos: p, rot: corr * loc.rot }
} }
fn trace_iter(&self, ray: Ray) -> impl Iterator<Item=Ray> + '_ {
std::iter::successors(Some(ray), |&ray| Some(self.trace_step(ray)))
}
fn trace_inner(&self, ray: Ray) -> Ray { fn trace_inner(&self, ray: Ray) -> Ray {
assert_eq!(self.which_subspace(ray.pos), Inner); assert_eq!(self.which_subspace(ray.pos), Inner);
let cell = RectInside { rect: self.rect }; let cell = RectInside { rect: self.rect };
@ -116,7 +120,7 @@ impl Space {
fn trace_boundary(&self, ray: Ray) -> Ray { fn trace_boundary(&self, ray: Ray) -> Ray {
assert_eq!(self.which_subspace(ray.pos), Boundary); assert_eq!(self.which_subspace(ray.pos), Boundary);
std::iter::successors(Some(ray), |&ray| Some(self.trace_step(ray))) self.trace_iter(ray)
.find(|&ray| self.which_subspace(ray.pos) != Boundary) .find(|&ray| self.which_subspace(ray.pos) != Boundary)
.expect("Can't get outta the wall!") .expect("Can't get outta the wall!")
} }