@@ -15,12 +15,12 @@ pub use edge::*;
1515pub use repulsive:: * ;
1616
1717use crate :: { Graph , SharedNode } ;
18- use alloc:: collections:: BTreeMap ;
1918use alloc:: rc:: Rc ;
2019use core:: cell:: RefCell ;
2120use core:: fmt:: { Debug , Formatter } ;
2221use irox_geometry:: { Point , Vector } ;
2322use irox_tools:: identifier:: { Identifier , SharedIdentifier } ;
23+ use irox_tools:: map:: OrderedHashMap ;
2424use irox_units:: units:: angle:: Angle ;
2525
2626const INITIAL_RADIUS : f64 = 1.0 ;
@@ -123,14 +123,30 @@ pub struct SimulationWorkingEdge {
123123pub trait InitialNodePlacer {
124124 fn place_node ( & mut self , node : & mut SharedNode , working : & mut SimulationWorkingNode ) ;
125125}
126- #[ derive( Debug , Default , Clone ) ]
126+ #[ derive( Debug , Clone ) ]
127127pub struct DefaultNodePlacement {
128+ initial_radius : f64 ,
128129 last_idx : usize ,
129130}
131+ impl DefaultNodePlacement {
132+ #[ must_use]
133+ pub fn with_initial_radius ( mut self , radius : f64 ) -> Self {
134+ self . initial_radius = radius;
135+ self
136+ }
137+ }
138+ impl Default for DefaultNodePlacement {
139+ fn default ( ) -> Self {
140+ Self {
141+ last_idx : 0 ,
142+ initial_radius : INITIAL_RADIUS ,
143+ }
144+ }
145+ }
130146impl InitialNodePlacer for DefaultNodePlacement {
131147 fn place_node ( & mut self , _node : & mut SharedNode , working : & mut SimulationWorkingNode ) {
132148 let idx = self . last_idx ;
133- let init_radius = INITIAL_RADIUS * ( 0.5 + idx as f64 ) . sqrt ( ) ;
149+ let init_radius = self . initial_radius * ( 0.5 + idx as f64 ) . sqrt ( ) ;
134150 let init_angle = INITIAL_ANGLE * ( idx as f64 ) ;
135151 let current_position = Vector {
136152 vx : init_radius * init_angle. cos ( ) ,
@@ -145,8 +161,8 @@ pub struct Simulation {
145161 pub graph : Shared < Graph > ,
146162 pub forces : Vec < Force > ,
147163
148- pub working_nodes : BTreeMap < SharedIdentifier , SimulationWorkingNode > ,
149- pub working_edges : BTreeMap < SharedIdentifier , SimulationWorkingEdge > ,
164+ pub working_nodes : OrderedHashMap < SharedIdentifier , SimulationWorkingNode > ,
165+ pub working_edges : OrderedHashMap < SharedIdentifier , SimulationWorkingEdge > ,
150166
151167 pub params : SimulationParams ,
152168 pub placement : Box < dyn InitialNodePlacer > ,
0 commit comments