Skip to content

Commit

Permalink
Merge pull request #6 from nsat/ff-cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
spire-ffoston authored Oct 2, 2020
2 parents 116402a + fee8491 commit c62fe7c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ links = "static=sgp4"

[dependencies]
chrono = { version="0.4" }
itertools = "0.9.0"
time = "0.2.16"
libc = "0.2.71"
thiserror = "1.0"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# sgp4-rs

[![CI Status](https://github.com/nsat/sgp4-rs/workflows/Rust/badge.svg)](https://github.com/nsat/sgp4-rs/actions)
[![Docs](https://docs.rs/sgp4-rs/badge.svg)](https://docs.rs/sgp4-rs/)
[![Crate](https://img.shields.io/crates/v/sgp4-rs)](https://crates.io/crates/sgp4-rs)

This crate implements a wrapper around the C++ implementation of the SGP-4 orbital propagator as
provided in the "Revisiting Spacetrack Report #3" paper
Expand Down
10 changes: 6 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ impl TwoLineElement {
Ok(self.elements.epoch())
}


/// Propagate a TwoLineElement to the given time to obtain a state vector for the object.
pub fn propagate_to(&self, t: DateTime<Utc>) -> Result<StateVector> {
let tle_epoch = self.elements.epoch();
Expand Down Expand Up @@ -231,15 +230,18 @@ mod tests {

#[test]
fn test_julian_day_identity() {
let t = Utc.ymd(2020, 01, 01).and_hms(0, 0, 0);
let t = Utc.ymd(2020, 1, 1).and_hms(0, 0, 0);
assert_eq!(DateTime::<Utc>::from(JulianDay::from(t)), t);
}

#[test]
fn test_gmst_conversion() {
let t = Utc.ymd(2020, 01, 01).and_hms(0, 0, 0);
let t = Utc.ymd(2020, 1, 1).and_hms(0, 0, 0);
let a: f64 = 100.1218209532; // GMST for 2020-01-01T00:00:00 in degrees
let a_rad = a.to_radians();
assert!(sgp4_sys::close(GreenwichMeanSiderealTime::from(t).as_radians(), a_rad));
assert!(sgp4_sys::close(
GreenwichMeanSiderealTime::from(t).as_radians(),
a_rad
));
}
}
45 changes: 21 additions & 24 deletions src/sgp4_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,28 +367,27 @@ impl OrbitalElementSet {
}

pub(crate) fn julian_day_to_datetime(jd: c_double) -> DateTime<Utc> {
let mut year = c_int::default();
let mut month = c_int::default();
let mut day = c_int::default();
let mut hour = c_int::default();
let mut minute = c_int::default();
let mut second = c_double::default();
let mut year = c_int::default();
let mut month = c_int::default();
let mut day = c_int::default();
let mut hour = c_int::default();
let mut minute = c_int::default();
let mut second = c_double::default();

unsafe {
invjday(
jd,
&mut year,
&mut month,
&mut day,
&mut hour,
&mut minute,
&mut second,
);
}

Utc.ymd(year, month as u32, day as u32)
.and_hms(hour as u32, minute as u32, second as u32)
unsafe {
invjday(
jd,
&mut year,
&mut month,
&mut day,
&mut hour,
&mut minute,
&mut second,
);
}

Utc.ymd(year, month as u32, day as u32)
.and_hms(hour as u32, minute as u32, second as u32)
}

pub(crate) fn datetime_to_julian_day(d: DateTime<Utc>) -> c_double {
Expand All @@ -402,7 +401,7 @@ pub(crate) fn datetime_to_julian_day(d: DateTime<Utc>) -> c_double {
d.hour() as c_int,
d.minute() as c_int,
d.second() as c_double,
&mut jd
&mut jd,
);
}

Expand Down Expand Up @@ -477,9 +476,7 @@ pub fn run_sgp4(

pub(crate) fn datetime_to_gstime(d: DateTime<Utc>) -> c_double {
let jd = datetime_to_julian_day(d);
unsafe {
gstime(jd)
}
unsafe { gstime(jd) }
}

#[link(name = "sgp4", kind = "static")]
Expand Down

0 comments on commit c62fe7c

Please sign in to comment.