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_yand:naturalfall back to:linearfor two points; the closed loops close a line withZ.- 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.
Summary
Functions
The uniform cubic B-spline, its ends pulled to the data (§5.3, d3-shape's curveBasis).
The B-spline as a closed loop (§5.3, curveBasisClosed).
The cardinal spline of tension (§5.4); 1 is linear.
The cardinal spline as a closed loop (§5.3, curveCardinalClosed).
The Catmull-Rom spline of parameter alpha (§5.4): 0 uniform, 0.5 centripetal, 1 chordal.
generate(type, points, []).
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}}.
Straight lines between the points: M, then L per point.
The Fritsch-Carlson monotone cubic in x (§5.5).
The monotone cubic in y: :monotone_x with the axes swapped (§5.5).
The natural cubic spline, C² with zero second derivative at both ends (§5.6).
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.
The twelve curve types, in spec/07 §5.1's order.
Types
@type curve_type() ::
:linear
| :step
| :step_before
| :step_after
| :basis
| :cardinal
| :catmull_rom
| :monotone_x
| :monotone_y
| :natural
| :cardinal_closed
| :basis_closed
@type error() :: {:error, [Macaw.Base.Fault.t()]}
A refusal: faults with their paths.
Functions
@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).
@spec basis_closed([point()]) :: Macaw.Draw.IR.Path.t() | error()
The B-spline as a closed loop (§5.3, curveBasisClosed).
@spec cardinal([point()], number()) :: Macaw.Draw.IR.Path.t() | error()
The cardinal spline of tension (§5.4); 1 is linear.
@spec cardinal_closed([point()], number()) :: Macaw.Draw.IR.Path.t() | error()
The cardinal spline as a closed loop (§5.3, curveCardinalClosed).
@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.
@spec generate(term(), [point()]) :: Macaw.Draw.IR.Path.t() | error()
generate(type, points, []).
@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}}.
@spec linear([point()]) :: Macaw.Draw.IR.Path.t() | error()
Straight lines between the points: M, then L per point.
@spec monotone_x([point()]) :: Macaw.Draw.IR.Path.t() | error()
The Fritsch-Carlson monotone cubic in x (§5.5).
@spec monotone_y([point()]) :: Macaw.Draw.IR.Path.t() | error()
The monotone cubic in y: :monotone_x with the axes swapped (§5.5).
@spec natural([point()]) :: Macaw.Draw.IR.Path.t() | error()
The natural cubic spline, C² with zero second derivative at both ends (§5.6).
@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.
@spec types() :: [curve_type()]
The twelve curve types, in spec/07 §5.1's order.