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: Option<&str>)
pub fn pin(&mut self, id: Option<&str>)
Hold id in place. None releases. Unknown ids are ignored.
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.