siderust/coordinates/transform/frames/
mod.rs1pub 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
19impl<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>>, SphericalCoord<C, F2, U>: for<'a> From<&'a Vector<C, F2, U>>, {
68 self.to_cartesian()
69 .transform(JulianDate::J2000)
70 .to_spherical()
71 }
72}
73
74