use std::ops::Index;
use astro_units::mass::solar_mass;
use uom::si::{
f64::{Mass, Time},
time::year,
};
use super::line::ParsecLine;
#[derive(Clone)]
pub struct Trajectory {
params: Vec<ParsecLine>,
pub initial_mass: Mass,
pub lifetime: Time,
pub ages_in_years: Vec<f64>,
}
impl Index<usize> for Trajectory {
type Output = ParsecLine;
fn index(&self, index: usize) -> &Self::Output {
&self.params[index]
}
}
impl Trajectory {
pub(super) fn new(params: Vec<ParsecLine>) -> Self {
let initial_mass = match params.first() {
Some(params) => params.mass,
None => Mass::new::<solar_mass>(0.),
};
let lifetime = match params.last() {
Some(last) => last.age,
None => Time::new::<year>(0.),
};
let ages_in_years = params.iter().map(|line| line.age.get::<year>()).collect();
Self {
params,
initial_mass,
lifetime,
ages_in_years,
}
}
pub(super) fn is_empty(&self) -> bool {
self.params.is_empty()
}
}
#[cfg(test)]
mod test {
use super::Trajectory;
#[test]
fn constructor_with_empty_params_does_not_throw() {
let trajectory = Trajectory::new(vec![]);
assert!(trajectory.is_empty());
}
}