for c in self.wall_grid.grid_coordinates_on_line(p1, p2) {
for w in &self.wall_grid.cells[c.x][c.y] {
if let Intersection::Point(p) = Intersection::lines(p1, p2, w.p1, w.p2) {
- let wall = Wall {
- region: Rc::clone(&self.walls[w.region]),
- edge: Rc::clone(w),
- };
- return IntersectResult::Intersection(wall, p)
+ if w.point_is_in_front(p1) {
+ let wall = Wall {
+ region: Rc::clone(&self.walls[w.region]),
+ edge: Rc::clone(w),
+ };
+ return IntersectResult::Intersection(wall, p)
+ }
}
}
}
pub p2: Point<f64>,
}
+impl WallEdge {
+ fn point_is_in_front(&self, p: Point<f64>) -> bool {
+ let cross = (self.p2 - self.p1).cross_product(p - self.p1);
+ cross > 0.0
+ }
+}
+
////////// WALL ////////////////////////////////////////////////////////////////
pub struct Wall {