siderust/coordinates/transform/frames/
mod.rs

1pub mod to_ecliptic;
2pub mod to_equatorial;
3pub mod to_icrs;
4
5use crate::astro::JulianDate;
6use crate::coordinates::cartesian::Vector;
7use crate::coordinates::centers::ReferenceCenter;
8use crate::coordinates::frames::MutableFrame;
9use crate::coordinates::spherical::SphericalCoord;
10use crate::coordinates::{cartesian, spherical};
11use crate::units::{LengthUnit, Unit};
12
13use crate::coordinates::transform::Transform;
14
15pub trait TransformFrame<Coord> {
16    fn to_frame(&self) -> Coord;
17}
18
19// Implement Identity frame transform
20impl<C, F, U> TransformFrame<Vector<C, F, U>> for Vector<C, F, U>
21where
22    U: Unit,
23    F: MutableFrame,
24    C: ReferenceCenter,
25{
26    fn to_frame(&self) -> Vector<C, F, U> {
27        Vector::new(self.x(), self.y(), self.z())
28    }
29}
30
31impl<C, F1, F2, U> TransformFrame<spherical::Position<C, F2, U>> for spherical::Position<C, F1, U>
32where
33    cartesian::Position<C, F1, U>: TransformFrame<cartesian::Position<C, F2, U>>,
34    C: ReferenceCenter,
35    F1: MutableFrame,
36    F2: MutableFrame,
37    U: LengthUnit,
38{
39    fn to_frame(&self) -> spherical::Position<C, F2, U> {
40        self.to_cartesian().to_frame().to_spherical()
41    }
42}
43
44impl<C, F1, F2> TransformFrame<spherical::Direction<C, F2>> for spherical::Direction<C, F1>
45where
46    cartesian::Direction<C, F1>: TransformFrame<cartesian::Direction<C, F2>>,
47    C: ReferenceCenter,
48    F1: MutableFrame,
49    F2: MutableFrame,
50{
51    fn to_frame(&self) -> spherical::Direction<C, F2> {
52        self.to_cartesian().to_frame().to_spherical()
53    }
54}
55
56impl<C, F, U> SphericalCoord<C, F, U>
57where
58    C: ReferenceCenter,
59    F: MutableFrame,
60    U: crate::units::LengthUnit,
61{
62    pub fn to_frame<F2: MutableFrame>(&self) -> SphericalCoord<C, F2, U>
63    where
64        Vector<C, F, U>: Transform<Vector<C, F2, U>>,
65        Vector<C, F, U>: for<'a> From<&'a SphericalCoord<C, F, U>>, // to_cartesian
66        SphericalCoord<C, F2, U>: for<'a> From<&'a Vector<C, F2, U>>, // to_spherical
67    {
68        self.to_cartesian()
69            .transform(JulianDate::J2000)
70            .to_spherical()
71    }
72}
73
74/*
75#[cfg(test)]
76mod tests {
77    use crate::coordinates::centers;
78    use crate::coordinates::frames;
79    use crate::coordinates::spherical::direction::Direction;
80    use crate::units::DEG;
81
82    #[test]
83    fn test_to_center() {
84        let ecl  =  Direction::<centers::Heliocentric, frames::Ecliptic>::new(90.0*DEG, 45.0*DEG);
85        let equ: Direction<centers::Heliocentric, frames::Equatorial> = ecl.to_frame::<frames::Equatorial>();
86        let expected: Direction<centers::Heliocentric, frames::Equatorial> = (&ecl).into();
87
88        assert_eq!(equ.polar, expected.polar);
89        assert_eq!(equ.azimuth, expected.azimuth);
90        assert_eq!(equ.distance, expected.distance);
91    }
92}
93*/