From 716fe65841c30060b19c583be278c843e067e4f2 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 27 May 2024 19:16:40 +0300 Subject: [PATCH] Extra tracers --- src/bin/flat.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/bin/flat.rs b/src/bin/flat.rs index 214d20a..5163a01 100644 --- a/src/bin/flat.rs +++ b/src/bin/flat.rs @@ -95,6 +95,35 @@ impl Space { let p = loc.pos + corr * loc.rot * off; Location { pos: p, rot: corr * loc.rot } } + + fn trace_inner(&self, ray: Ray) -> Ray { + 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!"); + cell.ray_to_global(ray) + } + + fn trace_outer(&self, ray: Ray) -> Option { + assert_eq!(self.which_subspace(ray.pos), Outer); + let cell = basic_shapes::Rect { size: vec2(self.rect.outer_radius, self.rect.external_halflength) }; + if let Some(dist) = cell.trace_into(ray) { + Some(Ray { pos: ray.pos + ray.dir * dist, dir: ray.dir }) + } else { + None + } + } + + 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; + } + } + } } fn draw_ray_2(gc: &mut Vec, space: &Space, base: Vec2, dir: Vec2) {