Module

Hylograph.Forces.ThreeD.Collide

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

The collision force in three dimensions: treat each node as a sphere and push overlapping spheres apart.

Ported from d3-force-3d 3.0.6, collide.js (MIT, Copyright 2017 Vasco Asturiano; itself from d3-force, ISC, Mike Bostock); see LICENSE. It is d3-force's collide.js with a third coordinate, over d3-octree, and the shape is Hylograph.Forces.Collide's: each iteration builds the octree of where the nodes are about to be (x + vx), turns it into a chain of Regions that know the largest radius inside them, and walks the chain once per node. A walk returns the node's new velocity and the new velocities of the nodes it pushed, which are written when it returns.

Like d3, this looks only at the newest of several nodes at exactly the same place.

#Config Source

type Config :: Row Type -> Typetype Config row = { iterations :: Int, radius :: Node row -> Number, strength :: Number }

forceCollide settings. radius is asked once per node when the force is initialized.

#defaultConfig Source

defaultConfig :: forall row. Config row

d3's defaults: radius 1, full strength, one iteration.

#Collide Source

newtype Collide :: Row Type -> Typenewtype Collide row

An initialized collision force.

#initialize Source

initialize :: forall row. Config row -> Source -> Array (Node row) -> Collide row

force.initialize(nodes, random, 3).

#apply Source

apply :: forall row. Collide row -> Effect Unit

force(): resolve overlaps, iterations times over.