Skip to content

Commit 1dfa01c

Browse files
committed
feat(lox-frames): add frame ID to builtin frames
WIP
1 parent 50a7a3a commit 1dfa01c

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

crates/lox-frames/src/dynamic.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
providers::DefaultTransformProvider,
1515
traits::{
1616
NonBodyFixedFrameError, NonQuasiInertialFrameError, ReferenceFrame, TryBodyFixed,
17-
TryQuasiInertial,
17+
TryQuasiInertial, frame_id,
1818
},
1919
transformations::{Rotation, TryTransform},
2020
};
@@ -65,6 +65,16 @@ impl ReferenceFrame for DynFrame {
6565
DynFrame::Tirf | DynFrame::Itrf | DynFrame::Iau(_) => true,
6666
}
6767
}
68+
69+
fn frame_id(&self, _: crate::traits::private::Internal) -> Option<i32> {
70+
match self {
71+
DynFrame::Icrf => frame_id(Icrf),
72+
DynFrame::Cirf => frame_id(Cirf),
73+
DynFrame::Tirf => frame_id(Tirf),
74+
DynFrame::Itrf => frame_id(Itrf),
75+
DynFrame::Iau(dyn_origin) => Some(1000 + dyn_origin.id().0),
76+
}
77+
}
6878
}
6979

7080
impl TryQuasiInertial for DynFrame {
@@ -168,7 +178,7 @@ mod tests {
168178
use super::*;
169179

170180
use glam::DVec3;
171-
use lox_bodies::DynOrigin;
181+
use lox_bodies::{DynOrigin, Earth};
172182
use lox_test_utils::assert_approx_eq;
173183
use lox_time::utc::Utc;
174184
use rstest::rstest;
@@ -223,4 +233,16 @@ mod tests {
223233
assert_approx_eq!(r_act, r_exp, rtol <= 1e-8);
224234
assert_approx_eq!(v_act, v_exp, rtol <= 1e-5);
225235
}
236+
237+
#[test]
238+
fn test_frame_id() {
239+
assert_eq!(frame_id(Icrf), frame_id(DynFrame::Icrf));
240+
assert_eq!(frame_id(Cirf), frame_id(DynFrame::Cirf));
241+
assert_eq!(frame_id(Tirf), frame_id(DynFrame::Tirf));
242+
assert_eq!(frame_id(Itrf), frame_id(DynFrame::Itrf));
243+
assert_eq!(
244+
frame_id(Iau::new(Earth)),
245+
frame_id(DynFrame::Iau(DynOrigin::Earth))
246+
);
247+
}
226248
}

crates/lox-frames/src/frames.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// SPDX-License-Identifier: MPL-2.0
44

5-
use lox_bodies::{RotationalElements, TryRotationalElements, UndefinedOriginPropertyError};
5+
use lox_bodies::{Origin, RotationalElements, TryRotationalElements, UndefinedOriginPropertyError};
66

77
use crate::traits::{BodyFixed, QuasiInertial, ReferenceFrame};
88

@@ -21,6 +21,10 @@ impl ReferenceFrame for Icrf {
2121
fn is_rotating(&self) -> bool {
2222
false
2323
}
24+
25+
fn frame_id(&self, _: crate::traits::private::Internal) -> Option<i32> {
26+
Some(0)
27+
}
2428
}
2529

2630
impl QuasiInertial for Icrf {}
@@ -40,6 +44,10 @@ impl ReferenceFrame for Cirf {
4044
fn is_rotating(&self) -> bool {
4145
false
4246
}
47+
48+
fn frame_id(&self, _: crate::traits::private::Internal) -> Option<i32> {
49+
Some(1)
50+
}
4351
}
4452

4553
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -57,6 +65,10 @@ impl ReferenceFrame for Tirf {
5765
fn is_rotating(&self) -> bool {
5866
true
5967
}
68+
69+
fn frame_id(&self, _: crate::traits::private::Internal) -> Option<i32> {
70+
Some(2)
71+
}
6072
}
6173

6274
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -74,6 +86,10 @@ impl ReferenceFrame for Itrf {
7486
fn is_rotating(&self) -> bool {
7587
true
7688
}
89+
90+
fn frame_id(&self, _: crate::traits::private::Internal) -> Option<i32> {
91+
Some(3)
92+
}
7793
}
7894

7995
impl BodyFixed for Itrf {}
@@ -119,7 +135,7 @@ impl<T: TryRotationalElements> BodyFixed for Iau<T> {}
119135

120136
impl<T> ReferenceFrame for Iau<T>
121137
where
122-
T: TryRotationalElements,
138+
T: TryRotationalElements + Origin,
123139
{
124140
fn name(&self) -> String {
125141
let body = self.0.name();
@@ -137,4 +153,8 @@ where
137153
fn is_rotating(&self) -> bool {
138154
true
139155
}
156+
157+
fn frame_id(&self, _: crate::traits::private::Internal) -> Option<i32> {
158+
Some(1000 + self.0.id().0)
159+
}
140160
}

crates/lox-frames/src/traits.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@
44

55
use thiserror::Error;
66

7+
pub(crate) mod private {
8+
pub struct Internal;
9+
}
10+
711
pub trait ReferenceFrame {
812
fn name(&self) -> String;
913
fn abbreviation(&self) -> String;
1014
fn is_rotating(&self) -> bool;
15+
#[doc(hidden)]
16+
fn frame_id(&self, _: private::Internal) -> Option<i32> {
17+
None
18+
}
19+
}
20+
21+
pub fn frame_id(frame: impl ReferenceFrame) -> Option<i32> {
22+
frame.frame_id(private::Internal)
1123
}
1224

1325
pub trait QuasiInertial: ReferenceFrame {}

0 commit comments

Comments
 (0)