Attempt to work around crash when creating direction.
This commit is contained in:
parent
56dc32cce3
commit
4c95ddf296
|
@ -80,13 +80,14 @@ impl Viewshed {
|
||||||
// println!("Checking {coord:?}");
|
// println!("Checking {coord:?}");
|
||||||
if let Some((_, entities)) = opacity_map.get(&coord) {
|
if let Some((_, entities)) = opacity_map.get(&coord) {
|
||||||
for e in entities {
|
for e in entities {
|
||||||
if entities.len() == 1 || sensors.contains(*e) {
|
let coord = Vec2::new(coord.x as f32 + 0.5, coord.y as f32 + 0.5);
|
||||||
|
let dir = (coord - *start).normalize_or_zero();
|
||||||
|
if dir == Vec2::ZERO || entities.len() == 1 || sensors.contains(*e) {
|
||||||
// println!("Spotted {e:?}");
|
// println!("Spotted {e:?}");
|
||||||
new_visible_entities.insert(*e);
|
new_visible_entities.insert(*e);
|
||||||
} else {
|
} else {
|
||||||
let should_push = std::cell::RefCell::new(true);
|
let should_push = std::cell::RefCell::new(true);
|
||||||
let coord = Vec2::new(coord.x as f32 + 0.5, coord.y as f32 + 0.5);
|
let dir = Dir2::new_unchecked(dir);
|
||||||
let dir = Dir2::new_unchecked((coord - *start).normalize_or_zero());
|
|
||||||
// println!("Casting from {coord} to {dir:?}");
|
// println!("Casting from {coord} to {dir:?}");
|
||||||
spatial_query.cast_ray_predicate(
|
spatial_query.cast_ray_predicate(
|
||||||
*start,
|
*start,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user