Module

Hylograph.Forces.Measure

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

Measures of how settled a layout is. The definitions are the Rust kernel's (kinetic_energy, max_displacement, max_acceleration and settled in force-kernel/src/lib.rs), and test/differential.mjs holds the two to each other bit for bit.

Kinetic energy is read off the nodes. The other three need to know where the nodes were, so they are kept by a Watch: tell it when a tick begins and when it ends, and ask it afterwards.

#kineticEnergy Source

kineticEnergy :: forall row. Array (Node row) -> Effect Number

Kinetic energy, taking every node to have unit mass: the sum over the nodes, in order, of vx * vx and then vy * vy, halved. After a tick the velocity is the step the node took in it, so this falls toward zero as the layout settles.

#Watch Source

newtype Watch

A record of the last two ticks.

#watch Source

watch :: Effect Watch

A watch that has seen nothing.

#forget Source

forget :: Watch -> Effect Unit

Forget everything: after the nodes are replaced, restored from a snapshot or moved by hand, when what was seen no longer applies.

#before Source

before :: forall row. Watch -> Array (Node row) -> Effect Unit

Call as a tick begins: note where the nodes are.

#after Source

after :: forall row. Watch -> Array (Node row) -> Effect Unit

Call when the tick has ended: work out how far each node moved and how that differs from its step the tick before.

The largest change of step is only meaningful from the second tick on; until then maxAcceleration is zero and settled is false.

#maxDisplacement Source

maxDisplacement :: Watch -> Effect Number

The furthest any node moved in the last tick: the largest distance between where a node was when the tick began and where it ended, everything included (forces, centring, clamps, pins). Zero before the first tick.

#maxAcceleration Source

maxAcceleration :: Watch -> Effect Number

The largest change in any node's step between the last two ticks: the acceleration it actually underwent. A node on a spring is momentarily still at the far end of every swing, where energy and displacement vanish and this is at its largest. Zero until two ticks have been seen.

#settled Source

settled :: { acceleration :: Number, step :: Number } -> Watch -> Effect Boolean

Is the layout at rest? True when, over the last two ticks, no node moved further than step in a tick and no node's step changed by more than acceleration. False until two ticks have been seen.