diff options
| author | Jon Santmyer <jon@jonsantmyer.com> | 2026-05-12 19:01:27 -0400 |
|---|---|---|
| committer | Jon Santmyer <jon@jonsantmyer.com> | 2026-05-12 19:01:27 -0400 |
| commit | a0a3b3974cab754c10a1517d82762b99482970ce (patch) | |
| tree | 8aeb0ca1e007bacecc8e12a263bd5aa321b8f69a /src/solar_system.rs | |
| parent | 7f63ec5c10eb7e8dd4edaabd1a6a437328911d39 (diff) | |
| download | systemic4x-a0a3b3974cab754c10a1517d82762b99482970ce.tar.gz systemic4x-a0a3b3974cab754c10a1517d82762b99482970ce.tar.bz2 systemic4x-a0a3b3974cab754c10a1517d82762b99482970ce.zip | |
Diffstat (limited to 'src/solar_system.rs')
| -rw-r--r-- | src/solar_system.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/solar_system.rs b/src/solar_system.rs index 94508fd..7799a59 100644 --- a/src/solar_system.rs +++ b/src/solar_system.rs @@ -6,6 +6,8 @@ use self::orbit::*; use serde::{Deserialize}; use crate::known_stars::*; +use crate::ntree::NTree; +use crate::ntree::NTreeNode; use crate::timeman::Second; use std::error::Error; @@ -42,10 +44,26 @@ pub struct SolarSystem name: String, bodies: Vec<OrbitalBody>, + heirarchy: NTreeNode<BodyId> } impl SolarSystem { + fn rebuild_system_heirarchy( + bodies: &[OrbitalBody], + root: &mut NTreeNode<BodyId>) + { + for body in bodies { + if let Some(orbit) = body.orbit() { + if orbit.parent() == *root.value() { + let mut subtree = NTreeNode::new(body.id()); + SolarSystem::rebuild_system_heirarchy(bodies, &mut subtree); + root.insert_node(subtree); + } + } + } + } + pub fn new_from_csv( id: SystemId, data: &'static str) @@ -69,13 +87,17 @@ impl SolarSystem //if record.radius == 0.0 { continue; } println!("New body: {:?}", record); - bodies.push(OrbitalBody::new_from_record(bodies.len(), record)); + bodies.push(OrbitalBody::new_from_record(bodies.len(), id, record)); } + let mut heirarchy_root = NTreeNode::new(0); + SolarSystem::rebuild_system_heirarchy(&bodies, &mut heirarchy_root); + Ok(Self { id: id, name: bodies[0].name().clone(), bodies: bodies, + heirarchy: heirarchy_root }) } @@ -102,6 +124,9 @@ impl SolarSystem pub fn body(&self, id: BodyId) -> &OrbitalBody { &self.bodies[id] } + pub fn heirarchy(&self) -> &NTreeNode<BodyId> + { &self.heirarchy } + pub fn body_position( &self, body: &OrbitalBody, |
