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

Function point_intersects_polygon

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

Point intersects polygon — inside OR on boundary.

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

Source from the content-addressed store, hash-verified

94
95/// Point intersects polygon — inside OR on boundary.
96fn point_intersects_polygon(pt: [f64; 2], rings: &[Vec<[f64; 2]>]) -> bool {
97 let Some(exterior) = rings.first() else {
98 return false;
99 };
100
101 // On exterior boundary → intersects.
102 if point_on_ring_boundary(pt, exterior) {
103 return true;
104 }
105
106 // Must be inside exterior.
107 if !point_in_polygon(pt[0], pt[1], exterior) {
108 return false;
109 }
110
111 // Must not be inside a hole (but on hole boundary counts as intersects).
112 for hole in &rings[1..] {
113 if point_on_ring_boundary(pt, hole) {
114 return true;
115 }
116 if point_in_polygon(pt[0], pt[1], hole) {
117 return false;
118 }
119 }
120
121 true
122}
123
124/// Two linestrings intersect if any of their segments cross.
125fn linestrings_intersect(la: &[[f64; 2]], lb: &[[f64; 2]]) -> bool {

Callers 3

st_intersectsFunction · 0.85
polygons_intersectFunction · 0.85

Calls 3

point_on_ring_boundaryFunction · 0.85
point_in_polygonFunction · 0.85
firstMethod · 0.80

Tested by

no test coverage detected