Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Dec 13, 2024
1 parent 0793f3b commit 9c1da82
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 83 deletions.
11 changes: 4 additions & 7 deletions crates/lox-bodies/src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ pub struct UnknownOriginName(String);
#[error("no origin with NAIF ID `{0}` is known")]
pub struct UnknownOriginId(i32);

#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, FromPrimitive, ToPrimitive, PartialOrd, Ord)]
#[derive(
Debug, Copy, Clone, Default, Eq, PartialEq, Hash, FromPrimitive, ToPrimitive, PartialOrd, Ord,
)]
pub enum DynOrigin {
Sun = 10,

// Planets.
Mercury = 199,
Venus = 299,
#[default]
Earth = 399,
Mars = 499,
Jupiter = 599,
Expand Down Expand Up @@ -215,12 +218,6 @@ pub enum DynOrigin {
Bennu = 2101955,
}

impl Default for DynOrigin {
fn default() -> Self {
DynOrigin::Earth
}
}

impl Origin for DynOrigin {
fn id(&self) -> NaifId {
NaifId(self.to_i32().unwrap())
Expand Down
8 changes: 1 addition & 7 deletions crates/lox-bodies/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl From<UnknownOriginName> for PyErr {
}

#[pyclass(name = "Origin", module = "lox_space", frozen, eq)]

Check warning on line 27 in crates/lox-bodies/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-bodies/src/python.rs#L27

Added line #L27 was not covered by tests
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct PyOrigin(pub DynOrigin);

#[pymethods]
Expand Down Expand Up @@ -63,9 +63,3 @@ impl PyOrigin {
self.0.name()
}
}

impl Default for PyOrigin {
fn default() -> Self {
Self(DynOrigin::default())
}
}
2 changes: 1 addition & 1 deletion crates/lox-math/src/linear_algebra/tridiagonal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<'a> Tridiagonal<'a> {
}
}

impl<'a> Index<Idx> for Tridiagonal<'a> {
impl Index<Idx> for Tridiagonal<'_> {
type Output = f64;

fn index(&self, (i, j): Idx) -> &Self::Output {
Expand Down
4 changes: 2 additions & 2 deletions crates/lox-math/src/math.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Module math provides common mathematical functions shared by many parts of the library.
use std::f64::consts::{PI, TAU};

use crate::types::units::{Arcseconds, Radians};

/// Module math provides common mathematical functions shared by many parts of the library.
/// Normalizes an angle `a` to the range [center-π, center+π).
pub fn normalize_two_pi(a: Radians, center: Radians) -> Radians {
a - 2.0 * PI * ((a + PI - center) / (2.0 * PI)).floor()
Expand Down
3 changes: 1 addition & 2 deletions crates/lox-orbits/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ use lox_math::roots::Brent;
use lox_math::series::{Series, SeriesError};
use lox_math::types::units::Radians;
use lox_time::deltas::TimeDelta;
use lox_time::julian_dates::JulianDate;
use lox_time::time_scales::Tdb;
use lox_time::transformations::TryToScale;
use lox_time::TimeLike;
use thiserror::Error;

use crate::events::{find_windows, Window};
use crate::frames::{
BodyFixed, DynFrame, FrameTransformationProvider, Icrf, ReferenceFrame, TryRotateTo, TryToFrame,
BodyFixed, DynFrame, FrameTransformationProvider, Icrf, TryRotateTo, TryToFrame,
};
use crate::ground::{DynGroundLocation, GroundLocation};
use crate::states::State;
Expand Down
2 changes: 1 addition & 1 deletion crates/lox-orbits/src/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::f64::consts::TAU;
use float_eq::float_eq;
use glam::{DMat3, DVec3};

use lox_bodies::{DynOrigin, MaybePointMass, Origin, PointMass};
use lox_bodies::{DynOrigin, MaybePointMass, PointMass};
use lox_time::deltas::TimeDelta;
use lox_time::TimeLike;

Expand Down
14 changes: 4 additions & 10 deletions crates/lox-orbits/src/frames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ use crate::frames::iau::icrf_to_bodyfixed;
use crate::frames::iers::{cirf_to_tirf, icrf_to_cirf, tirf_to_itrf};
use crate::rotations::Rotation;
use glam::{DMat3, DVec3};
use lox_bodies::{DynOrigin, MaybeRotationalElements, Origin, RotationalElements, Spheroid};
use lox_bodies::{DynOrigin, MaybeRotationalElements, Origin, RotationalElements};
use lox_math::types::units::Seconds;
use lox_time::prelude::Tdb;
use lox_time::transformations::{OffsetProvider, TryToScale};
use lox_time::transformations::OffsetProvider;
use lox_time::TimeLike;
use thiserror::Error;

Expand Down Expand Up @@ -153,21 +152,16 @@ impl<T: RotationalElements> ReferenceFrame for BodyFixed<T> {
}

Check warning on line 152 in crates/lox-orbits/src/frames.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/frames.rs#L150-L152

Added lines #L150 - L152 were not covered by tests
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
pub enum DynFrame {
#[default]
Icrf,
Cirf,
Tirf,
Itrf,
BodyFixed(DynOrigin),
}

impl Default for DynFrame {
fn default() -> Self {
DynFrame::Icrf
}
}

impl ReferenceFrame for DynFrame {
fn name(&self) -> String {
match self {
Expand Down
3 changes: 1 addition & 2 deletions crates/lox-orbits/src/frames/iau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::rotations::Rotation;
use glam::{DMat3, DVec3};
use lox_bodies::{MaybeRotationalElements, RotationalElements};
use lox_math::types::units::Seconds;
use lox_time::prelude::Tdb;
use lox_time::TimeLike;

pub(crate) fn icrf_to_bodyfixed<T: MaybeRotationalElements>(
Expand Down Expand Up @@ -38,7 +37,7 @@ impl<O: RotationalElements, P: FrameTransformationProvider> TryRotateTo<BodyFixe
&self,
frame: &BodyFixed<O>,
time: T,
provider: &P,
_provider: &P,
) -> Result<Rotation, Self::Error> {
// FIXME
let seconds = time.seconds_since_j2000();
Expand Down
43 changes: 11 additions & 32 deletions crates/lox-orbits/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,13 @@ use lox_time::python::time_scales::PyTimeScale;
use lox_time::python::ut1::{PyNoOpOffsetProvider, PyUt1Provider};
use lox_time::time_scales::Tai;
use lox_time::transformations::TryToScale;
use lox_time::{python::time::PyTime, ut1::DeltaUt1Tai, Time};
use lox_time::{python::time::PyTime, ut1::DeltaUt1Tai};

use crate::analysis::{ElevationMask, ElevationMaskError};
use crate::elements::{DynKeplerian, Keplerian};
use crate::events::{Event, FindEventError, Window};
use crate::frames::{
BodyFixed, CoordinateSystem, DynFrame, ReferenceFrame, TryRotateTo, TryToFrame,
UnknownFrameError,
};
use crate::ground::{
DynGroundLocation, DynGroundPropagator, GroundLocation, GroundPropagator,
GroundPropagatorError, Observables,
};
use crate::frames::{CoordinateSystem, DynFrame, ReferenceFrame, TryRotateTo, UnknownFrameError};
use crate::ground::{DynGroundLocation, DynGroundPropagator, GroundPropagatorError, Observables};
use crate::propagators::semi_analytical::{Vallado, ValladoError};
use crate::propagators::sgp4::{Sgp4, Sgp4Error};
use crate::propagators::Propagator;
Expand Down Expand Up @@ -123,7 +117,7 @@ impl From<UnknownFrameError> for PyErr {

#[pyclass(name = "Frame", module = "lox_space", frozen)]
#[pyo3(eq)]
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
#[derive(Debug, Clone, Default, Eq, PartialEq, Ord, PartialOrd)]
pub struct PyFrame(DynFrame);

#[pymethods]
Expand All @@ -146,12 +140,6 @@ impl PyFrame {
}
}

impl Default for PyFrame {
fn default() -> Self {
Self(DynFrame::default())
}
}

impl FrameTransformationProvider for DeltaUt1Tai {}

impl FrameTransformationProvider for PyNoOpOffsetProvider {}
Expand Down Expand Up @@ -258,9 +246,7 @@ impl PyState {
));
}
Ok(PyKeplerian(
self.0
.try_to_keplerian()
.map_err(|err| PyValueError::new_err(err))?,
self.0.try_to_keplerian().map_err(PyValueError::new_err)?,

Check warning on line 249 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L248-L249

Added lines #L248 - L249 were not covered by tests
))
}

Expand All @@ -270,15 +256,12 @@ impl PyState {
"only inertial frames are supported for the LVLH rotation matrix",
));
}
let rot = self
.0
.try_rotation_lvlh()
.map_err(|err| PyValueError::new_err(err))?;
let rot = self.0.try_rotation_lvlh().map_err(PyValueError::new_err)?;

Check warning on line 259 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L259

Added line #L259 was not covered by tests
let rot: Vec<Vec<f64>> = rot.to_cols_array_2d().iter().map(|v| v.to_vec()).collect();
Ok(PyArray2::from_vec2_bound(py, &rot)?)
}

fn to_ground_location(&self, py: Python<'_>) -> PyResult<PyGroundLocation> {
fn to_ground_location(&self) -> PyResult<PyGroundLocation> {

Check warning on line 264 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L264

Added line #L264 was not covered by tests
Ok(PyGroundLocation(
self.0
.to_dyn_ground_location()
Expand Down Expand Up @@ -407,7 +390,7 @@ impl PyTrajectory {
}
let mut states: Vec<DynState<PyTime>> = Vec::with_capacity(array.nrows());

Check warning on line 391 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L391

Added line #L391 was not covered by tests
for row in array.rows() {
let time = PyTime(start_time.0 + TimeDelta::from_decimal_seconds(row[0]).unwrap());
let time = PyTime(start_time.0 + TimeDelta::from_decimal_seconds(row[0])?);

Check warning on line 393 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L393

Added line #L393 was not covered by tests
let position = DVec3::new(row[1], row[2], row[3]);
let velocity = DVec3::new(row[4], row[5], row[6]);
states.push(State::new(time, position, velocity, origin.0, frame.0));

Check warning on line 396 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L396

Added line #L396 was not covered by tests
Expand Down Expand Up @@ -594,7 +577,7 @@ impl PyGroundLocation {
fn new(origin: PyOrigin, longitude: f64, latitude: f64, altitude: f64) -> PyResult<Self> {
Ok(PyGroundLocation(
DynGroundLocation::with_dynamic(longitude, latitude, altitude, origin.0)
.map_err(|err| PyValueError::new_err(err))?,
.map_err(PyValueError::new_err)?,

Check warning on line 580 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L577-L580

Added lines #L577 - L580 were not covered by tests
))
}

Expand Down Expand Up @@ -662,11 +645,7 @@ impl PyGroundPropagator {
if let Ok(time) = steps.extract::<PyTime>() {
return Ok(Bound::new(
py,
PyState(
self.0
.propagate_dyn(time)
.map_err(|err| PyValueError::new_err(err))?,
),
PyState(self.0.propagate_dyn(time).map_err(PyValueError::new_err)?),

Check warning on line 648 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L648

Added line #L648 was not covered by tests
)?
.into_any());
}
Expand All @@ -676,7 +655,7 @@ impl PyGroundPropagator {
PyTrajectory(
self.0
.propagate_all_dyn(steps)
.map_err(|err| PyValueError::new_err(err))?,
.map_err(PyValueError::new_err)?,

Check warning on line 658 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L657-L658

Added lines #L657 - L658 were not covered by tests
),
)?
.into_any());
Expand Down
19 changes: 0 additions & 19 deletions crates/lox-orbits/src/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,25 +208,6 @@ fn eccentricity_vector(r: DVec3, v: DVec3, mu: f64) -> DVec3 {
((v2 - mu / rm) * r - rv * v) / mu
}

impl<T, O, R> State<T, O, R>
where
T: TimeLike,
O: PointMass,
R: ReferenceFrame,
{
fn eccentricity_vector(&self) -> DVec3 {
let r = self.position();
let v = self.velocity();
let mu = self.origin.gravitational_parameter();

let rm = r.length();
let v2 = v.dot(v);
let rv = r.dot(v);

((v2 - mu / rm) * r - rv * v) / mu
}
}

impl<T, O, R> CoordinateSystem<R> for State<T, O, R>
where
T: TimeLike,
Expand Down

0 comments on commit 9c1da82

Please sign in to comment.