diff --git a/src/bin/flat.rs b/src/bin/flat.rs index 1d31814..7501058 100644 --- a/src/bin/flat.rs +++ b/src/bin/flat.rs @@ -130,15 +130,14 @@ fn draw_ray_2(gc: &mut Vec, space: &Space, base: Vec2, dir: Vec2) { let dir = space.rect.globalize(base, dir); gc.new_path(); gc.move_to(base.x, base.y); - let mut p = base; - let mut v = space.rect.normalize_vec_at(base, dir) * DT; + let mut ray = Ray { pos: base, dir: space.rect.normalize_vec_at(base, dir) * DT }; for _ in 0..10000 { - Ray { pos: p, dir: v } = space.trace_step(Ray { pos: p, dir: v }); - gc.line_to(p.x, p.y); - if p.abs().cmpgt(Vec2::splat(1000.0)).any() { + ray = space.trace_step(ray); + gc.line_to(ray.pos.x, ray.pos.y); + if ray.pos.abs().cmpgt(Vec2::splat(1000.0)).any() { break; } - let sub = space.which_subspace(p); + let sub = space.which_subspace(ray.pos); if sub == Boundary { continue; } @@ -146,31 +145,29 @@ fn draw_ray_2(gc: &mut Vec, space: &Space, base: Vec2, dir: Vec2) { gc.new_dash_pattern(); gc.dash_length(6.0); gc.new_path(); - gc.move_to(p.x, p.y); + gc.move_to(ray.pos.x, ray.pos.y); match sub { Inner => { - let cell = RectInside { rect: space.rect }; - let ray = cell.ray_to_local(Ray { pos: p, dir: v }); - let ray = cell.to_boundary(ray).expect("Can't get outta here!"); - Ray { pos: p, dir: v } = cell.ray_to_global(ray); + ray = space.trace_inner(ray); } Outer => { - let cell = basic_shapes::Rect { size: vec2(space.rect.outer_radius, space.rect.external_halflength) }; - let Some(dist) = cell.trace_into(Ray { pos: p, dir: v }) else { - p += v * (1000.0 / DT); - gc.line_to(p.x, p.y); - gc.stroke(); - break; + ray = match space.trace_outer(ray) { + Some(r) => r, + None => { + ray.pos += ray.dir * (1000.0 / DT); + gc.line_to(ray.pos.x, ray.pos.y); + gc.stroke(); + break; + } }; - p += v * dist; } Boundary => panic!(), } - gc.line_to(p.x, p.y); + gc.line_to(ray.pos.x, ray.pos.y); gc.stroke(); gc.new_dash_pattern(); gc.new_path(); - gc.move_to(p.x, p.y); + gc.move_to(ray.pos.x, ray.pos.y); } gc.stroke(); gc.new_dash_pattern();