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

Interpolator factories (spec/07 §17), copied from visualize's `Visualize.Interpolate`:
each answers `{:ok, fun}`, `fun` a 1-arity function of `t`, or `{:error, faults}` for
endpoints it cannot interpolate, and has a `!` twin answering the function itself.

    iex> {:ok, half} = Macaw.Draw.Interpolate.number(0, 100)
    iex> half.(0.5)
    50.0

`t` is not clamped unless stated; callers pass `[0, 1]` for the nominal range. Motion
between two states, a zoom's smooth path and a color ramp read these.

**Colors are `Macaw.Layers.Color` terms.** `rgb/2`, `hsl/2` and `hsl_long/2` take two
literal colors (`%Macaw.Layers.Color{}`) and nothing else, an endpoint that is none
`{[i], {:type, :color}}`; they answer an opaque 8-bit literal, as visualize's factories
have since #1006. The blending is macaw_layers' (`Macaw.Layers.Color.interpolate/4` in
`:rgb`, `:hsl` and `:hsl_long`): each endpoint goes in as its opaque 8-bit channels, so
an endpoint's opacity is not blended, and each answer comes out rounded to them.

The other refusals: `discrete/1` of `[]` is `{[], {:type, :non_empty}}`, `array/2` of
unequal lengths `{[], {:lengths, la, lb}}`, `basis/1` of fewer than two values
`{[], {:type, :values}}`, and `zoom/2` of a view whose width is not positive
`{[i, 2], {:not_positive, w}}`.

# `error`

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

A refusal: faults with their paths.

# `interpolator`

```elixir
@type interpolator(value) :: (number() -&gt; value)
```

An interpolator: a function of `t`.

# `array`

```elixir
@spec array([number()], [number()]) :: {:ok, interpolator([number()])} | error()
```

Element-wise `number/2` over two equal-length lists of numbers: a list.

# `array!`

```elixir
@spec array!(term(), term()) :: term()
```

As `array/2`, the value itself, raising `Macaw.Draw.Error` with its faults.

# `basis`

```elixir
@spec basis([number()]) :: {:ok, interpolator(float())} | error()
```

A uniform cubic B-spline through at least two numbers, its ends clamped: `t` is clamped
to `[0, 1]`, and `t = 0` and `1` are exactly the first and last values.

# `basis!`

```elixir
@spec basis!(term()) :: term()
```

As `basis/1`, the value itself, raising `Macaw.Draw.Error` with its faults.

# `date`

```elixir
@spec date(Date.t(), Date.t()) :: {:ok, interpolator(Date.t())} | error()
```

The blend of two `Date`s at day precision, rounded.

# `date!`

```elixir
@spec date!(term(), term()) :: term()
```

As `date/2`, the value itself, raising `Macaw.Draw.Error` with its faults.

# `datetime`

```elixir
@spec datetime(DateTime.t(), DateTime.t()) ::
  {:ok, interpolator(DateTime.t())} | error()
```

The blend of two `DateTime`s at millisecond precision, rounded.

# `datetime!`

```elixir
@spec datetime!(term(), term()) :: term()
```

As `datetime/2`, the value itself, raising `Macaw.Draw.Error` with its faults.

# `discrete`

```elixir
@spec discrete([term()]) :: {:ok, interpolator(term())} | error()
```

One of `n` values: `values[clamp(⌊t·n⌋, 0, n − 1)]`.

# `discrete!`

```elixir
@spec discrete!(term()) :: term()
```

As `discrete/1`, the value itself, raising `Macaw.Draw.Error` with its faults.

# `hsl`

```elixir
@spec hsl(Macaw.Layers.Color.t(), Macaw.Layers.Color.t()) ::
  {:ok, interpolator(Macaw.Layers.Color.t())} | error()
```

HSL with the shorter hue arc: an opaque 8-bit literal color.

# `hsl!`

```elixir
@spec hsl!(term(), term()) :: term()
```

As `hsl/2`, the value itself, raising `Macaw.Draw.Error` with its faults.

# `hsl_long`

```elixir
@spec hsl_long(Macaw.Layers.Color.t(), Macaw.Layers.Color.t()) ::
  {:ok, interpolator(Macaw.Layers.Color.t())} | error()
```

HSL with the longer hue arc: an opaque 8-bit literal color.

# `hsl_long!`

```elixir
@spec hsl_long!(term(), term()) :: term()
```

As `hsl_long/2`, the value itself, raising `Macaw.Draw.Error` with its faults.

# `number`

```elixir
@spec number(number(), number()) :: {:ok, interpolator(number())} | error()
```

`a + (b − a)·t`.

# `number!`

```elixir
@spec number!(term(), term()) :: term()
```

As `number/2`, the value itself, raising `Macaw.Draw.Error` with its faults.

# `rgb`

```elixir
@spec rgb(Macaw.Layers.Color.t(), Macaw.Layers.Color.t()) ::
  {:ok, interpolator(Macaw.Layers.Color.t())} | error()
```

Each channel linear, rounded and clamped: an opaque 8-bit literal color.

# `rgb!`

```elixir
@spec rgb!(term(), term()) :: term()
```

As `rgb/2`, the value itself, raising `Macaw.Draw.Error` with its faults.

# `round`

```elixir
@spec round(number(), number()) :: {:ok, interpolator(integer())} | error()
```

`round(a + (b − a)·t)`, an integer.

# `round!`

```elixir
@spec round!(term(), term()) :: term()
```

As `round/2`, the value itself, raising `Macaw.Draw.Error` with its faults.

# `string`

```elixir
@spec string(String.t(), String.t()) :: {:ok, interpolator(String.t())} | error()
```

The numbers embedded in `b` blended pairwise with those in `a`, the rest of the text
`b`'s: a missing number of `a` starts from 0 and extras in `a` are ignored; a whole
result prints as an integer, else a float rounded to 4 decimals.

    iex> {:ok, fun} = Macaw.Draw.Interpolate.string("10px", "20px")
    iex> fun.(0.5)
    "15px"

# `string!`

```elixir
@spec string!(term(), term()) :: term()
```

As `string/2`, the value itself, raising `Macaw.Draw.Error` with its faults.

# `transform`

```elixir
@spec transform(String.t(), String.t()) :: {:ok, interpolator(String.t())} | error()
```

Two SVG transform strings blended: the first `translate(x[, y])`, `scale(s[, sy])` and
`rotate(a)` of each, a component in one string only held constant, one in neither the
identity; written `translate(x, y) scale(sx, sy) rotate(r)` without the identity
components, or `""`.

# `transform!`

```elixir
@spec transform!(term(), term()) :: term()
```

As `transform/2`, the value itself, raising `Macaw.Draw.Error` with its faults.

# `zoom`

```elixir
@spec zoom([number()], [number()]) :: {:ok, interpolator([float()])} | error()
```

van Wijk and Nuij's smooth zoom between two views `[cx, cy, w]`, `ρ = 1.4`: a view.
When the centers coincide (distance below `1.0e-6`) only `w` changes, exponentially.

# `zoom!`

```elixir
@spec zoom!(term(), term()) :: term()
```

As `zoom/2`, the value itself, raising `Macaw.Draw.Error` with its faults.

---

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