Transform

ceramic.Transform (Class)
Implements: tracker.Events

Transform holds matrix data to make 2d rotate, translate, scale and skew transformations. Angles are in degrees.

This class represents a 2D affine transformation matrix used for positioning, rotating, scaling, and skewing visual objects. The matrix is stored in the following format:

| a | c | tx |
| b | d | ty |
| 0 | 0 | 1  |

Where:

  • a and d control scaling and rotation
  • b and c control skewing and rotation
  • tx and ty control translation (position)

Example usage:

var transform = new Transform();
transform.translate(100, 50);    // Move to (100, 50)
transform.rotate(Math.PI / 4);   // Rotate 45 degrees
transform.scale(2, 2);           // Double the size

// Apply to a point
var newX = transform.transformX(10, 20);
var newY = transform.transformY(10, 20);

The Transform class includes change tracking to optimize rendering pipelines and supports decomposition into individual components (position, scale, rotation, skew).

Instance Members

changedDirty: Bool

The (0,0) element of the matrix, affects horizontal scaling and rotation.


The (1,0) element of the matrix, affects vertical skewing and rotation.


The (0,1) element of the matrix, affects horizontal skewing and rotation.


The (1,1) element of the matrix, affects vertical scaling and rotation.


tx: Float

The horizontal translation (x position) in pixels.


ty: Float

The vertical translation (y position) in pixels.


changed: Bool

Whether the transform has changed since the last change event. Call computeChanged() to update this value.


emitChange(): Void

Emitted when any transform property changes. Useful for invalidating caches or triggering re-renders.


computeChanged(): Void

Check if the transform has changed by comparing current values to previous values. Updates the changed property. Call this before checking changed to ensure the value is up to date.


cleanChangedState(): Void

Reset the change tracking state. After calling this, changed will be false until the transform is modified again.


clone(): Transform

Create a copy of this transform.

Returns Description
Transform A new Transform with the same matrix values

concat(m: Transform): Void

Concatenate (multiply) this transform with another transform. The result is stored in this transform. This is equivalent to: this = this * m

Name Type Description
m Transform The transform to concatenate with this one

Decompose the transform matrix into its component parts. Extracts position, scale, rotation, and skew from the matrix.

Name Type Default Description
output DecomposedTransform (optional) Optional DecomposedTransform to store the result (creates new if null)
Returns Description
DecomposedTransform The decomposed transform containing x, y, scaleX, scaleY, rotation, skewX, skewY

setFromDecomposed(decomposed: DecomposedTransform): Void

Set this transform from decomposed values. Rebuilds the matrix from position, scale, rotation, and skew components.

Name Type Description
decomposed DecomposedTransform The decomposed transform values to apply

setFromValues(?x: Float = 0, ?y: Float = 0, ?scaleX: Float = 1, ?scaleY: Float = 1, ?rotation: Float = 0, ?skewX: Float = 0, ?skewY: Float = 0, ?pivotX: Float = 0, ?pivotY: Float = 0): Void

Set this transform from individual component values. Rebuilds the matrix from position, scale, rotation, skew, and pivot.

Name Type Default Description
x Float 0 X position
y Float 0 Y position
scaleX Float 1 Horizontal scale factor
scaleY Float 1 Vertical scale factor
rotation Float 0 Rotation angle in radians
skewX Float 0 Horizontal skew angle in radians
skewY Float 0 Vertical skew angle in radians
pivotX Float 0 X coordinate of the pivot point
pivotY Float 0 Y coordinate of the pivot point

setFromInterpolated(transform1: Transform, transform2: Transform, ratio: Float): Void

Set this transform by interpolating between two other transforms. Useful for animations and transitions.

Name Type Description
transform1 Transform The starting transform (used when ratio = 0)
transform2 Transform The ending transform (used when ratio = 1)
ratio Float The interpolation factor (0 to 1)

deltaTransformX(x: Float, y: Float): Float

Transform a vector's X component without translation. Useful for transforming directions or deltas.

Name Type Description
x Float The X component of the vector
y Float The Y component of the vector
Returns Description
Float The transformed X component

deltaTransformY(x: Float, y: Float): Float

Transform a vector's Y component without translation. Useful for transforming directions or deltas.

Name Type Description
x Float The X component of the vector
y Float The Y component of the vector
Returns Description
Float The transformed Y component

equals(transform: Transform): Bool

Check if this transform equals another transform. Compares all matrix elements for exact equality.

Name Type Description
transform Transform The transform to compare with
Returns Description
Bool true if all matrix elements are equal

identity(): Void

Reset this transform to the identity matrix. The identity matrix has no translation, rotation, scale, or skew. Equivalent to: a=1, b=0, c=0, d=1, tx=0, ty=0


invert(): Void

Invert this transform matrix. The inverted matrix can be used to reverse transformations. If the matrix is not invertible (determinant = 0), sets to a degenerate state.


rotate(angle: Float): Void

Rotate the transform by the specified angle. The rotation is applied relative to the current transform.

Name Type Description
angle Float The rotation angle in radians (use degrees * Math.PI / 180 to convert)

scale(x: Float, y: Float): Void

Scale the transform by the specified factors. The scaling is applied relative to the current transform.

Name Type Description
x Float Horizontal scale factor
y Float Vertical scale factor

translate(x: Float, y: Float): Void

Translate (move) the transform by the specified offset. The translation is applied relative to the current transform.

Name Type Description
x Float Horizontal offset in pixels
y Float Vertical offset in pixels

skew(skewX: Float, skewY: Float): Void

Apply skew transformation. Skewing shears the coordinate space along the X and Y axes.

Name Type Description
skewX Float Horizontal skew angle in radians
skewY Float Vertical skew angle in radians

setRotation(angle: Float, ?scale: Float = 1): Void

Set the rotation and uniform scale directly. This replaces the current rotation and scale, discarding any skew.

Name Type Default Description
angle Float The rotation angle in radians
scale Float 1 Uniform scale factor (default: 1)

setTo(a: Float, b: Float, c: Float, d: Float, tx: Float, ty: Float): Void

Set all matrix values directly.

Name Type Description
a Float Horizontal scaling/rotation component
b Float Vertical skewing/rotation component
c Float Horizontal skewing/rotation component
d Float Vertical scaling/rotation component
tx Float Horizontal translation
ty Float Vertical translation

setToTransform(transform: Transform): Void

Copy all values from another transform.

Name Type Description
transform Transform The transform to copy from

toString(): String

Get a string representation of the transform. Includes both matrix values and decomposed components.

Returns Description
String String representation for debugging

transformX(x: Float, y: Float): Float

Transform a point's X coordinate. Applies the full transformation including translation.

Name Type Description
x Float The X coordinate of the point
y Float The Y coordinate of the point
Returns Description
Float The transformed X coordinate

transformY(x: Float, y: Float): Float

Transform a point's Y coordinate. Applies the full transformation including translation.

Name Type Description
x Float The X coordinate of the point
y Float The Y coordinate of the point
Returns Description
Float The transformed Y coordinate

unbindEvents(): Void

new(?a: Float = 1, ?b: Float = 0, ?c: Float = 0, ?d: Float = 1, ?tx: Float = 0, ?ty: Float = 0): Void

Create a new Transform matrix.

Name Type Default Description
a Float 1 Horizontal scaling/rotation component (default: 1)
b Float 0 Vertical skewing/rotation component (default: 0)
c Float 0 Horizontal skewing/rotation component (default: 0)
d Float 1 Vertical scaling/rotation component (default: 1)
tx Float 0 Horizontal translation (default: 0)
ty Float 0 Vertical translation (default: 0)

Private Members

didEmitChange(): Void

Metadata

Name Parameters
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()
:allow ceramic.TransformPool