use crate::models::GeoPoint;
pub fn split_into_polygons(points: &[GeoPoint]) -> Vec<Vec<GeoPoint>> {
if points.is_empty() {
return vec![];
}
let mut polygons: Vec<Vec<GeoPoint>> = Vec::new();
let mut current: Vec<GeoPoint> = Vec::new();
for point in points {
if let Some(first) = current.first() {
if approx_equal(first.latitude, point.latitude)
&& approx_equal(first.longitude, point.longitude)
{
current.push(point.clone());
if current.len() >= 4 {
polygons.push(current.clone());
}
current.clear();
continue;
}
}
current.push(point.clone());
}
if current.len() >= 3 {
current.push(current[0].clone());
polygons.push(current);
}
polygons
}
pub fn is_multi_polygon(points: &[GeoPoint]) -> bool {
split_into_polygons(points).len() > 1
}
fn approx_equal(a: f64, b: f64) -> bool {
(a - b).abs() < 1e-5
}