MCPcopy Create free account
hub / github.com/ecto/muni / longest_edge_angle

Function longest_edge_angle

depot/dispatch/src/coverage.rs:181–197  ·  view source on GitHub ↗

Find the angle of the longest edge of the polygon (heuristic for optimal sweep).

(coords: &[Coord])

Source from the content-addressed store, hash-verified

179
180/// Find the angle of the longest edge of the polygon (heuristic for optimal sweep).
181fn 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.

Callers 1

generateFunction · 0.85

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected