A node's transform (spec/10 §1.3), copied from visualize's Visualize.IR.Transform:
%Macaw.Draw.IR.Transform{operations}, applied left to right as SVG composes them.
An operation is {:translate, x, y}, {:rotate, a}, {:rotate, a, cx, cy},
{:scale, sx, sy}, {:skew_x, a}, {:skew_y, a} or {:matrix, a, b, c, d, e, f},
angles in degrees. to_matrix/1 folds them into one affine matrix, M = Op₁ · … · Opₙ;
to_string/1 writes the transform attribute, every number through
Macaw.Draw.IR.Path.format_number/1, a uniform scale as scale(s).
iex> alias Macaw.Draw.IR.Transform
iex> Transform.new() |> Transform.translate(100, 50) |> Transform.rotate(45) |> Transform.scale(2) |> Transform.to_string()
"translate(100,50) rotate(45) scale(2)"An operation of no shape above, in a transform built by hand, is the fault
{[:operations, i], {:bad_transform, op}} of to_matrix/1 and to_string/1.
Summary
Types
A refusal: faults with their paths.
An affine matrix {a, b, c, d, e, f} for [a c e; b d f; 0 0 1]: a point maps as
x' = a·x + c·y + e, y' = b·x + d·y + f.
One transform operation (spec/10 §1.3).
Functions
An affine matrix applied to a point {x, y}.
The operations of first then those of second.
Whether the transform has no operation.
The transform followed by the matrix (a, b, c, d, e, f).
The product m1 · m2 of two affine matrices: applying it to a point applies m2 and
then m1.
An empty transform.
A rotation by angle degrees about the origin.
The transform followed by a rotation by angle degrees about the origin.
The transform followed by a rotation by angle degrees about (cx, cy).
A uniform scale by s.
With two numbers, a scale by sx and sy; with a transform and a number, the transform
followed by a uniform scale.
The transform followed by a scale by sx and sy.
The transform followed by a skew along x by angle degrees.
The transform followed by a skew along y by angle degrees.
The operations folded into one affine matrix, M = Op₁ · Op₂ · … · Opₙ, so the last
operation applies to a point first, exactly as the transform attribute does;
rotate(a, cx, cy) is translate(cx, cy) rotate(a) translate(-cx, -cy).
The SVG transform attribute's text: the operations joined by spaces.
A translation by (x, y).
The transform followed by a translation by (x, y).
Types
@type error() :: {:error, [Macaw.Base.Fault.t()]}
A refusal: faults with their paths.
An affine matrix {a, b, c, d, e, f} for [a c e; b d f; 0 0 1]: a point maps as
x' = a·x + c·y + e, y' = b·x + d·y + f.
@type operation() :: {:translate, number(), number()} | {:rotate, number()} | {:rotate, number(), number(), number()} | {:scale, number(), number()} | {:skew_x, number()} | {:skew_y, number()} | {:matrix, number(), number(), number(), number(), number(), number()}
One transform operation (spec/10 §1.3).
@type t() :: %Macaw.Draw.IR.Transform{operations: [operation()]}
Functions
An affine matrix applied to a point {x, y}.
The operations of first then those of second.
Whether the transform has no operation.
The transform followed by the matrix (a, b, c, d, e, f).
The product m1 · m2 of two affine matrices: applying it to a point applies m2 and
then m1.
@spec new() :: t()
An empty transform.
A rotation by angle degrees about the origin.
The transform followed by a rotation by angle degrees about the origin.
The transform followed by a rotation by angle degrees about (cx, cy).
A uniform scale by s.
With two numbers, a scale by sx and sy; with a transform and a number, the transform
followed by a uniform scale.
The transform followed by a scale by sx and sy.
The transform followed by a skew along x by angle degrees.
The transform followed by a skew along y by angle degrees.
The operations folded into one affine matrix, M = Op₁ · Op₂ · … · Opₙ, so the last
operation applies to a point first, exactly as the transform attribute does;
rotate(a, cx, cy) is translate(cx, cy) rotate(a) translate(-cx, -cy).
iex> Macaw.Draw.IR.Transform.translate(10, 20) |> Macaw.Draw.IR.Transform.to_matrix()
{1.0, 0.0, 0.0, 1.0, 10.0, 20.0}
The SVG transform attribute's text: the operations joined by spaces.
iex> Macaw.Draw.IR.Transform.translate(22.5, 0) |> Macaw.Draw.IR.Transform.to_string()
"translate(22.5,0)"
A translation by (x, y).
The transform followed by a translation by (x, y).