Skip to content

Commit 9f389d9

Browse files
committed
Simplify: Dont worry about redundant error reporting
This is subjective, but I don't think we get much value here. This code is already quite complicated, so there is value in simplifying.
1 parent 7e1ca97 commit 9f389d9

File tree

2 files changed

+30
-32
lines changed

2 files changed

+30
-32
lines changed

geo/src/algorithm/validation/polygon.rs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,8 @@ impl<F: GeoFloat> Validation for Polygon<F> {
128128
let polygon_exterior = Polygon::new(self.exterior().clone(), vec![]);
129129
let prepared_exterior = PreparedGeometry::from(&polygon_exterior);
130130

131-
// Track ring pairs that already have intersection errors so the
132-
// simply-connected check can skip them (avoids duplicate reporting).
133-
// Keys use GeometryGraph edge indices: 0 = exterior, N = interior N-1.
134-
let mut errored_edge_pairs: HashSet<(usize, usize)> = HashSet::new();
135-
136131
for (interior_1_idx, interior_1) in self.interiors().iter().enumerate() {
137132
let ring_role_1 = RingRole::Interior(interior_1_idx);
138-
let edge_idx_1 = interior_1_idx + 1;
139133
if interior_1.is_empty() {
140134
continue;
141135
}
@@ -154,7 +148,6 @@ impl<F: GeoFloat> Validation for Polygon<F> {
154148
if exterior_vs_interior.get(CoordPos::OnBoundary, CoordPos::OnBoundary)
155149
== Dimensions::OneDimensional
156150
{
157-
errored_edge_pairs.insert((0, edge_idx_1));
158151
handle_validation_error(InvalidPolygon::IntersectingRingsOnALine(
159152
RingRole::Exterior,
160153
ring_role_1,
@@ -165,7 +158,6 @@ impl<F: GeoFloat> Validation for Polygon<F> {
165158
self.interiors().iter().enumerate().skip(interior_1_idx + 1)
166159
{
167160
let ring_role_2 = RingRole::Interior(interior_2_idx);
168-
let edge_idx_2 = interior_2_idx + 1;
169161
if interior_2.is_empty() {
170162
continue;
171163
}
@@ -176,7 +168,6 @@ impl<F: GeoFloat> Validation for Polygon<F> {
176168
if intersection_matrix.get(CoordPos::Inside, CoordPos::Inside)
177169
== Dimensions::TwoDimensional
178170
{
179-
errored_edge_pairs.insert((edge_idx_1, edge_idx_2));
180171
handle_validation_error(InvalidPolygon::IntersectingRingsOnAnArea(
181172
ring_role_1,
182173
ring_role_2,
@@ -185,7 +176,6 @@ impl<F: GeoFloat> Validation for Polygon<F> {
185176
if intersection_matrix.get(CoordPos::OnBoundary, CoordPos::OnBoundary)
186177
== Dimensions::OneDimensional
187178
{
188-
errored_edge_pairs.insert((edge_idx_1, edge_idx_2));
189179
handle_validation_error(InvalidPolygon::IntersectingRingsOnALine(
190180
ring_role_1,
191181
ring_role_2,
@@ -196,10 +186,9 @@ impl<F: GeoFloat> Validation for Polygon<F> {
196186

197187
// Check that the interior is simply connected.
198188
let prepared_polygon = PreparedGeometry::from(self);
199-
if let Some((edge_a, edge_b)) = check_interior_simply_connected_from_graph(
200-
&prepared_polygon.geometry_graph,
201-
&errored_edge_pairs,
202-
) {
189+
if let Some((edge_a, edge_b)) =
190+
check_interior_simply_connected_from_graph(&prepared_polygon.geometry_graph)
191+
{
203192
let role_a = edge_index_to_ring_role(edge_a);
204193
let role_b = edge_index_to_ring_role(edge_b);
205194
handle_validation_error(InvalidPolygon::InteriorNotSimplyConnected(role_a, role_b))?;
@@ -241,7 +230,6 @@ fn edge_index_to_ring_role(edge_idx: usize) -> RingRole {
241230
/// identifying the ring pair that causes disconnection.
242231
fn check_interior_simply_connected_from_graph<F: GeoFloat>(
243232
graph: &GeometryGraph<F>,
244-
skip_pairs: &HashSet<(usize, usize)>,
245233
) -> Option<(usize, usize)> {
246234
let edges = graph.edges();
247235
if edges.len() < 2 {
@@ -317,12 +305,10 @@ fn check_interior_simply_connected_from_graph<F: GeoFloat>(
317305
for (idx_a, &(edge_a, _)) in unique_edges.iter().enumerate() {
318306
for &(edge_b, _) in unique_edges.iter().skip(idx_a + 1) {
319307
let key = (edge_a, edge_b);
320-
if !skip_pairs.contains(&key) {
321-
if !ring_pair_seen.insert(key) {
322-
return Some(key);
323-
}
324-
coord_edges.push((current_coord, edge_a, edge_b));
308+
if !ring_pair_seen.insert(key) {
309+
return Some(key);
325310
}
311+
coord_edges.push((current_coord, edge_a, edge_b));
326312
}
327313
}
328314
}
@@ -520,10 +506,16 @@ mod tests {
520506

521507
assert_validation_errors!(
522508
&polygon,
523-
vec![InvalidPolygon::IntersectingRingsOnALine(
524-
RingRole::Interior(0),
525-
RingRole::Interior(1)
526-
)]
509+
vec![
510+
InvalidPolygon::IntersectingRingsOnALine(
511+
RingRole::Interior(0),
512+
RingRole::Interior(1)
513+
),
514+
InvalidPolygon::InteriorNotSimplyConnected(
515+
RingRole::Interior(0),
516+
RingRole::Interior(1)
517+
)
518+
]
527519
);
528520
}
529521

@@ -568,10 +560,13 @@ mod tests {
568560

569561
assert_validation_errors!(
570562
&polygon,
571-
vec![InvalidPolygon::IntersectingRingsOnALine(
572-
RingRole::Exterior,
573-
RingRole::Interior(0)
574-
)]
563+
vec![
564+
InvalidPolygon::IntersectingRingsOnALine(RingRole::Exterior, RingRole::Interior(0)),
565+
InvalidPolygon::InteriorNotSimplyConnected(
566+
RingRole::Exterior,
567+
RingRole::Interior(0)
568+
)
569+
]
575570
);
576571
}
577572

geo/src/algorithm/validation/tests.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,13 @@ mod gdal_test_cases {
374374
let polygon = wkt!(POLYGON ((10. 90., 90. 90., 90. 10., 10. 10., 10. 90.), (10. 90., 90. 90., 90. 10., 10. 10., 10. 90.)));
375375
assert_eq!(
376376
polygon.validation_errors(),
377-
vec![InvalidPolygon::IntersectingRingsOnALine(
378-
RingRole::Exterior,
379-
RingRole::Interior(0)
380-
)]
377+
vec![
378+
InvalidPolygon::IntersectingRingsOnALine(RingRole::Exterior, RingRole::Interior(0)),
379+
InvalidPolygon::InteriorNotSimplyConnected(
380+
RingRole::Exterior,
381+
RingRole::Interior(0)
382+
)
383+
]
381384
);
382385
}
383386

0 commit comments

Comments
 (0)