rust-galmon-web/src/ui/main/world_geo/contains.rs

26 lines
514 B
Rust

use super::RadianPoint;
fn wrap_longitude(lambda: f32) -> f32 {
use std::f32::consts::PI;
if lambda.abs() <= PI {
lambda
} else {
lambda.signum() * ((lambda.abs() + PI) % (2.0 * PI) - PI)
}
}
pub fn polygon_contains_south(polygon: &[Vec<RadianPoint>]) -> bool {
let mut angle_sum = 0.0;
for ring in polygon {
if let Some(mut prev) = ring.last() {
for point in ring {
angle_sum += wrap_longitude(point.lambda - prev.lambda);
prev = point;
}
}
}
angle_sum < -std::f32::consts::PI
}