pub struct Simulation { /* private fields */ }Expand description
Public force simulation handle. Owns positions, velocities, edges, and a scratch quadtree that gets rebuilt every tick.
In 2D mode (config.dimensions == 2, the default) only the
positions/velocities/forces vectors and the tree quadtree
are used. In 3D mode the parallel positions_3d/velocities_3d/
forces_3d vectors are populated alongside an oct_tree octree,
and positions mirrors the x/y pair of each 3D position so the
positions() accessor stays zero-copy for the common 2D readers.
Implementations§
Source§impl Simulation
impl Simulation
Sourcepub fn new(n_nodes: u32, config: SimulationConfig) -> Self
pub fn new(n_nodes: u32, config: SimulationConfig) -> Self
Build a simulation with n_nodes nodes. Initial positions are
scattered uniformly inside a circle of radius sqrt(n) * 10
using a deterministic ChaCha8 RNG seeded from config.seed.
When config.dimensions == 3, the 3D positions_3d field is
also populated with points scattered inside a ball of the same
radius; the 2D positions field mirrors the x/y slice of each
3D point so consumers of the 2D accessor continue to see a
sensible layout.
Sourcepub fn set_edges(&mut self, edges: &[(u32, u32, f32)])
pub fn set_edges(&mut self, edges: &[(u32, u32, f32)])
Replace the edge set. Each edge is (src, dst, weight).
Out-of-range or self-loop indices are silently dropped — callers
who care should validate upstream.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes in the simulation.
Sourcepub fn positions(&self) -> &[Vec2]
pub fn positions(&self) -> &[Vec2]
Borrow positions as a flat &[Vec2] for zero-copy consumption
by downstream bindings.
Sourcepub fn positions_3d(&self) -> &[Vec3]
pub fn positions_3d(&self) -> &[Vec3]
Borrow 3D positions as a flat &[Vec3]. Returns an empty slice
when the simulation was constructed in 2D mode. Phase 224 Wave 2.