# `Visualize.IR.Transform`
[🔗](https://github.com/dcoai/Visualize/blob/v0.8.3/lib/visualize/ir/transform.ex#L1)

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}]}

# `matrix`

```elixir
@type matrix() :: {number(), number(), number(), number(), number(), number()}
```

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`.

# `operation`

```elixir
@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()}
```

# `t`

```elixir
@type t() :: %Visualize.IR.Transform{operations: [operation()]}
```

# `apply_matrix`

```elixir
@spec apply_matrix(matrix(), {number(), number()}) :: {number(), number()}
```

Applies an affine matrix to a point.

# `concat`

```elixir
@spec concat(t(), t()) :: t()
```

Combines two transforms by appending the operations.

# `empty?`

```elixir
@spec empty?(t()) :: boolean()
```

Returns whether the transform is empty (has no operations).

# `matrix`

```elixir
@spec matrix(t(), number(), number(), number(), number(), number(), number()) :: t()
```

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 |

# `multiply`

```elixir
@spec multiply(matrix(), matrix()) :: matrix()
```

The product `m1 · m2` of two affine matrices, so that applying the result to a point is
applying `m2` first and then `m1`.

# `new`

```elixir
@spec new() :: t()
```

Creates a new empty transform.

# `rotate`

```elixir
@spec rotate(number()) :: t()
```

Creates a transform with a single rotate operation.
Angle is in degrees.

# `rotate`

```elixir
@spec rotate(t(), number()) :: t()
```

Adds a rotate operation.
Angle is in degrees.

# `rotate`

```elixir
@spec rotate(t(), number(), number(), number()) :: t()
```

Adds a rotate operation around a specific center point.
Angle is in degrees.

# `scale`

```elixir
@spec scale(number()) :: t()
```

Creates a transform with a single uniform scale operation.

# `scale`

```elixir
@spec scale(number(), number()) :: t()
@spec scale(t(), number()) :: t()
```

With two numbers, creates a transform with a single scale operation.
With a transform and one number, adds a uniform scale operation to it.

# `scale`

```elixir
@spec scale(t(), number(), number()) :: t()
```

Adds a scale operation with separate x and y factors.

# `skew_x`

```elixir
@spec skew_x(t(), number()) :: t()
```

Adds a skewX operation.
Angle is in degrees.

# `skew_y`

```elixir
@spec skew_y(t(), number()) :: t()
```

Adds a skewY operation.
Angle is in degrees.

# `to_matrix`

```elixir
@spec to_matrix(t()) :: matrix()
```

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}

# `to_string`

```elixir
@spec to_string(t()) :: String.t()
```

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)"

# `translate`

```elixir
@spec translate(number(), number()) :: t()
```

Creates a transform with a single translate operation.

# `translate`

```elixir
@spec translate(t(), number(), number()) :: t()
```

Adds a translate operation.

---

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