use geo::algorithm::ClosestPoint;
use geo::algorithm::HaversineDistance;
use geo::{Coord, LineString, Point};
#[test]
fn test_project_point_on_linestring() {
let linestring = LineString::from(vec![
Coord { x: 4.0, y: 50.0 }, Coord { x: 4.0, y: 51.0 },
]);
let point = Point::new(4.0, 50.5);
let closest = linestring.closest_point(&point);
match closest {
geo::Closest::SinglePoint(projected) | geo::Closest::Intersection(projected) => {
let distance = point.haversine_distance(&projected);
assert!(distance < 1.0, "Point should be very close to linestring");
assert!(
(projected.x() - 4.0_f64).abs() < 0.0001,
"Projected longitude should be 4.0"
);
assert!(
(projected.y() - 50.5_f64).abs() < 0.1,
"Projected latitude should be around 50.5"
);
}
geo::Closest::Indeterminate => {
panic!("Could not find closest point");
}
}
}
#[test]
fn test_linestring_creation() {
let coords = vec![Coord { x: 4.0, y: 50.0 }, Coord { x: 4.0, y: 51.0 }];
let linestring = LineString::from(coords);
assert_eq!(linestring.coords().count(), 2);
}
#[test]
fn test_point_creation() {
let point = Point::new(4.0, 50.0);
assert_eq!(point.x(), 4.0);
assert_eq!(point.y(), 50.0);
}