galileo_types/geo/traits/
point.rs1use num_traits::Float;
2
3use crate::geo::traits::projection::Projection;
4use crate::geometry::{Geom, GeometrySpecialization};
5use crate::geometry_type::{GeoSpace2d, GeometryType, PointGeometryType};
6
7pub trait GeoPoint {
9 type Num: Float;
11
12 fn lat(&self) -> Self::Num;
14 fn lon(&self) -> Self::Num;
16
17 fn lat_rad(&self) -> Self::Num {
19 self.lat().to_radians()
20 }
21
22 fn lon_rad(&self) -> Self::Num {
24 self.lon().to_radians()
25 }
26}
27
28pub trait NewGeoPoint<N = f64>: GeoPoint<Num = N> + Sized {
30 fn latlon(lat: N, lon: N) -> Self;
32 fn lonlat(lon: N, lat: N) -> Self {
34 Self::latlon(lat, lon)
35 }
36}
37
38impl<P> GeometrySpecialization<PointGeometryType, GeoSpace2d> for P
39where
40 P: GeoPoint + GeometryType<Type = PointGeometryType, Space = GeoSpace2d>,
41{
42 type Point = P;
43
44 fn project_spec<Proj>(&self, projection: &Proj) -> Option<Geom<Proj::OutPoint>>
45 where
46 Proj: Projection<InPoint = Self::Point> + ?Sized,
47 {
48 Some(Geom::Point(projection.project(self)?))
49 }
50}