Skip to main content

Class: Transform2D

A 2D affine transformation. By default, Transform2D objects are initially created as identity transformations.

Constructors

constructor

new Transform2D(): Transform2D

Returns

Transform2D

Methods

addReflection

addReflection(theta, order?): this

Adds a reflection across a line passing through the origin (0, 0) to this transformation.

Parameters

NameTypeDescription
thetanumberThe angle of the reflection line, in radians, with respect to the positive x axis.
order?"after" | "before"The order in which to add the reflection, relative to this existing transformation, either 'before' or 'after'. Defaults to 'after'.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:411

addReflection(theta, originX, originY, order?): this

Adds a reflection across a line passing through an arbitrary origin to this transformation.

Parameters

NameTypeDescription
thetanumberThe angle of the reflection line, in radians, with respect to the positive x axis.
originXnumberThe x-coordinate of the reflection origin.
originYnumberThe y-coordinate of the reflection origin.
order?"after" | "before"The order in which to add the reflection, relative to this existing transformation, either 'before' or 'after'. Defaults to 'after'.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:421


addRotation

addRotation(theta, order?): this

Adds a rotation about the origin (0, 0) to this transformation.

Parameters

NameTypeDescription
thetanumberThe rotation angle, in radians.
order?"after" | "before"The order in which to add the rotation, relative to this existing transformation, either 'before' or 'after'. Defaults to 'after'.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:370

addRotation(theta, originX, originY, order?): this

Adds a rotation about an arbitrary origin to this transformation.

Parameters

NameTypeDescription
thetanumberThe rotation angle, in radians.
originXnumberThe x-coordinate of the rotation origin.
originYnumberThe y-coordinate of the rotation origin.
order?"after" | "before"The order in which to add the rotation, relative to this existing transformation, either 'before' or 'after'. Defaults to 'after'.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:380


addScale

addScale(x, y, order?): this

Adds a scaling about the origin (0, 0) to this transformation.

Parameters

NameTypeDescription
xnumberThe x scaling factor.
ynumberThe y scaling factor.
order?"after" | "before"The order in which to add the scaling, relative to this existing transformation, either 'before' or 'after'. Defaults to 'after'.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:328

addScale(x, y, originX, originY, order?): this

Adds a scaling about an arbitrary origin to this transformation.

Parameters

NameTypeDescription
xnumberThe x scaling factor.
ynumberThe y scaling factor.
originXnumberThe x-coordinate of the scaling origin.
originYnumberThe y-coordinate of the scaling origin.
order?"after" | "before"The order in which to add the scaling, relative to this existing transformation, either 'before' or 'after'. Defaults to 'after'.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:339


addTranslation

addTranslation(x, y, order?): this

Adds a translation to this transformation.

Parameters

NameTypeDefault valueDescription
xnumberundefinedThe x translation.
ynumberundefinedThe y translation.
order"after" | "before"'after'The order in which to add the translation, relative to this existing transformation, either 'before' or 'after'. Defaults to 'after'.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:308


apply

apply(vec, out): Float64Array

Applies this transformation to a 2D vector.

Parameters

NameTypeDescription
vecReadonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>A 2D vector.
outFloat64ArrayThe vector to which to write the result.

Returns

Float64Array

The result of applying this transformation to vec.

Defined in

src/sdk/math/Transform2D.ts:179


copy

copy(): Transform2D

Copies this transformation.

Returns

Transform2D

A copy of this transformation.

Defined in

src/sdk/math/Transform2D.ts:169


getParameters

getParameters(): Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>

Gets the parameters of this transformation as a 6-tuple: [scaleX, skewX, translateX, skewY, scaleY, translateY].

Returns

Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>

The parameters of this transformation.

Defined in

src/sdk/math/Transform2D.ts:16


invert

invert(): this

Inverts this transformation.

Returns

this

This transformation, after it has been inverted.

Defined in

src/sdk/math/Transform2D.ts:141


offsetOrigin

offsetOrigin(x, y): this

Changes this transformation to the one that is the result of offsetting this transformation's origin.

Parameters

NameTypeDescription
xnumberThe x-coordinate of the offset origin.
ynumberThe y-coordinate of the offset origin.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:195


set

set(scaleX, skewX, translateX, skewY, scaleY, translateY): this

Sets the parameters of this transformation.

Parameters

NameTypeDescription
scaleXnumberThe x scaling factor.
skewXnumberThe x skew factor.
translateXnumberThe x translation.
skewYnumberThe y skew factor.
scaleYnumberThe y scaling factor.
translateYnumberThe y translation.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:30

set(transform): this

Sets the parameters of this transformation from another transformation.

Parameters

NameTypeDescription
transformReadonlyTransform2DThe transformation from which to take parameters.

Returns

this

Defined in

src/sdk/math/Transform2D.ts:35


setScale

setScale(x, y): this

Sets the x and y scaling factors of this transformation.

Parameters

NameTypeDescription
xnumberThe new x scaling factor.
ynumberThe new y scaling factor.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:79


setScaleX

setScaleX(value): this

Sets the x scaling factor of this transformation.

Parameters

NameTypeDescription
valuenumberThe new x scaling factor.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:58


setScaleY

setScaleY(value): this

Sets the y scaling factor of this transformation.

Parameters

NameTypeDescription
valuenumberThe new y scaling factor.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:68


setSkewX

setSkewX(value): this

Sets the x skew factor of this transformation.

Parameters

NameTypeDescription
valuenumberThe new x skew factor.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:90


setSkewY

setSkewY(value): this

Sets the y skew factor of this transformation.

Parameters

NameTypeDescription
valuenumberThe new y skew factor.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:100


setTranslate

setTranslate(x, y): this

Sets the x and y translations of this transformation.

Parameters

NameTypeDescription
xnumberThe new x translation.
ynumberThe new y translation.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:131


setTranslateX

setTranslateX(value): this

Sets the x translation of this transformation.

Parameters

NameTypeDescription
valuenumberThe new x translation.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:110


setTranslateY

setTranslateY(value): this

Sets the y translation of this transformation.

Parameters

NameTypeDescription
valuenumberThe new y translation.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:120


toIdentity

toIdentity(): this

Sets this transformation to the identity transformation.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:207


toReflection

toReflection(theta): this

Sets this transformation to a reflection across a line passing through the origin (0, 0).

Parameters

NameTypeDescription
thetanumberThe angle of the reflection line, in radians, with respect to the positive x axis.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:277

toReflection(theta, originX, originY): this

Sets this transformation to a reflection across a line passing through an arbitrary origin.

Parameters

NameTypeDescription
thetanumberThe angle of the reflection line, in radians, with respect to the positive x axis.
originXnumberThe x-coordinate of the reflection origin.
originYnumberThe y-coordinate of the reflection origin.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:285


toRotation

toRotation(theta): this

Sets this transformation to a rotation about the origin (0, 0).

Parameters

NameTypeDescription
thetanumberThe rotation angle, in radians.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:251

toRotation(theta, originX, originY): this

Sets this transformation to a rotation about an arbitrary origin.

Parameters

NameTypeDescription
thetanumberThe rotation angle, in radians.
originXnumberThe x-coordinate of the rotation origin.
originYnumberThe y-coordinate of the rotation origin.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:259


toScale

toScale(x, y): this

Sets this transformation to a scaling about the origin (0, 0).

Parameters

NameTypeDescription
xnumberThe x scaling factor.
ynumberThe y scaling factor.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:227

toScale(x, y, originX, originY): this

Sets this transformation to a scaling about an arbitrary origin.

Parameters

NameTypeDescription
xnumberThe x scaling factor.
ynumberThe y scaling factor.
originXnumberThe x-coordinate of the scaling origin.
originYnumberThe y-coordinate of the scaling origin.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:236


toTranslation

toTranslation(x, y): this

Sets this transformation to a translation.

Parameters

NameTypeDescription
xnumberThe x translation.
ynumberThe y translation.

Returns

this

This transformation, after it has been changed.

Defined in

src/sdk/math/Transform2D.ts:217


concat

concat<T>(out, transforms): T

Concatenates one or more transformations and returns the result. Concatenating transformations [A, B, ...] results in a transformation that is equivalent to first applying A, then applying B, etc. Note that this order is the opposite of the one resulting from multiplying the individual transformation matrices M_A * M_B * ....

If the number of transformations to concatenate equals zero, the identity matrix is returned.

Type parameters

NameType
Textends Transform2D

Parameters

NameTypeDescription
outTThe transformation to which to write the result.
transformsreadonly ReadonlyTransform2D[]The transformations to concatenate, in order.

Returns

T

The result of concatenating all transformations in transforms.

Defined in

src/sdk/math/Transform2D.ts:458