Skip to main content

Simulation

Struct Simulation 

Source
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

Source

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.

Source

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.

Source

pub fn node_count(&self) -> usize

Number of nodes in the simulation.

Source

pub fn positions(&self) -> &[Vec2]

Borrow positions as a flat &[Vec2] for zero-copy consumption by downstream bindings.

Source

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.

Source

pub fn tick(&mut self, dt: f32)

Advance the simulation by one tick of size dt. Routes to the 3D octree pass when config.dimensions == 3, otherwise runs the 2D quadtree path.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V