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.0t 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}}.
Summary
Functions
Element-wise number/2 over two equal-length lists of numbers: a list.
As array/2, the value itself, raising Macaw.Draw.Error with its faults.
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.
As basis/1, the value itself, raising Macaw.Draw.Error with its faults.
The blend of two Dates at day precision, rounded.
As date/2, the value itself, raising Macaw.Draw.Error with its faults.
The blend of two DateTimes at millisecond precision, rounded.
As datetime/2, the value itself, raising Macaw.Draw.Error with its faults.
One of n values: values[clamp(⌊t·n⌋, 0, n − 1)].
As discrete/1, the value itself, raising Macaw.Draw.Error with its faults.
HSL with the shorter hue arc: an opaque 8-bit literal color.
As hsl/2, the value itself, raising Macaw.Draw.Error with its faults.
HSL with the longer hue arc: an opaque 8-bit literal color.
As hsl_long/2, the value itself, raising Macaw.Draw.Error with its faults.
a + (b − a)·t.
As number/2, the value itself, raising Macaw.Draw.Error with its faults.
Each channel linear, rounded and clamped: an opaque 8-bit literal color.
As rgb/2, the value itself, raising Macaw.Draw.Error with its faults.
round(a + (b − a)·t), an integer.
As round/2, the value itself, raising Macaw.Draw.Error with its faults.
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.
As string/2, the value itself, raising Macaw.Draw.Error with its faults.
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 "".
As transform/2, the value itself, raising Macaw.Draw.Error with its faults.
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.
As zoom/2, the value itself, raising Macaw.Draw.Error with its faults.
Types
@type error() :: {:error, [Macaw.Base.Fault.t()]}
A refusal: faults with their paths.
@type interpolator(value) :: (number() -> value)
An interpolator: a function of t.
Functions
@spec array([number()], [number()]) :: {:ok, interpolator([number()])} | error()
Element-wise number/2 over two equal-length lists of numbers: a list.
As array/2, the value itself, raising Macaw.Draw.Error with its faults.
@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.
As basis/1, the value itself, raising Macaw.Draw.Error with its faults.
@spec date(Date.t(), Date.t()) :: {:ok, interpolator(Date.t())} | error()
The blend of two Dates at day precision, rounded.
As date/2, the value itself, raising Macaw.Draw.Error with its faults.
@spec datetime(DateTime.t(), DateTime.t()) :: {:ok, interpolator(DateTime.t())} | error()
The blend of two DateTimes at millisecond precision, rounded.
As datetime/2, the value itself, raising Macaw.Draw.Error with its faults.
@spec discrete([term()]) :: {:ok, interpolator(term())} | error()
One of n values: values[clamp(⌊t·n⌋, 0, n − 1)].
As discrete/1, the value itself, raising Macaw.Draw.Error with its faults.
@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.
As hsl/2, the value itself, raising Macaw.Draw.Error with its faults.
@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.
As hsl_long/2, the value itself, raising Macaw.Draw.Error with its faults.
@spec number(number(), number()) :: {:ok, interpolator(number())} | error()
a + (b − a)·t.
As number/2, the value itself, raising Macaw.Draw.Error with its faults.
@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.
As rgb/2, the value itself, raising Macaw.Draw.Error with its faults.
@spec round(number(), number()) :: {:ok, interpolator(integer())} | error()
round(a + (b − a)·t), an integer.
As round/2, the value itself, raising Macaw.Draw.Error with its faults.
@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"
As string/2, the value itself, raising Macaw.Draw.Error with its faults.
@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 "".
As transform/2, the value itself, raising Macaw.Draw.Error with its faults.
@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.
As zoom/2, the value itself, raising Macaw.Draw.Error with its faults.