MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / validate_recursive

Function validate_recursive

nodedb-spatial/src/validate.rs:29–135  ·  view source on GitHub ↗
(geom: &Geometry, issues: &mut Vec<String>)

Source from the content-addressed store, hash-verified

27}
28
29fn validate_recursive(geom: &Geometry, issues: &mut Vec<String>) {
30 match geom {
31 Geometry::Point { coordinates }
32 if coordinates[0].is_nan()
33 || coordinates[1].is_nan()
34 || coordinates[0].is_infinite()
35 || coordinates[1].is_infinite() =>
36 {
37 issues.push("Point has NaN or Infinite coordinate".to_string());
38 }
39
40 Geometry::LineString { coordinates } if coordinates.len() < 2 => {
41 issues.push(format!(
42 "LineString has {} points, minimum is 2",
43 coordinates.len()
44 ));
45 }
46
47 Geometry::Polygon { coordinates } => {
48 if coordinates.is_empty() {
49 issues.push("Polygon has no rings".to_string());
50 return;
51 }
52
53 for (ring_idx, ring) in coordinates.iter().enumerate() {
54 let label = if ring_idx == 0 {
55 "Exterior ring".to_string()
56 } else {
57 format!("Hole ring {ring_idx}")
58 };
59
60 if ring.len() < 4 {
61 issues.push(format!(
62 "{label} has {} points, minimum is 4 (triangle + close)",
63 ring.len()
64 ));
65 continue;
66 }
67
68 // Check closed.
69 if let (Some(first), Some(last)) = (ring.first(), ring.last())
70 && ((first[0] - last[0]).abs() > 1e-10 || (first[1] - last[1]).abs() > 1e-10)
71 {
72 issues.push(format!("{label} is not closed (first != last)"));
73 }
74
75 // Check winding order.
76 let area = signed_area(ring);
77 if ring_idx == 0 && area < 0.0 {
78 issues.push(
79 "Exterior ring has clockwise winding (should be counter-clockwise)"
80 .to_string(),
81 );
82 } else if ring_idx > 0 && area > 0.0 {
83 issues.push(format!(
84 "{label} has counter-clockwise winding (holes should be clockwise)"
85 ));
86 }

Callers 1

validate_geometryFunction · 0.85

Calls 10

signed_areaFunction · 0.85
to_stringMethod · 0.80
firstMethod · 0.80
pushMethod · 0.45
lenMethod · 0.45
is_emptyMethod · 0.45
iterMethod · 0.45
lastMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected