Skip to content

Commit

Permalink
Define getters on CoefficientKernel
Browse files Browse the repository at this point in the history
  • Loading branch information
AngusGMorrison committed Nov 8, 2023
1 parent a511c5c commit a548c7d
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 178 deletions.
14 changes: 11 additions & 3 deletions crates/lox_core/src/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,21 @@ pub fn gravitational_parameter<T: PointMass>(_: T) -> f64 {
<T as PointMass>::gravitational_parameter()
}

const N_COEFFICIENTS: usize = 18;
pub const N_COEFFICIENTS: usize = 18;

type PolynomialCoefficients = (f64, f64, f64, [f64; N_COEFFICIENTS]);
type NutationPrecessionCoefficients = ([f64; N_COEFFICIENTS], [f64; N_COEFFICIENTS]);
pub struct PolynomialCoefficients(f64, f64, f64, [f64; N_COEFFICIENTS]);

pub struct NutationPrecessionCoefficients(pub [f64; N_COEFFICIENTS], pub [f64; N_COEFFICIENTS]);

impl Default for NutationPrecessionCoefficients {
fn default() -> Self {
Self([0.0; N_COEFFICIENTS], [0.0; N_COEFFICIENTS])
}
}

pub trait RotationalElements {
fn nutation_precession_coefficients() -> NutationPrecessionCoefficients;

fn right_ascension_coefficients() -> PolynomialCoefficients;

fn declination_coefficients() -> PolynomialCoefficients;
Expand Down
21 changes: 11 additions & 10 deletions tools/lox_gen/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/lox_gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ proc-macro2 = "1.0"
quote = "1.0"
lox_io = { path = "../../crates/lox_io" }
lox_core = { path = "../../crates/lox_core" }
thiserror = "1.0.50"
43 changes: 10 additions & 33 deletions tools/lox_gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote};

use lox_io::spice::Kernel;
use naif_ids::{Body, BARYCENTERS, MINOR_BODIES, PLANETS, SATELLITES, SUN};
use naif_ids::{BARYCENTERS, Body, MINOR_BODIES, PLANETS, SATELLITES, SUN};

use crate::rotational_elements::{BarycenterTrigElements, BodyRotationalElements};
use crate::rotational_elements::RotationalElements;

mod naif_ids;
mod rotational_elements;
Expand Down Expand Up @@ -46,27 +46,27 @@ pub fn main() {
(
"sun",
Vec::from(SUN),
vec![naif_id, point_mass, spheroid, body_rotational_elements],
vec![naif_id, point_mass, spheroid, rotational_elements],
),
(
"barycenters",
Vec::from(BARYCENTERS),
vec![naif_id, point_mass, barycenter_rotational_elements],
vec![naif_id, point_mass],
),
(
"planets",
Vec::from(PLANETS),
vec![naif_id, point_mass, spheroid, body_rotational_elements],
vec![naif_id, point_mass, spheroid, rotational_elements],
),
(
"satellites",
Vec::from(SATELLITES),
vec![naif_id, point_mass, tri_axial, body_rotational_elements],
vec![naif_id, point_mass, tri_axial, rotational_elements],
),
(
"minor",
Vec::from(MINOR_BODIES),
vec![naif_id, point_mass, tri_axial, body_rotational_elements],
vec![naif_id, point_mass, tri_axial, rotational_elements],
),
];
bodies
Expand Down Expand Up @@ -305,8 +305,8 @@ fn point_mass(
};
}

/// Generates implementations for [lox_core::bodies::BodyRotationalElements].
fn body_rotational_elements(
/// Generates implementations for [lox_core::bodies::RotationalElements].
fn rotational_elements(
imports: &mut HashSet<Ident>,
code: &mut TokenStream,
tests: &mut TokenStream,
Expand All @@ -315,7 +315,7 @@ fn body_rotational_elements(
data: &Data,
) {
let elements =
if let Some(elements) = BodyRotationalElements::parse(*id as u32, ident, &data.pck) {
if let Some(elements) = RotationalElements::parse(*id as u32, ident, &data.pck) {
elements
} else {
return;
Expand All @@ -332,26 +332,3 @@ fn body_rotational_elements(
code.extend(elements.code_tokens());
tests.extend(elements.test_tokens());
}

fn barycenter_rotational_elements(
imports: &mut HashSet<Ident>,
code: &mut TokenStream,
tests: &mut TokenStream,
ident: &Ident,
id: &i32,
data: &Data,
) {
let elements =
if let Some(elements) = BarycenterTrigElements::parse(*id as u32, ident, &data.pck) {
elements
} else {
return;
};

imports.extend([
format_ident!("BarycenterTrigRotationalElements"),
format_ident!("PolynomialCoefficient"),
]);
code.extend(elements.code_tokens());
tests.extend(elements.test_tokens());
}
Loading

0 comments on commit a548c7d

Please sign in to comment.