pub mod step;
pub mod transformer;
use super::{BaseProjection, Coords, Proj};
use alloc::{boxed::Box, rc::Rc};
use core::cell::RefCell;
use s2json::VectorPoint;
pub use step::*;
pub use transformer::*;
#[derive(Debug, Clone, PartialEq)]
pub struct ProjectionTransform {
pub proj: Rc<RefCell<Proj>>,
pub method: Step,
pub axisswap: Option<Box<ProjectionTransform>>,
pub cart: Option<Box<ProjectionTransform>>,
pub cart_wgs84: Option<Box<ProjectionTransform>>,
pub helmert: Option<Box<ProjectionTransform>>,
pub hgridshift: Option<Box<ProjectionTransform>>,
pub vgridshift: Option<Box<ProjectionTransform>>,
}
impl Default for ProjectionTransform {
fn default() -> Self {
let proj = Rc::new(RefCell::new(Proj::default()));
let method = BaseProjection::new(proj.clone());
Self {
proj,
method: method.into(),
axisswap: None,
cart: None,
cart_wgs84: None,
helmert: None,
hgridshift: None,
vgridshift: None,
}
}
}
impl ProjectionTransform {
pub fn wgs84() -> Self {
Self {
proj: Rc::new(RefCell::new(Proj::default())),
method: BaseProjection::to_step(),
axisswap: None,
cart: None,
cart_wgs84: None,
helmert: None,
hgridshift: None,
vgridshift: None,
}
}
}
pub trait TransformCoordinates: Clone + Default {
fn x(&self) -> f64;
fn y(&self) -> f64;
fn z(&self) -> f64;
fn t(&self) -> f64;
fn set_x(&mut self, x: f64);
fn set_y(&mut self, y: f64);
fn set_z(&mut self, z: f64);
fn set_t(&mut self, t: f64);
fn get(&self, idx: usize) -> f64 {
match idx {
0 => self.x(),
1 => self.y(),
2 => self.z(),
3 => self.t(),
_ => panic!("Invalid index"),
}
}
fn set(&mut self, idx: usize, val: f64) {
match idx {
0 => self.set_x(val),
1 => self.set_y(val),
2 => self.set_z(val),
3 => self.set_t(val),
_ => panic!("Invalid index"),
}
}
fn u(&self) -> f64 {
self.x()
}
fn set_u(&mut self, u: f64) {
self.set_x(u)
}
fn lam(&self) -> f64 {
self.x()
}
fn set_lam(&mut self, lam: f64) {
self.set_x(lam)
}
fn s(&self) -> f64 {
self.x()
}
fn set_s(&mut self, s: f64) {
self.set_x(s)
}
fn o(&self) -> f64 {
self.x()
}
fn set_o(&mut self, o: f64) {
self.set_x(o)
}
fn e(&self) -> f64 {
self.x()
}
fn set_e(&mut self, e: f64) {
self.set_x(e)
}
fn v(&self) -> f64 {
self.y()
}
fn set_v(&mut self, v: f64) {
self.set_y(v)
}
fn phi(&self) -> f64 {
self.y()
}
fn set_phi(&mut self, phi: f64) {
self.set_y(phi)
}
fn a1(&self) -> f64 {
self.y()
}
fn set_a1(&mut self, t: f64) {
self.set_y(t)
}
fn p(&self) -> f64 {
self.y()
}
fn set_p(&mut self, t: f64) {
self.set_y(t)
}
fn n(&self) -> f64 {
self.y()
}
fn set_n(&mut self, n: f64) {
self.set_y(n)
}
fn has_z(&self) -> bool;
fn w(&self) -> f64 {
self.z()
}
fn set_w(&mut self, w: f64) {
self.set_z(w)
}
fn a2(&self) -> f64 {
self.z()
}
fn set_a2(&mut self, a2: f64) {
self.set_z(a2)
}
fn k(&self) -> f64 {
self.z()
}
fn set_k(&mut self, k: f64) {
self.set_z(k)
}
fn up(&self) -> f64 {
self.z()
}
fn set_up(&mut self, up: f64) {
self.set_z(up)
}
}
impl<M: Default + Clone> TransformCoordinates for VectorPoint<M> {
fn x(&self) -> f64 {
self.x
}
fn y(&self) -> f64 {
self.y
}
fn z(&self) -> f64 {
self.z.unwrap_or(0.)
}
fn t(&self) -> f64 {
0.
}
fn set_x(&mut self, x: f64) {
self.x = x
}
fn set_y(&mut self, y: f64) {
self.y = y
}
fn set_z(&mut self, z: f64) {
self.z = Some(z);
}
fn set_t(&mut self, t: f64) {
self.t = Some(t);
}
fn has_z(&self) -> bool {
self.z.is_some()
}
}
impl TransformCoordinates for Coords {
fn x(&self) -> f64 {
self.0
}
fn y(&self) -> f64 {
self.1
}
fn z(&self) -> f64 {
self.2
}
fn t(&self) -> f64 {
self.3
}
fn set_x(&mut self, x: f64) {
self.0 = x
}
fn set_y(&mut self, y: f64) {
self.1 = y
}
fn set_z(&mut self, z: f64) {
self.2 = z
}
fn set_t(&mut self, t: f64) {
self.3 = t
}
fn has_z(&self) -> bool {
self.z() != 0.
}
}