This commit is contained in:
Fabien Freling 2020-04-06 23:56:59 +02:00
parent 4620f647ad
commit d442070194

View file

@ -118,7 +118,9 @@ fn closest_point(level: &Level, pos: &Position, angle: Radian) -> (Tile, Positio
let mut tile = Tile::Empty; let mut tile = Tile::Empty;
while tile == Tile::Empty && level.contains(next_point) { while tile == Tile::Empty && level.contains(next_point) {
if next_point.distance(x_candidate) < next_point.distance(y_candidate) { println!("x_candidate: {:?}, distance: {}", x_candidate, pos.distance(x_candidate));
println!("y_candidate: {:?}, distance: {}", y_candidate, pos.distance(y_candidate));
if pos.distance(x_candidate) < pos.distance(y_candidate) {
next_point = x_candidate; next_point = x_candidate;
x_candidate = Position { x_candidate = Position {
x: x_candidate.x + x_step.signum(), x: x_candidate.x + x_step.signum(),
@ -131,16 +133,28 @@ fn closest_point(level: &Level, pos: &Position, angle: Radian) -> (Tile, Positio
y: y_candidate.y + y_step.signum(), y: y_candidate.y + y_step.signum(),
}; };
} }
// println!("next candidate: {:?}", next_point); println!("next candidate: {:?}", next_point);
tile = if next_point.x.fract() == 0.0 { tile = if next_point.x.fract() == 0.0 {
let mut position = next_point; let mut position = next_point;
position.x += 0.5 * x_step.signum(); position.x += 0.5 * x_step.signum();
level.tile_at(position) let tile = level.tile_at(position);
if tile == Tile::Wall {
position.x -= x_step.signum();
let opposite_tile = level.tile_at(position);
assert_eq!(opposite_tile, Tile::Empty);
}
tile
} else { } else {
let mut position = next_point; let mut position = next_point;
position.y += 0.5 * y_step.signum(); position.y += 0.5 * y_step.signum();
level.tile_at(position) let tile = level.tile_at(position);
if tile == Tile::Wall {
position.y -= y_step.signum();
let opposite_tile = level.tile_at(position);
assert_eq!(opposite_tile, Tile::Empty);
}
tile
}; };
} }