Skip to main content

lox_frames/
traits.rs

1// SPDX-FileCopyrightText: 2025 Helge Eichhorn <git@helgeeichhorn.de>
2//
3// SPDX-License-Identifier: MPL-2.0
4
5use thiserror::Error;
6
7pub(crate) mod private {
8    pub struct Internal;
9}
10
11pub trait ReferenceFrame {
12    fn name(&self) -> String;
13    fn abbreviation(&self) -> String;
14    #[doc(hidden)]
15    fn frame_id(&self, _: private::Internal) -> Option<usize> {
16        None
17    }
18}
19
20pub fn frame_id(frame: &impl ReferenceFrame) -> Option<usize> {
21    frame.frame_id(private::Internal)
22}
23
24pub trait QuasiInertial: ReferenceFrame {}
25
26#[derive(Clone, Debug, Error, Eq, PartialEq)]
27#[error("{0} is not a quasi-inertial frame")]
28pub struct NonQuasiInertialFrameError(pub String);
29
30pub trait TryQuasiInertial: ReferenceFrame {
31    fn try_quasi_inertial(&self) -> Result<(), NonQuasiInertialFrameError>;
32}
33
34impl<T: QuasiInertial> TryQuasiInertial for T {
35    fn try_quasi_inertial(&self) -> Result<(), NonQuasiInertialFrameError> {
36        Ok(())
37    }
38}
39
40pub trait BodyFixed: ReferenceFrame {}
41
42#[derive(Clone, Debug, Error)]
43#[error("{0} is not a body-fixed frame")]
44pub struct NonBodyFixedFrameError(pub String);
45
46pub trait TryBodyFixed: ReferenceFrame {
47    fn try_body_fixed(&self) -> Result<(), NonBodyFixedFrameError>;
48}
49
50impl<T: BodyFixed> TryBodyFixed for T {
51    fn try_body_fixed(&self) -> Result<(), NonBodyFixedFrameError> {
52        Ok(())
53    }
54}