Find the angle of the longest edge of the polygon (heuristic for optimal sweep).
(coords: &[Coord])
| 179 | |
| 180 | /// Find the angle of the longest edge of the polygon (heuristic for optimal sweep). |
| 181 | fn longest_edge_angle(coords: &[Coord]) -> f64 { |
| 182 | let mut best_angle = 0.0; |
| 183 | let mut best_len_sq = 0.0; |
| 184 | |
| 185 | for i in 0..coords.len() { |
| 186 | let j = (i + 1) % coords.len(); |
| 187 | let dx = coords[j].x - coords[i].x; |
| 188 | let dy = coords[j].y - coords[i].y; |
| 189 | let len_sq = dx * dx + dy * dy; |
| 190 | if len_sq > best_len_sq { |
| 191 | best_len_sq = len_sq; |
| 192 | best_angle = dy.atan2(dx); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | best_angle |
| 197 | } |
| 198 | |
| 199 | /// Intersect a horizontal line with the edges of a polygon, returning X coordinates |
| 200 | /// of all intersection points. |