# `Macaw.Draw.Layout.Force.Forces`
[🔗](https://github.com/dcoai/macaw_draw/blob/v0.1.0/lib/macaw/draw/layout/force/forces.ex#L1)

The seven forces of the force simulation (spec/08 §9.2), each a function of the nodes,
the links, the temperature `alpha` and the force's options.

| Type | Options (defaults) | Effect |
|---|---|---|
| `:center` | `x` (0), `y` (0), `strength` (1) | translates every position so the mean moves toward `{x, y}` by `strength`; ignores `alpha` |
| `:many_body` | `strength` (−30), `distance_min` (1), `distance_max` (`:infinity`) | every pair directly: `v += (other − node) · strength · alpha / d²`, `d` at least `distance_min`, pairs at `d ≥ distance_max` skipped |
| `:link` | `distance` (30), `strength` (1), `iterations` (1) | per link, `k = (d − distance) / d · alpha · strength` over the ends' `pos + vel`, added to the source's velocity and taken from the target's |
| `:collision` | `radius` (10, or a function of a node), `strength` (1), `iterations` (1) | each overlapping pair pushed apart equally, half of `(r − d) / d · strength · alpha` each, summed over every pair before any velocity changes |
| `:x` | `x` (0, or a function), `strength` (0.1) | `vx += (target − x) · strength · alpha` |
| `:y` | `y` (0, or a function), `strength` (0.1) | `vy += (target − y) · strength · alpha` |
| `:radial` | `radius` (100, or a function), `x` (0), `y` (0), `strength` (0.1) | `v += (node − center) · (radius − d) / d · strength · alpha` |

A node is a map with `x`, `y`, `vx`, `vy`; a link a map with `source` and `target`, the
positions of its ends in the node list, and optional `distance` and `strength` that
override the link force's. This is visualize's `Visualize.Layout.Force.Forces`, its
links by position and an unknown force a fault where it raised `CaseClauseError`.

# `link`

```elixir
@type link() :: %{
  :source =&gt; non_neg_integer(),
  :target =&gt; non_neg_integer(),
  optional(:distance) =&gt; number(),
  optional(:strength) =&gt; number()
}
```

A link between two node positions.

# `sim_node`

```elixir
@type sim_node() :: %{
  :x =&gt; number(),
  :y =&gt; number(),
  :vx =&gt; number(),
  :vy =&gt; number(),
  optional(atom()) =&gt; term()
}
```

A simulated node.

# `type`

```elixir
@type type() :: :center | :many_body | :link | :collision | :x | :y | :radial
```

A force type.

# `apply`

```elixir
@spec apply(type(), [sim_node()], [link()], number(), keyword()) ::
  [sim_node()] | Macaw.Draw.Layout.error()
```

The nodes after the force `type` with `opts` at temperature `alpha` (§9.2). An unknown
type is `{[], {:unknown, :force, type}}`, a bad option a fault at `[4, key]`, and a link
whose end is not a node position `{[2, i], {:type, :link}}`.

# `types`

```elixir
@spec types() :: [type()]
```

The force types: `[:center, :many_body, :link, :collision, :x, :y, :radial]`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
