pub struct ForceSimulation { /* private fields */ }Implementations§
Source§impl ForceSimulation
impl ForceSimulation
pub fn new(spec: SimulationSpec) -> Self
pub fn set_spec(&mut self, spec: SimulationSpec)
pub fn spec(&self) -> &SimulationSpec
Sourcepub fn sync(&mut self, graph: &Graph, seed: &HashMap<NodeId, [f32; 2]>)
pub fn sync(&mut self, graph: &Graph, seed: &HashMap<NodeId, [f32; 2]>)
Adopt the graph’s topology, preserving position and velocity for every
id already present. New ids take seed when given — a revealed ghost
enters exactly where it was drawn, so physics continues from the
preview rather than teleporting. Does not reheat; callers decide that.
Sourcepub fn reheat(&mut self)
pub fn reheat(&mut self)
Re-energise after a graph change. Sets alpha unconditionally —
enabled is enforced solely by is_active/tick, so a disabled sim
still accumulates the alpha a later settle_forced needs to have
anything to act on (reduced-motion and physics-disabled hosts reheat
exactly like a live one, then force a settle instead of ticking).
Sourcepub fn reheat_full(&mut self)
pub fn reheat_full(&mut self)
Re-energise from scratch (alpha = 1), for a cold start. See reheat
on why this does not gate on enabled.
Sourcepub fn pin(&mut self, id: &str)
pub fn pin(&mut self, id: &str)
Hold id at its current position. Unknown ids are ignored — a pin
describes a node that is present now, and does not arm itself for one
that arrives later.
Sourcepub fn pin_at(&mut self, id: &str, at: [f32; 2])
pub fn pin_at(&mut self, id: &str, at: [f32; 2])
Hold id at at, moving it there immediately. Unknown ids are ignored.
This is the drag entry point: each pointer move re-places the hold, and the surrounding graph follows through the ordinary force integration. Velocity is cleared so the node does not carry momentum from wherever the simulation was pushing it before the grab.
pub fn is_pinned(&self, id: &str) -> bool
pub fn pinned_ids(&self) -> impl Iterator<Item = &NodeId>
pub fn is_active(&self) -> bool
Sourcepub fn is_unsettled(&self) -> bool
pub fn is_unsettled(&self) -> bool
Whether alpha is still above the settle threshold — is_active
without the enabled term, so a disabled sim can be asked whether it
was frozen mid-settle (and so needs a settle_forced to finish).
pub fn position(&self, id: &str) -> Option<[f32; 2]>
pub fn velocity(&self, id: &str) -> Option<[f32; 2]>
pub fn positions(&self) -> impl Iterator<Item = (&NodeId, [f32; 2])> + '_
Sourcepub fn settle(&mut self, max: usize)
pub fn settle(&mut self, max: usize)
Tick to convergence, bounded by max so a pathological graph cannot
hang the caller. Used by reduced-motion, which snaps rather than
animating.
Sourcepub fn settle_forced(&mut self, max: usize)
pub fn settle_forced(&mut self, max: usize)
settle, but runs even when spec.enabled is false — for hosts that
need a finished layout without any animation (reduced motion, or
physics disabled while the Force layout source is active). The flag is
restored unconditionally before returning; tick runs no host code,
so a scoped set/restore is panic-safe in practice.