/**
 * Affine transformation matrix. It behaves like a 3x3 matrix where the third row is always assumed to be 0 0 1.
 * This matrix is useful for 2D transformations and is compatible to the transformations done in a Canvas for example.
 */ export class AffineTransform { /**
     * Creates a matrix initialized to an identity matrix.
     */ public constructor ( ) ; param m11 param m12 param m21 param m22 param dx param dy public constructor ( m11 , m12 , m21 , m22 , dx , dy ) ; public constructor ( public m11 = 1 , public m12 = 0 , public m21 = 0 , public m22 = 1 , public dx = 0 , public dy = 0 ) { } aram return public static fromDOMMatrix ( domMatrix ) { if ( ! domMatrix . is2D ) { throw new Error ( "Can only create Matrix3 from 2D DOMMatrix" ) ; } return new AffineTransform ( domMatrix . a , domMatrix . b , domMatrix . c , domMatrix . d , domMatrix . e , domMatrix . f ) ; } return public clone ( ) { return new AffineTransform ( this . m11 , this . m12 , this . m21 , this . m22 , this . dx , this . dy ) ; } return public toDOMMatrix ( ) { return new DOMMatrix ( [ this . m11 , this . m12 , this . m21 , this . m22 , this . dx , this . dy ] ) ; } return public toString ( ) { return `[ ${ this . m11 }, ${ this . m12 }, ${ this . m21 }, ${ this . m22 }, ${ this . dx }, ${ this . dy } ]` ; } param m11 param m12 param m21 param m22 param dx param dy public setComponents ( m11 , m12 , m21 , m22 , dx , dy ) { this . m11 = m11 ; this . m12 = m12 ; this . m21 = m21 ; this . m22 = m22 ; this . dx = dx ; this . dy = dy ; return this ; } param matrix public setMatrix ( matrix ) { this . m11 = matrix . m11 ; this . m12 = matrix . m12 ; this . m21 = matrix . m21 ; this . m22 = matrix . m22 ; this . dx = matrix . dx ; this . dy = matrix . dy ; return this ; } return public isIdentity ( ) { return this . m11 === 1 && this . m12 === 0 && this . m21 === 0 && this . m22 === 1 && this . dx === 0 && this . dy === 0 ; } /**
     * Resets this matrix to identity.
     */ public reset ( ) { this . m11 = 1 ; this . m12 = 0 ; this . m21 = 0 ; this . m22 = 1 ; this . dx = 0 ; this . dy = 0 ; return this ; } param other public mul ( other ) { const a11 = this . m11 , a12 = this . m12 ; const a21 = this . m21 , a22 = this . m22 ; const a31 = this . dx , a32 = this . dy ; const b11 = other . m11 , b12 = other . m12 ; const b21 = other . m21 , b22 = other . m22 ; const b31 = other . dx , b32 = other . dy ; this . m11 = a11 * b11 + a21 * b12 ; this . m12 = a12 * b11 + a22 * b12 ; this . m21 = a11 * b21 + a21 * b22 ; this . m22 = a12 * b21 + a22 * b22 ; this . dx = a11 * b31 + a21 * b32 + a31 ; this . dy = a12 * b31 + a22 * b32 + a32 ; return this ; } param other public div ( other ) { const a11 = this . m11 , a12 = this . m12 ; const a21 = this . m21 , a22 = this . m22 ; const a31 = this . dx , a32 = this . dy ; const b11 = other . m11 , b12 = other . m12 ; const b21 = other . m21 , b22 = other . m22 ; const b31 = other . dx , b32 = other . dy ; const d = b11 * b22 - b21 * b12 ; const c11 = b22 / d ; const c12 = - b12 / d ; const c21 = - b21 / d ; const c22 = b11 / d ; const c31 = ( b21 * b32 - b31 * b22 ) / d ; const c32 = ( b31 * b12 - b11 * b32 ) / d ; this . m11 = a11 * c11 + a21 * c12 ; this . m12 = a12 * c11 + a22 * c12 ; this . m21 = a11 * c21 + a21 * c22 ; this . m22 = a12 * c21 + a22 * c22 ; this . dx = a11 * c31 + a21 * c32 + a31 ; this . dy = a12 * c31 + a22 * c32 + a32 ; return this ; } return public getDeterminant ( ) { return this . m11 * this . m22 - this . m21 * this . m12 ; } /**
     * Inverts this matrix.
     */ public invert ( ) { const m11 = this . m11 , m12 = this . m12 ; const m21 = this . m21 , m22 = this . m22 ; const m31 = this . dx , m32 = this . dy ; const d = m11 * m22 - m21 * m12 ; this . m11 = m22 / d ; this . m12 = - m12 / d ; this . m21 = - m21 / d ; this . m22 = m11 / d ; this . dx = ( m21 * m32 - m31 * m22 ) / d ; this . dy = ( m31 * m12 - m11 * m32 ) / d ; return this ; } param dx param dy public translate ( dx , dy ) { this . dx += dx * this . m11 + dy * this . m21 ; this . dy += dx * this . m12 + dy * this . m22 ; return this ; } param d public translateX ( d ) { this . dx += d * this . m11 ; this . dy += d * this . m12 ; return this ; } return public getTranslationX ( ) { return this . dx ; } param d public translateY ( d ) { this . dx += d * this . m21 ; this . dy += d * this . m22 ; return this ; } return public getTranslationY ( ) { return this . dy ; } param dx param dy public setTranslation ( dx , dy ) { this . m11 = 1 ; this . m12 = 0 ; this . m21 = 0 ; this . m22 = 1 ; this . dx = dx ; this . dy = dy ; return this ; } param dx param dy public static createTranslation ( dx , dy ) { return new AffineTransform ( ) . setTranslation ( dx , dy ) ; } param sx param sy public scale ( sx , sy = sx ) { this . m11 *= sx ; this . m12 *= sx ; this . m21 *= sy ; this . m22 *= sy ; return this ; } param sx param sy public setScale ( sx , sy = sx ) { this . m11 = sx ; this . m12 = 0 ; this . m21 = 0 ; this . m22 = sy ; this . dx = 0 ; this . dy = 0 ; return this ; } param s public scaleX ( s ) { this . m11 *= s ; this . m12 *= s ; return this ; } return public getScaleX ( ) { return Math . hypot ( this . m11 , this . m21 ) ; } param s public scaleY ( s ) { this . m21 *= s ; this . m22 *= s ; return this ; } return public getScaleY ( ) { return Math . hypot ( this . m12 , this . m22 ) ; } param sx param sy public static createScale ( sx , sy ? ) { return new AffineTransform ( ) . setScale ( sx , sy ) ; } param angle public rotate ( angle ) { const m11 = this . m11 , m12 = this . m12 ; const m21 = this . m21 , m22 = this . m22 ; const s = Math . sin ( angle ) , c = Math . cos ( angle ) ; this . m11 = c * m11 + s * m21 ; this . m12 = c * m12 + s * m22 ; this . m21 = c * m21 - s * m11 ; this . m22 = c * m22 - s * m12 ; return this ; } return public getRotation ( ) { const m11 = this . m11 , m12 = this . m12 ; const m21 = this . m21 , m22 = this . m22 ; if ( m11 !== 0 || m21 !== 0 ) { const acos = Math . acos ( m11 / Math . hypot ( m11 , m21 ) ) ; return m21 > 0 ? - acos : acos ; } else if ( m12 !== 0 || m22 !== 0 ) { const acos = Math . acos ( m12 / Math . hypot ( m12 , m22 ) ) ; return Math . PI / 2 + ( m22 > 0 ? - acos : acos ) ; } else { return 0 ; } } param angle public setRotation ( angle ) { const s = Math . sin ( angle ) , c = Math . cos ( angle ) ; this . m11 = c ; this . m12 = s ; this . m21 = - s ; this . m22 = c ; this . dx = 0 ; this . dy = 0 ; return this ; } param angle public static createRotation ( angle ) { return new AffineTransform ( ) . setRotation ( angle ) ; } param ctx public transformCanvas ( ctx ) { ctx . transform ( this . m11 , this . m12 , this . m21 , this . m22 , this . dx , this . dy ) ; return this ; } param ctx public setCanvasTransform ( ctx ) { ctx . setTransform ( this . m11 , this . m12 , this . m21 , this . m22 , this . dx , this . dy ) ; return this ; } }