# `Macaw.Draw.Shape.Curve`
[🔗](https://github.com/dcoai/macaw_draw/blob/v0.1.0/lib/macaw/draw/shape/curve.ex#L1)

The curve interpolators of lines and areas (spec/07 §5), copied from visualize's
`Visualize.Shape.Curve`: how a run of points is joined into a path.

`generate(type, points, opts)` answers a `Macaw.Draw.IR.Path`. A type is an atom or its
string, read by spelling (spec/06 §1.3); `types/0` lists the twelve. Options are read
only by the curves that take one: `tension` (`:cardinal`, `:cardinal_closed`, default
`0`) and `alpha` (`:catmull_rom`, default `0.5`).

    iex> alias Macaw.Draw.Shape.Curve
    iex> Curve.generate(:step_after, [{0, 0}, {10, 5}, {20, 2}]) |> Macaw.Draw.IR.Path.to_string()
    "M0,0H10V5H20V2"

- `[]` or one point is the empty path, for every type, and so is an unknown type: the
  setters that store a type refuse one as `{:unknown, :curve, spelling}` (§5.1).
- `:basis`, `:cardinal`, `:catmull_rom`, `:monotone_x`, `:monotone_y` and `:natural`
  fall back to `:linear` for two points; the closed loops close a line with `Z`.
- **Every type is built in work linear in its points** (visualize #414, #462): a curve
  that reads points by position reads a tuple made once, never `Enum.at/2`.

Points are `{x, y}` tuples of numbers; a list holding anything else is
`{[1, i], {:type, :point}}` at the first such point's index.

# `curve_type`

```elixir
@type curve_type() ::
  :linear
  | :step
  | :step_before
  | :step_after
  | :basis
  | :cardinal
  | :catmull_rom
  | :monotone_x
  | :monotone_y
  | :natural
  | :cardinal_closed
  | :basis_closed
```

# `error`

```elixir
@type error() :: {:error, [Macaw.Base.Fault.t()]}
```

A refusal: faults with their paths.

# `point`

```elixir
@type point() :: {number(), number()}
```

# `basis`

```elixir
@spec basis([point()]) :: Macaw.Draw.IR.Path.t() | error()
```

The uniform cubic B-spline, its ends pulled to the data (§5.3, d3-shape's `curveBasis`).

# `basis_closed`

```elixir
@spec basis_closed([point()]) :: Macaw.Draw.IR.Path.t() | error()
```

The B-spline as a closed loop (§5.3, `curveBasisClosed`).

# `cardinal`

```elixir
@spec cardinal([point()], number()) :: Macaw.Draw.IR.Path.t() | error()
```

The cardinal spline of `tension` (§5.4); `1` is linear.

# `cardinal_closed`

```elixir
@spec cardinal_closed([point()], number()) :: Macaw.Draw.IR.Path.t() | error()
```

The cardinal spline as a closed loop (§5.3, `curveCardinalClosed`).

# `catmull_rom`

```elixir
@spec catmull_rom([point()], number()) :: Macaw.Draw.IR.Path.t() | error()
```

The Catmull-Rom spline of parameter `alpha` (§5.4): `0` uniform, `0.5` centripetal, `1` chordal.

# `generate`

```elixir
@spec generate(term(), [point()]) :: Macaw.Draw.IR.Path.t() | error()
```

`generate(type, points, [])`.

# `generate`

```elixir
@spec generate(term(), [point()], keyword()) :: Macaw.Draw.IR.Path.t() | error()
```

The path of `points` through the curve `type` (§5.1): the empty path for fewer than two
points or an unknown type; an option of the wrong type is `{[key], {:type, :number}}`.

# `linear`

```elixir
@spec linear([point()]) :: Macaw.Draw.IR.Path.t() | error()
```

Straight lines between the points: `M`, then `L` per point.

# `monotone_x`

```elixir
@spec monotone_x([point()]) :: Macaw.Draw.IR.Path.t() | error()
```

The Fritsch-Carlson monotone cubic in x (§5.5).

# `monotone_y`

```elixir
@spec monotone_y([point()]) :: Macaw.Draw.IR.Path.t() | error()
```

The monotone cubic in y: `:monotone_x` with the axes swapped (§5.5).

# `natural`

```elixir
@spec natural([point()]) :: Macaw.Draw.IR.Path.t() | error()
```

The natural cubic spline, C² with zero second derivative at both ends (§5.6).

# `step`

```elixir
@spec step([point()], number()) :: Macaw.Draw.IR.Path.t() | error()
```

Steps at `t` of the way to each next point (§5.2): `0.5` is `:step`, `0` `:step_before`
and `1` `:step_after`. Consecutive horizontals merge; a vertical is drawn per point.

# `types`

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

The twelve curve types, in spec/07 §5.1's order.

---

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