Two polygons intersect — edge crossing or containment.
(ra: &[Vec<[f64; 2]>], rb: &[Vec<[f64; 2]>])
| 172 | |
| 173 | /// Two polygons intersect — edge crossing or containment. |
| 174 | fn 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)] |
| 211 | mod tests { |
no test coverage detected