From 5759cb5ee7178f2da159459fd2306c965e224c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Tue, 15 Aug 2023 23:16:21 +0200 Subject: [PATCH] code cleanup --- src/input/triangulation.rs | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/input/triangulation.rs b/src/input/triangulation.rs index 873dfa7..03cc554 100644 --- a/src/input/triangulation.rs +++ b/src/input/triangulation.rs @@ -68,36 +68,32 @@ impl Triangulation { std::mem::replace(&mut self.inner, GeoPolygon::new(LineString(vec![]), vec![])) .into_inner(); - let mut not_intersecting: Vec> = vec![]; + let mut not_intersecting: Vec> = 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 = poly.into(); + intersecting.reverse(); + let mut merged: MultiPolygon = GeoPolygon::new(poly, vec![]).into(); for other in intersecting.iter() { - merged = merged.union(¬_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::>(), + )); } } - self.inner = GeoPolygon::new( - exterior, - not_intersecting - .into_iter() - .map(|polygon| LineString(polygon.exterior_coords_iter().collect::>())) - .collect::>(), - ); + self.inner = GeoPolygon::new(exterior, not_intersecting); } #[inline] @@ -149,7 +145,7 @@ impl From 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();