From a82441677df93b939e1ba87fb1ddf9fb5eaa9be3 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 27 May 2024 19:16:59 +0300 Subject: [PATCH] Functional tracer --- src/bin/flat.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/bin/flat.rs b/src/bin/flat.rs index 5163a01..1d70cf3 100644 --- a/src/bin/flat.rs +++ b/src/bin/flat.rs @@ -116,13 +116,9 @@ impl Space { fn trace_boundary(&self, ray: Ray) -> Ray { assert_eq!(self.which_subspace(ray.pos), Boundary); - let mut ray = ray; - loop { - ray = self.trace_step(ray); - if self.which_subspace(ray.pos) != Boundary { - break ray; - } - } + std::iter::successors(Some(ray), |&ray| Some(self.trace_step(ray))) + .find(|&ray| self.which_subspace(ray.pos) != Boundary) + .expect("Can't get outta the wall!") } }