Backend-agnostic transformation representation.
Stores a sequence of transformation operations that can be applied to elements when rendering.
Examples
iex> alias Visualize.IR.Transform
iex> Transform.new()
...> |> Transform.translate(100, 50)
...> |> Transform.rotate(45)
...> |> Transform.scale(2, 2)
%Visualize.IR.Transform{operations: [{:translate, 100, 50}, {:rotate, 45}, {:scale, 2, 2}]}
Summary
Types
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.
Functions
Applies an affine matrix to a point.
Combines two transforms by appending the operations.
Returns whether the transform is empty (has no operations).
Adds a matrix transformation. The matrix is specified as (a, b, c, d, e, f) which corresponds to
The product m1 · m2 of two affine matrices, so that applying the result to a point is
applying m2 first and then m1.
Creates a new empty transform.
Creates a transform with a single rotate operation. Angle is in degrees.
Adds a rotate operation. Angle is in degrees.
Adds a rotate operation around a specific center point. Angle is in degrees.
Creates a transform with a single uniform scale operation.
With two numbers, creates a transform with a single scale operation. With a transform and one number, adds a uniform scale operation to it.
Adds a scale operation with separate x and y factors.
Adds a skewX operation. Angle is in degrees.
Adds a skewY operation. Angle is in degrees.
Folds the operations into one affine matrix {a, b, c, d, e, f}.
Converts the transform to an SVG transform attribute string.
Creates a transform with a single translate operation.
Adds a translate operation.
Types
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 t() :: %Visualize.IR.Transform{operations: [operation()]}
Functions
Applies an affine matrix to a point.
Combines two transforms by appending the operations.
Returns whether the transform is empty (has no operations).
Adds a matrix transformation. The matrix is specified as (a, b, c, d, e, f) which corresponds to:
| a c e |
| b d f |
| 0 0 1 |
The product m1 · m2 of two affine matrices, so that applying the result to a point is
applying m2 first and then m1.
@spec new() :: t()
Creates a new empty transform.
Creates a transform with a single rotate operation. Angle is in degrees.
Adds a rotate operation. Angle is in degrees.
Adds a rotate operation around a specific center point. Angle is in degrees.
Creates a transform with a single uniform scale operation.
With two numbers, creates a transform with a single scale operation. With a transform and one number, adds a uniform scale operation to it.
Adds a scale operation with separate x and y factors.
Adds a skewX operation. Angle is in degrees.
Adds a skewY operation. Angle is in degrees.
Folds the operations into one affine matrix {a, b, c, d, e, f}.
Composition follows SVG: M = Op₁ · Op₂ · … · Opₙ, so the last operation applies to a
point first, exactly as the transform attribute string would. rotate(a, cx, cy) is
translate(cx, cy) rotate(a) translate(-cx, -cy); angles are degrees.
Examples
iex> alias Visualize.IR.Transform
iex> Transform.translate(10, 20) |> Transform.to_matrix()
{1.0, 0.0, 0.0, 1.0, 10.0, 20.0}
Converts the transform to an SVG transform attribute string.
Examples
iex> alias Visualize.IR.Transform
iex> Transform.translate(100, 50) |> Transform.to_string()
"translate(100,50)"
Creates a transform with a single translate operation.
Adds a translate operation.