Module

Hylograph.Forces.Snapshot

Package
purescript-hylograph-forces
Repository
afcondon/purescript-hylograph-forces

Snapshot and restore: everything that changes as a simulation runs, as one immutable value.

The forces keep no state between ticks (each rebuilds what it needs from the nodes), so what changes is alpha, the random source, and each node's position, velocity and pins. Restoring a snapshot and running N ticks gives exactly what N more ticks would have given when it was taken, as long as the forces and settings are the same; they are configuration, not state, and are not in the snapshot.

The Rust kernel has the same pair (snapshot and restore in force-kernel/src/lib.rs), and test/differential.mjs checks both against each other across a restore.

#Snapshot Source

newtype Snapshot

The state of a simulation at one moment.

#take Source

take :: forall row. Source -> Number -> Array (Node (Pinnable row)) -> Effect Snapshot

Record the simulation as it is: the alpha to give the next tick, the random source, and the nodes.

#restore Source

restore :: forall row. Snapshot -> Source -> Array (Node (Pinnable row)) -> Effect Number

Put the nodes and the random source back as the snapshot recorded them, and return the alpha to give the next tick. The nodes are matched by place; if there are more or fewer than were recorded, the extra ones on either side are left alone.