squish_polygons_together infinite loops sometimes. until a proper fix, just limit it to 100 relaxations

This commit is contained in:
Dustin Carlino 2020-08-16 08:36:00 -07:00
parent bef3434ac8
commit 7d460f27c8

View File

@ -928,6 +928,7 @@ fn squish_polygons_together(mut polygons: Vec<Polygon>) -> Vec<(f64, f64)> {
// Once a polygon hits another while moving, stop adjusting it. Otherwise, go round-robin.
let mut indices: VecDeque<usize> = (0..polygons.len()).collect();
let mut attempts = 0;
while !indices.is_empty() {
let idx = indices.pop_front().unwrap();
let center = Pt2D::center(&polygons.iter().map(|p| p.center()).collect());
@ -948,6 +949,11 @@ fn squish_polygons_together(mut polygons: Vec<Polygon>) -> Vec<(f64, f64)> {
polygons[idx] = translated;
indices.push_back(idx);
}
attempts += 1;
if attempts == 100 {
break;
}
}
translations