@mocanvas/editor · class

Mat

declare class Mat

This one ships without a description. The signature above is read from the package, and the guides cover the area it belongs to.


Methods · 37

static Absolute(m: MatLike): Mat

The transform with any reflection taken out of it, so that both axes scale positively and only the rotation carries the orientation.

SEMANTICS-ASSUMED: the docs give the name and signature only. "Absolute" reading as "absolute scale" is the interpretation that makes it useful — it is what lets a mirrored shape be measured without its own flip confusing the measurement.

static applyToBounds(m: MatLike, box: BoxLike): Box

The axis-aligned box containing box after m is applied. A rotation makes this larger than the original — it is the bounding box of the transformed rectangle, not the transformed rectangle.

applyToPoint(point: VecLike): Vec

Push a point through the transform.

applyToPoints(points: readonly VecLike[]): Vec[]
static applyToXY(m: MatLike, x: number, y: number): number[]

Push (x, y) through m, as a bare pair.

static Cast(m: MatLike): Mat

m itself when it is already a Mat, otherwise a Mat copy of it.

clone(): Mat
static Compose(...matrices: MatLike[]): Mat

The product of every transform given, left to right — Compose(parent, child) is the parent's transform followed by the child's, which is the order a shape hierarchy composes in. With no arguments this is the identity.

constructor(a: number, b: number, c: number, d: number, e: number, f: number)
decompose(): DecomposedMat
static Decompose(m: MatLike): DecomposedMat
decomposed(): DecomposedMat

An alias of Mat.decompose.

equals(m: MatLike): boolean
static From(m: MatLike): Mat

Adopt any {a,b,c,d,e,f} — including the plain literals used internally.

getRotation(): number

The rotation this transform applies, in radians, signed.

getScale(): number

The uniform scale this transform applies, as the mean of its two axes.

identity(): this

Reset to the identity, in place.

static Identity(): Mat
static Inverse(m: MatLike): Mat

The inverse of any {a…f}, as a new Mat. See Mat.invert.

invert(): this

Invert this transform in place, for going from page space back into shape space. A singular matrix (a zero-scale shape) has no inverse; it becomes the identity rather than a field of NaNs, so a degenerate shape maps points to themselves instead of poisoning everything downstream.

multiply(m: MatLike): this

Post-multiply this transform by m, in place.

SEMANTICS-ASSUMED: the chainable builders (multiply, translate, rotate, scale) mutate and return this rather than returning a copy. The call sites are all of the form Mat.Identity().translate(x, y).rotate(r) — a fresh matrix built up in one expression — which reads the same either way, and mutating matches how Vec.add/Vec.mul behave. Callers holding a matrix they did not create should clone() first.

static Multiply(m: MatLike, n: MatLike): Mat

m then n, i.e. the matrix product m × n.

multiplyBy(m: MatLike): this

Post-multiply this transform by m, in place.

@deprecated Use Mat.multiply, the documented name.

point(): Vec

The translation component, i.e. where this transform sends the origin.

static Point(m: MatLike): Vec

Where m sends the origin, i.e. its translation component.

rotate(r: number, cx?: number, cy?: number): this

Rotate by r radians about this transform's own origin, or about (cx, cy) in its own space when given. A zero angle short-circuits, so an unrotated shape's transform stays free of cos/sin float dust.

static Rotate(r: number, cx?: number, cy?: number): Mat

A pure rotation, about the origin or about (cx, cy) when given.

rotation(): number

The rotation this transform encodes, in radians, normalized to [0, 2π).

static Rotation(m: MatLike): number

The rotation m encodes, in radians, normalized to [0, 2π).

scale(x: number, y?: number): this

Scale by (x, y) in this transform's own space, in place.

static Scale(x: number, y: number): Mat

A pure scale.

setTo(model: MatLike): this

Adopt every component of model, in place.

static Smooth(m: MatLike, precision?: number): Mat

Every component rounded, to keep float dust out of a serialized transform.

toCssString(): string
toJson(): MatModel

The six components as a plain object.

translate(x: number, y: number): this

Translate by (x, y) in this transform's own space, in place.

static Translate(x: number, y: number): Mat

A pure translation.


Properties · 6

a: number
b: number
c: number
d: number
e: number
f: number

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.