diff --git a/src/bin/flat/main.rs b/src/bin/flat/main.rs index 30c066c..85ee39c 100644 --- a/src/bin/flat/main.rs +++ b/src/bin/flat/main.rs @@ -275,6 +275,20 @@ impl Space { None }).collect() } + + fn line(&self, a: Vec2, b: Vec2, step: f32) -> Vec { + match self.which_subspace(a) { + Outer => vec![b], + Inner => { + let cell = RectInside { rect: self.rect }; + let n = ((b - a).length() / step) as usize + 1; + let a = cell.pos_to_local(a); + let b = cell.pos_to_local(b); + (1..=n).map(|k| cell.pos_to_global(a.lerp(b, k as f32 / n as f32))).collect() + } + Boundary => panic!("Can't draw a line here!"), + } + } } fn draw_ray_2(gc: &mut Vec, space: &Space, base: Vec2, dir: Vec2) { @@ -306,6 +320,7 @@ fn draw_ray_2(gc: &mut Vec, space: &Space, base: Vec2, dir: Vec2) { for hit in ret.objects { hits.circle(hit.pos.x, hit.pos.y, 1.5); } + let a = ray.pos; ray = match ret.end { Some(r) => r, None => { @@ -314,7 +329,9 @@ fn draw_ray_2(gc: &mut Vec, space: &Space, base: Vec2, dir: Vec2) { break; } }; - gc.line_to(ray.pos.x, ray.pos.y); + for p in space.line(a, ray.pos, 10.0) { + gc.line_to(p.x, p.y); + } gc.stroke(); gc.new_dash_pattern(); gc.new_path();