miniproj_ops/
traits.rs

1//This file is licensed under EUPL v1.2
2
3use crate::ellipsoid::Ellipsoid;
4
5/// Two-dimensional coordinate operation
6pub trait Projection: Send + Sync {
7    ///Converts from a coordinate in the target coordinate system to lon/lat in EPSG 4326 in radians
8    fn projected_to_rad(&self, x: f64, y: f64) -> (f64, f64);
9
10    ///Converts from a geographic coordinate in radians to a projected coordinate `(x, y)`, usually in meters.
11    fn rad_to_projected(&self, lon: f64, lat: f64) -> (f64, f64);
12
13    ///Converts from projected coordinates to geographic coordinates `(longitude, latitude)` in decimal degrees.
14    fn projected_to_deg(&self, x: f64, y: f64) -> (f64, f64) {
15        let tmp = self.projected_to_rad(x, y);
16        (tmp.0.to_degrees(), tmp.1.to_degrees())
17    }
18
19    ///Converts from a geographic coordinate in degrees to a projected coordinate `(x, y)`, usually in meters.
20    fn deg_to_projected(&self, lon: f64, lat: f64) -> (f64, f64) {
21        self.rad_to_projected(lon.to_radians(), lat.to_radians())
22    }
23}
24
25pub trait PseudoSerialize {
26    fn to_constructed(&self) -> String;
27}
28
29pub trait DbContstruct {
30    fn from_database_params(params: &[(u32, f64)], ellipsoid: &Ellipsoid) -> Self;
31}
32
33pub trait GetterContstruct: Sized {
34    fn with_db_getter<G>(getter: G, ellipsoid: &Ellipsoid) -> Option<Self>
35    where
36        G: FnMut(u32) -> Option<f64>;
37}