module GraphRewriting.Layout.Force where
import Data.Vector
import GraphRewriting.Layout.Geometry
type Strength = Scalar → Scalar
type Displacement = Vector2 → Vector2
type Force = Strength → Displacement
fsum ∷ [Force] → Force
fsum [] strength pos = pos
fsum fs strength pos = focalPoint [f strength pos | f ← fs]
repulsion ∷ Vector2 → Vector2 → Force
repulsion from pos = force (pos from)
attraction ∷ Vector2 → Vector2 → Force
attraction towards pos = force (towards pos)
force ∷ Vector2 → Force
force f strength pos = pos + vnormalise f *| strength (vmag f)