Module
Hylograph.Forces.ThreeD.Center
- Package
- purescript-hylograph-forces
- Repository
- afcondon/purescript-hylograph-forces
The centring force in three dimensions: shift every node so that their mean position sits at a given point. It moves positions, not velocities.
Ported from d3-force-3d 3.0.6, center.js (MIT, Copyright 2017 Vasco
Asturiano; itself from d3-force, ISC, Mike Bostock); see LICENSE.
Not d3-force's center.js with a third coordinate: d3-force-3d counts a
coordinate that is NaN as zero in the sum (sx += node.x || 0), and
leaves an axis alone when its shift is zero or NaN (if (sx) node.x
-= sx), which also keeps a -0 coordinate -0.
#defaultConfig Source
defaultConfig :: Configd3-force-3d's defaults: the origin, at full strength.
#initialize Source
initialize :: forall row. Config -> Array (Node row) -> Center rowd3's force.initialize(nodes).
#apply Source
apply :: forall row. Center row -> Effect Unitd3-force-3d's force():
for (i = 0; i < n; ++i) node = nodes[i], sx += node.x || 0, sy += node.y || 0, sz += node.z || 0;
for (sx = (sx / n - x) * strength, sy = ..., sz = ..., i = 0; i < n; ++i) {
node = nodes[i];
if (sx) { node.x -= sx }
if (sy) { node.y -= sy; }
if (sz) { node.z -= sz; }
}
- Modules
- Hylograph.
Forces - Hylograph.
Forces. Center - Hylograph.
Forces. Cohesion - Hylograph.
Forces. Collide - Hylograph.
Forces. Contain - Hylograph.
Forces. Directional - Hylograph.
Forces. Group - Hylograph.
Forces. Link - Hylograph.
Forces. Linkage - Hylograph.
Forces. ManyBody - Hylograph.
Forces. Measure - Hylograph.
Forces. Node - Hylograph.
Forces. Position - Hylograph.
Forces. Quadtree - Hylograph.
Forces. Radial - Hylograph.
Forces. Random - Hylograph.
Forces. RectCollide - Hylograph.
Forces. Snapshot - Hylograph.
Forces. ThreeD - Hylograph.
Forces. ThreeD. Center - Hylograph.
Forces. ThreeD. Collide - Hylograph.
Forces. ThreeD. Link - Hylograph.
Forces. ThreeD. ManyBody - Hylograph.
Forces. ThreeD. Node - Hylograph.
Forces. ThreeD. Octree - Hylograph.
Forces. ThreeD. Position - Hylograph.
Forces. ThreeD. Radial - Hylograph.
Forces. ThreeD. Tick - Hylograph.
Forces. Tick - Hylograph.
Forces. Towards