Skip to main content

ForceSimulation

Struct ForceSimulation 

Source
pub struct ForceSimulation { /* private fields */ }

Implementations§

Source§

impl ForceSimulation

Source

pub fn new(spec: SimulationSpec) -> Self

Source

pub fn set_spec(&mut self, spec: SimulationSpec)

Source

pub fn spec(&self) -> &SimulationSpec

Source

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.

Source

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).

Source

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.

Source

pub fn pin(&mut self, id: Option<&str>)

Hold id in place. None releases. Unknown ids are ignored.

Source

pub fn is_active(&self) -> bool

Source

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).

Source

pub fn position(&self, id: &str) -> Option<[f32; 2]>

Source

pub fn velocity(&self, id: &str) -> Option<[f32; 2]>

Source

pub fn positions(&self) -> impl Iterator<Item = (&NodeId, [f32; 2])> + '_

Source

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.

Source

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.

Source

pub fn tick(&mut self) -> bool

Advance one step. Returns false once settled (alpha < alpha_min), so a caller can stop scheduling frames when the graph is at rest.

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.