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: &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.

Source

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.

Source

pub fn unpin(&mut self, id: &str)

Release id. Unknown or unpinned ids are ignored.

Source

pub fn unpin_all(&mut self)

Release every pin.

Source

pub fn is_pinned(&self, id: &str) -> bool

Source

pub fn pinned_ids(&self) -> impl Iterator<Item = &NodeId>

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.