Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Aug 15, 2023
1 parent de0407a commit 5759cb5
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/input/triangulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,32 @@ impl Triangulation {
std::mem::replace(&mut self.inner, GeoPolygon::new(LineString(vec![]), vec![]))
.into_inner();

let mut not_intersecting: Vec<MultiPolygon<f32>> = vec![];
let mut not_intersecting: Vec<LineString<f32>> = vec![];
let mut intersecting = vec![];
for poly in interiors.into_iter() {
let mut intersecting = vec![];
intersecting.clear();
for (i, other) in not_intersecting.iter().enumerate() {
if poly.intersects(other) {
intersecting.push(i);
}
}

let poly = GeoPolygon::new(poly.into(), vec![]);
intersecting.sort();
intersecting.reverse();
if intersecting.is_empty() {
not_intersecting.push(poly.into());
not_intersecting.push(poly);
} else {
let mut merged: MultiPolygon<f32> = poly.into();
intersecting.reverse();
let mut merged: MultiPolygon<f32> = GeoPolygon::new(poly, vec![]).into();
for other in intersecting.iter() {
merged = merged.union(&not_intersecting.remove(*other).into());
merged = merged
.union(&GeoPolygon::new(not_intersecting.remove(*other), vec![]).into());
}
not_intersecting.push(merged);
not_intersecting.push(LineString(
merged.exterior_coords_iter().collect::<Vec<_>>(),
));
}
}

self.inner = GeoPolygon::new(
exterior,
not_intersecting
.into_iter()
.map(|polygon| LineString(polygon.exterior_coords_iter().collect::<Vec<_>>()))
.collect::<Vec<_>>(),
);
self.inner = GeoPolygon::new(exterior, not_intersecting);
}

#[inline]
Expand Down Expand Up @@ -149,7 +145,7 @@ impl From<Triangulation> for Mesh {
Triangulation::add_constraint_edges(&mut cdt, value.inner.exterior());

value.inner.interiors().iter().for_each(|obstacle| {
Triangulation::add_constraint_edges(&mut cdt, &obstacle);
Triangulation::add_constraint_edges(&mut cdt, obstacle);
});

let mut face_to_polygon = HashMap::new();
Expand Down

0 comments on commit 5759cb5

Please sign in to comment.