lox_frames/
traits.rs

1/*
2 * Copyright (c) 2025. Helge Eichhorn and the LOX contributors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
7 */
8
9use lox_time::{Time, time_scales::TimeScale};
10use thiserror::Error;
11
12use crate::transformations::Rotation;
13
14pub trait ReferenceFrame {
15    fn name(&self) -> String;
16    fn abbreviation(&self) -> String;
17    fn is_rotating(&self) -> bool;
18}
19
20pub trait QuasiInertial: ReferenceFrame {}
21
22#[derive(Clone, Debug, Error, Eq, PartialEq)]
23#[error("{0} is not a quasi-inertial frame")]
24pub struct NonQuasiInertialFrameError(pub String);
25
26pub trait TryQuasiInertial: ReferenceFrame {
27    fn try_quasi_inertial(&self) -> Result<(), NonQuasiInertialFrameError>;
28}
29
30impl<T: QuasiInertial> TryQuasiInertial for T {
31    fn try_quasi_inertial(&self) -> Result<(), NonQuasiInertialFrameError> {
32        Ok(())
33    }
34}
35
36pub trait BodyFixed: ReferenceFrame {}
37
38#[derive(Clone, Debug, Error)]
39#[error("{0} is not a body-fixed frame")]
40pub struct NonBodyFixedFrameError(pub String);
41
42pub trait TryBodyFixed: ReferenceFrame {
43    fn try_body_fixed(&self) -> Result<(), NonBodyFixedFrameError>;
44}
45
46impl<T: BodyFixed> TryBodyFixed for T {
47    fn try_body_fixed(&self) -> Result<(), NonBodyFixedFrameError> {
48        Ok(())
49    }
50}
51
52pub trait TryRotateTo<T: TimeScale, R: ReferenceFrame, P> {
53    type Error;
54
55    fn try_rotation(
56        &self,
57        frame: R,
58        time: Time<T>,
59        provider: Option<&P>,
60    ) -> Result<Rotation, Self::Error>;
61}