{"version":3,"file":"Transform.mjs","sources":["../../../src/utils/misc/Transform.ts"],"sourcesContent":["import { Matrix } from '../../maths/matrix/Matrix';\nimport { ObservablePoint } from '../../maths/point/ObservablePoint';\n\nimport type { Observer } from '../../maths/point/ObservablePoint';\n\n/**\n * Options for the {@link utils.Transform} constructor.\n * @memberof utils.Transform\n */\nexport interface TransformOptions\n{\n    /** The matrix to use. */\n    matrix?: Matrix;\n    /** The observer to use. */\n    observer?: {_onUpdate: (transform: Transform) => void}\n}\n\n/**\n * The Transform class facilitates the manipulation of a 2D transformation matrix through\n * user-friendly properties: position, scale, rotation, skew, and pivot.\n * @memberof utils\n */\nexport class Transform\n{\n    /**\n     * The local transformation matrix.\n     * @internal\n     * @private\n     */\n    public _matrix: Matrix;\n\n    /** The coordinate of the object relative to the local coordinates of the parent. */\n    public position: ObservablePoint;\n\n    /** The scale factor of the object. */\n    public scale: ObservablePoint;\n\n    /** The pivot point of the container that it rotates around. */\n    public pivot: ObservablePoint;\n\n    /** The skew amount, on the x and y axis. */\n    public skew: ObservablePoint;\n\n    /** The rotation amount. */\n    protected _rotation: number;\n\n    /**\n     * The X-coordinate value of the normalized local X axis,\n     * the first column of the local transformation matrix without a scale.\n     */\n    protected _cx: number;\n\n    /**\n     * The Y-coordinate value of the normalized local X axis,\n     * the first column of the local transformation matrix without a scale.\n     */\n    protected _sx: number;\n\n    /**\n     * The X-coordinate value of the normalized local Y axis,\n     * the second column of the local transformation matrix without a scale.\n     */\n    protected _cy: number;\n\n    /**\n     * The Y-coordinate value of the normalized local Y axis,\n     * the second column of the local transformation matrix without a scale.\n     */\n    protected _sy: number;\n\n    protected dirty = true;\n    protected observer: Observer<Transform>;\n\n    /**\n     * @param options - Options for the transform.\n     * @param options.matrix - The matrix to use.\n     * @param options.observer - The observer to use.\n     */\n    constructor({ matrix, observer }: TransformOptions = {})\n    {\n        this._matrix = matrix ?? new Matrix();\n        this.observer = observer;\n\n        this.position = new ObservablePoint(this, 0, 0);\n        this.scale = new ObservablePoint(this, 1, 1);\n        this.pivot = new ObservablePoint(this, 0, 0);\n        this.skew = new ObservablePoint(this, 0, 0);\n\n        this._rotation = 0;\n        this._cx = 1;\n        this._sx = 0;\n        this._cy = 0;\n        this._sy = 1;\n    }\n\n    /**\n     * This matrix is computed by combining this Transforms position, scale, rotation, skew, and pivot\n     * properties into a single matrix.\n     * @readonly\n     */\n    get matrix(): Matrix\n    {\n        const lt = this._matrix;\n\n        if (!this.dirty) return lt;\n\n        lt.a = this._cx * this.scale.x;\n        lt.b = this._sx * this.scale.x;\n        lt.c = this._cy * this.scale.y;\n        lt.d = this._sy * this.scale.y;\n\n        lt.tx = this.position.x - ((this.pivot.x * lt.a) + (this.pivot.y * lt.c));\n        lt.ty = this.position.y - ((this.pivot.x * lt.b) + (this.pivot.y * lt.d));\n\n        this.dirty = false;\n\n        return lt;\n    }\n    /**\n     * Called when a value changes.\n     * @param point\n     * @internal\n     * @private\n     */\n    public _onUpdate(point?: ObservablePoint): void\n    {\n        this.dirty = true;\n\n        if (point === this.skew)\n        {\n            this.updateSkew();\n        }\n\n        this.observer?._onUpdate(this);\n    }\n\n    /** Called when the skew or the rotation changes. */\n    protected updateSkew(): void\n    {\n        this._cx = Math.cos(this._rotation + this.skew.y);\n        this._sx = Math.sin(this._rotation + this.skew.y);\n        this._cy = -Math.sin(this._rotation - this.skew.x); // cos, added PI/2\n        this._sy = Math.cos(this._rotation - this.skew.x); // sin, added PI/2\n\n        this.dirty = true;\n    }\n\n    // #if _DEBUG\n    public toString(): string\n    {\n        return `[pixi.js/math:Transform `\n            + `position=(${this.position.x}, ${this.position.y}) `\n            + `rotation=${this.rotation} `\n            + `scale=(${this.scale.x}, ${this.scale.y}) `\n            + `skew=(${this.skew.x}, ${this.skew.y}) `\n            + `]`;\n    }\n    // #endif\n\n    /**\n     * Decomposes a matrix and sets the transforms properties based on it.\n     * @param matrix - The matrix to decompose\n     */\n    public setFromMatrix(matrix: Matrix): void\n    {\n        matrix.decompose(this);\n        this.dirty = true;\n    }\n\n    /** The rotation of the object in radians. */\n    get rotation(): number\n    {\n        return this._rotation;\n    }\n\n    set rotation(value: number)\n    {\n        if (this._rotation !== value)\n        {\n            this._rotation = value;\n            this._onUpdate(this.skew);\n        }\n    }\n}\n"],"names":[],"mappings":";;;;AAsBO,MAAM,SACb,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuDI,YAAY,EAAE,MAAA,EAAQ,QAAS,EAAA,GAAsB,EACrD,EAAA;AATA,IAAA,IAAA,CAAU,KAAQ,GAAA,IAAA,CAAA;AAUd,IAAK,IAAA,CAAA,OAAA,GAAU,MAAU,IAAA,IAAI,MAAO,EAAA,CAAA;AACpC,IAAA,IAAA,CAAK,QAAW,GAAA,QAAA,CAAA;AAEhB,IAAA,IAAA,CAAK,QAAW,GAAA,IAAI,eAAgB,CAAA,IAAA,EAAM,GAAG,CAAC,CAAA,CAAA;AAC9C,IAAA,IAAA,CAAK,KAAQ,GAAA,IAAI,eAAgB,CAAA,IAAA,EAAM,GAAG,CAAC,CAAA,CAAA;AAC3C,IAAA,IAAA,CAAK,KAAQ,GAAA,IAAI,eAAgB,CAAA,IAAA,EAAM,GAAG,CAAC,CAAA,CAAA;AAC3C,IAAA,IAAA,CAAK,IAAO,GAAA,IAAI,eAAgB,CAAA,IAAA,EAAM,GAAG,CAAC,CAAA,CAAA;AAE1C,IAAA,IAAA,CAAK,SAAY,GAAA,CAAA,CAAA;AACjB,IAAA,IAAA,CAAK,GAAM,GAAA,CAAA,CAAA;AACX,IAAA,IAAA,CAAK,GAAM,GAAA,CAAA,CAAA;AACX,IAAA,IAAA,CAAK,GAAM,GAAA,CAAA,CAAA;AACX,IAAA,IAAA,CAAK,GAAM,GAAA,CAAA,CAAA;AAAA,GACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,MACJ,GAAA;AACI,IAAA,MAAM,KAAK,IAAK,CAAA,OAAA,CAAA;AAEhB,IAAA,IAAI,CAAC,IAAK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