From 978138c7804fa5f2c0fe07ce2c89c4c014b19e99 Mon Sep 17 00:00:00 2001 From: numzero Date: Sun, 9 Jun 2024 20:59:28 +0300 Subject: [PATCH] Pull the distance a level out --- src/bin/flat.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bin/flat.rs b/src/bin/flat.rs index f397495..9626cb5 100644 --- a/src/bin/flat.rs +++ b/src/bin/flat.rs @@ -158,7 +158,8 @@ impl Space { assert_eq!(self.which_subspace(ray.pos), Inner); let cell = RectInside { rect: self.rect }; let ray = cell.ray_to_local(ray); - let ray = cell.to_boundary(ray).expect("Can't get outta here!"); + let dist = cell.to_boundary(ray).expect("Can't get outta here!"); + let ray = Ray { pos: ray.pos + ray.dir * dist, dir: ray.dir }; cell.ray_to_global(ray) } @@ -412,7 +413,7 @@ trait FlatCell: std::fmt::Debug { } fn local_bounds(&self) -> (Vec2, Vec2); - fn to_boundary(&self, ray: Ray) -> Option { + fn to_boundary(&self, ray: Ray) -> Option { assert!(self.is_inside(ray.pos)); let sgn = ray.dir.signum(); let p = ray.pos * sgn; @@ -430,7 +431,7 @@ trait FlatCell: std::fmt::Debug { (bnd.1.y - p.y) / v.y }; if t <= 100000.0 { - Some(Ray { pos: sgn * (p + v * t), dir: sgn * v }) + Some(t) } else { None }