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

Function polygon_contains_point

nodedb-spatial/src/predicates/contains.rs:108–135  ·  view source on GitHub ↗

Polygon (with holes) contains a point — strict DE-9IM (boundary = false).

(rings: &[Vec<[f64; 2]>], pt: [f64; 2])

Source from the content-addressed store, hash-verified

106
107/// Polygon (with holes) contains a point — strict DE-9IM (boundary = false).
108fn polygon_contains_point(rings: &[Vec<[f64; 2]>], pt: [f64; 2]) -> bool {
109 let Some(exterior) = rings.first() else {
110 return false;
111 };
112
113 // Point on exterior boundary → NOT contained (DE-9IM).
114 if point_on_ring_boundary(pt, exterior) {
115 return false;
116 }
117
118 // Point must be inside exterior ring.
119 if !point_in_polygon(pt[0], pt[1], exterior) {
120 return false;
121 }
122
123 // Point must not be inside any hole.
124 for hole in &rings[1..] {
125 if point_in_polygon(pt[0], pt[1], hole) {
126 return false;
127 }
128 // Point on hole boundary is also outside (it's on A's boundary).
129 if point_on_ring_boundary(pt, hole) {
130 return false;
131 }
132 }
133
134 true
135}
136
137/// Polygon contains a linestring — all vertices inside, no edge crossings with exterior.
138fn polygon_contains_linestring(rings: &[Vec<[f64; 2]>], line: &[[f64; 2]]) -> bool {

Callers 3

st_containsFunction · 0.85
polygon_contains_polygonFunction · 0.85

Calls 3

point_on_ring_boundaryFunction · 0.85
point_in_polygonFunction · 0.85
firstMethod · 0.80

Tested by

no test coverage detected