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

Function polygons_intersect

nodedb-spatial/src/predicates/intersects.rs:174–208  ·  view source on GitHub ↗

Two polygons intersect — edge crossing or containment.

(ra: &[Vec<[f64; 2]>], rb: &[Vec<[f64; 2]>])

Source from the content-addressed store, hash-verified

172
173/// Two polygons intersect — edge crossing or containment.
174fn polygons_intersect(ra: &[Vec<[f64; 2]>], rb: &[Vec<[f64; 2]>]) -> bool {
175 let Some(ext_a) = ra.first() else {
176 return false;
177 };
178 let Some(ext_b) = rb.first() else {
179 return false;
180 };
181
182 // Check if any vertex of B is inside/on A.
183 for pt in ext_b {
184 if point_intersects_polygon(*pt, ra) {
185 return true;
186 }
187 }
188
189 // Check if any vertex of A is inside/on B.
190 for pt in ext_a {
191 if point_intersects_polygon(*pt, rb) {
192 return true;
193 }
194 }
195
196 // Check edge crossings between exteriors.
197 let a_edges = ring_edges(ext_a);
198 let b_edges = ring_edges(ext_b);
199 for &(a1, a2) in &a_edges {
200 for &(b1, b2) in &b_edges {
201 if segments_intersect(a1, a2, b1, b2) {
202 return true;
203 }
204 }
205 }
206
207 false
208}
209
210#[cfg(test)]
211mod tests {

Callers 1

st_intersectsFunction · 0.85

Calls 4

point_intersects_polygonFunction · 0.85
ring_edgesFunction · 0.85
segments_intersectFunction · 0.85
firstMethod · 0.80

Tested by

no test coverage detected