{"version":3,"file":"TextureUvs.mjs","sources":["../../src/textures/TextureUvs.ts"],"sourcesContent":["import { groupD8 } from '@pixi/math';\n\nimport type { ISize, Rectangle } from '@pixi/math';\n\n/**\n * Stores a texture's frame in UV coordinates, in\n * which everything lies in the rectangle `[(0,0), (1,0),\n * (1,1), (0,1)]`.\n *\n * | Corner       | Coordinates |\n * |--------------|-------------|\n * | Top-Left     | `(x0,y0)`   |\n * | Top-Right    | `(x1,y1)`   |\n * | Bottom-Right | `(x2,y2)`   |\n * | Bottom-Left  | `(x3,y3)`   |\n * @protected\n * @memberof PIXI\n */\nexport class TextureUvs\n{\n    /** X-component of top-left corner `(x0,y0)`. */\n    public x0: number;\n\n    /** Y-component of top-left corner `(x0,y0)`. */\n    public y0: number;\n\n    /** X-component of top-right corner `(x1,y1)`. */\n    public x1: number;\n\n    /** Y-component of top-right corner `(x1,y1)`. */\n    public y1: number;\n\n    /** X-component of bottom-right corner `(x2,y2)`. */\n    public x2: number;\n\n    /** Y-component of bottom-right corner `(x2,y2)`. */\n    public y2: number;\n\n    /** X-component of bottom-left corner `(x3,y3)`. */\n    public x3: number;\n\n    /** Y-component of bottom-right corner `(x3,y3)`. */\n    public y3: number;\n    public uvsFloat32: Float32Array;\n\n    constructor()\n    {\n        this.x0 = 0;\n        this.y0 = 0;\n        this.x1 = 1;\n        this.y1 = 0;\n        this.x2 = 1;\n        this.y2 = 1;\n        this.x3 = 0;\n        this.y3 = 1;\n\n        this.uvsFloat32 = new Float32Array(8);\n    }\n\n    /**\n     * Sets the texture Uvs based on the given frame information.\n     * @protected\n     * @param frame - The frame of the texture\n     * @param baseFrame - The base frame of the texture\n     * @param rotate - Rotation of frame, see {@link PIXI.groupD8}\n     */\n    set(frame: Rectangle, baseFrame: ISize, rotate: number): void\n    {\n        const tw = baseFrame.width;\n        const th = baseFrame.height;\n\n        if (rotate)\n        {\n            // width and height div 2 div baseFrame size\n            const w2 = frame.width / 2 / tw;\n            const h2 = frame.height / 2 / th;\n\n            // coordinates of center\n            const cX = (frame.x / tw) + w2;\n            const cY = (frame.y / th) + h2;\n\n            rotate = groupD8.add(rotate, groupD8.NW); // NW is top-left corner\n            this.x0 = cX + (w2 * groupD8.uX(rotate));\n            this.y0 = cY + (h2 * groupD8.uY(rotate));\n\n            rotate = groupD8.add(rotate, 2); // rotate 90 degrees clockwise\n            this.x1 = cX + (w2 * groupD8.uX(rotate));\n            this.y1 = cY + (h2 * groupD8.uY(rotate));\n\n            rotate = groupD8.add(rotate, 2);\n            this.x2 = cX + (w2 * groupD8.uX(rotate));\n            this.y2 = cY + (h2 * groupD8.uY(rotate));\n\n            rotate = groupD8.add(rotate, 2);\n            this.x3 = cX + (w2 * groupD8.uX(rotate));\n            this.y3 = cY + (h2 * groupD8.uY(rotate));\n        }\n        else\n        {\n            this.x0 = frame.x / tw;\n            this.y0 = frame.y / th;\n\n            this.x1 = (frame.x + frame.width) / tw;\n            this.y1 = frame.y / th;\n\n            this.x2 = (frame.x + frame.width) / tw;\n            this.y2 = (frame.y + frame.height) / th;\n\n            this.x3 = frame.x / tw;\n            this.y3 = (frame.y + frame.height) / th;\n        }\n\n        this.uvsFloat32[0] = this.x0;\n        this.uvsFloat32[1] = this.y0;\n        this.uvsFloat32[2] = this.x1;\n        this.uvsFloat32[3] = this.y1;\n        this.uvsFloat32[4] = this.x2;\n        this.uvsFloat32[5] = this.y2;\n        this.uvsFloat32[6] = this.x3;\n        this.uvsFloat32[7] = this.y3;\n    }\n}\n\nif (process.env.DEBUG)\n{\n    TextureUvs.prototype.toString = function toString(): string\n    {\n        return `[@pixi/core:TextureUvs `\n            + `x0=${this.x0} y0=${this.y0} `\n            + `x1=${this.x1} y1=${this.y1} x2=${this.x2} `\n            + `y2=${this.y2} x3=${this.x3} y3=${this.y3}`\n            + `]`;\n    };\n}\n"],"names":[],"mappings":";AAkBO,MAAM,WACb;AAAA,EA0BI,cACA;AACS,SAAA,KAAK,GACV,KAAK,KAAK,GACV,KAAK,KAAK,GACV,KAAK,K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