module GraphRewriting.Layout.Force where

import Data.Vector.Class
import Data.Vector.V2
import GraphRewriting.Layout.Geometry


type Strength = Scalar  Scalar
type Displacement = Vector2  Vector2 -- TODO: should be Position
type Force = Strength  Displacement

fsum  [Force]  Force
fsum :: [Force] -> Force
fsum [] Strength
strength Vector2
pos = Vector2
pos
fsum [Force]
fs Strength
strength Vector2
pos = [Vector2] -> Vector2
focalPoint [Force
f Strength
strength Vector2
pos | Force
f  [Force]
fs]

repulsion  Vector2  Vector2  Force
repulsion :: Vector2 -> Vector2 -> Force
repulsion Vector2
from Vector2
pos = Vector2 -> Force
force (Vector2
pos Vector2 -> Vector2 -> Vector2
forall a. Num a => a -> a -> a
- Vector2
from)

attraction  Vector2  Vector2  Force
attraction :: Vector2 -> Vector2 -> Force
attraction Vector2
towards Vector2
pos = Vector2 -> Force
force (Vector2
towards Vector2 -> Vector2 -> Vector2
forall a. Num a => a -> a -> a
- Vector2
pos)

force  Vector2  Force
force :: Vector2 -> Force
force Vector2
f Strength
strength Vector2
pos = Vector2
pos Vector2 -> Vector2 -> Vector2
forall a. Num a => a -> a -> a
+ Vector2 -> Vector2
forall v. Vector v => v -> v
vnormalise Vector2
f Vector2 -> Scalar -> Vector2
forall v. Vector v => v -> Scalar -> v
|* Strength
strength (Vector2 -> Scalar
forall v. Vector v => v -> Scalar
vmag Vector2
f)