From a0a3b3974cab754c10a1517d82762b99482970ce Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Tue, 12 May 2026 19:01:27 -0400 Subject: update packages to latest versions --- src/solar_system.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/solar_system.rs') 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, + heirarchy: NTreeNode } impl SolarSystem { + fn rebuild_system_heirarchy( + bodies: &[OrbitalBody], + root: &mut NTreeNode) + { + 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 + { &self.heirarchy } + pub fn body_position( &self, body: &OrbitalBody, -- cgit v1.2.3