{"version":3,"file":"QuadUv.js","sources":["../../src/utils/QuadUv.ts"],"sourcesContent":["import { Buffer } from '../geometry/Buffer';\nimport { Geometry } from '../geometry/Geometry';\n\nimport type { Rectangle } from '@pixi/math';\n\n/**\n * Helper class to create a quad with uvs like in v4\n * @memberof PIXI\n */\nexport class QuadUv extends Geometry\n{\n    vertexBuffer: Buffer;\n    uvBuffer: Buffer;\n\n    /** An array of vertices. */\n    vertices: Float32Array;\n\n    /** The Uvs of the quad. */\n    uvs: Float32Array;\n\n    constructor()\n    {\n        super();\n\n        this.vertices = new Float32Array([\n            -1, -1,\n            1, -1,\n            1, 1,\n            -1, 1,\n        ]);\n\n        this.uvs = new Float32Array([\n            0, 0,\n            1, 0,\n            1, 1,\n            0, 1,\n        ]);\n\n        this.vertexBuffer = new Buffer(this.vertices);\n        this.uvBuffer = new Buffer(this.uvs);\n\n        this.addAttribute('aVertexPosition', this.vertexBuffer)\n            .addAttribute('aTextureCoord', this.uvBuffer)\n            .addIndex([0, 1, 2, 0, 2, 3]);\n    }\n\n    /**\n     * Maps two Rectangle to the quad.\n     * @param targetTextureFrame - The first rectangle\n     * @param destinationFrame - The second rectangle\n     * @returns - Returns itself.\n     */\n    map(targetTextureFrame: Rectangle, destinationFrame: Rectangle): this\n    {\n        let x = 0; // destinationFrame.x / targetTextureFrame.width;\n        let y = 0; // destinationFrame.y / targetTextureFrame.height;\n\n        this.uvs[0] = x;\n        this.uvs[1] = y;\n\n        this.uvs[2] = x + (destinationFrame.width / targetTextureFrame.width);\n        this.uvs[3] = y;\n\n        this.uvs[4] = x + (destinationFrame.width / targetTextureFrame.width);\n        this.uvs[5] = y + (destinationFrame.height / targetTextureFrame.height);\n\n        this.uvs[6] = x;\n        this.uvs[7] = y + (destinationFrame.height / targetTextureFrame.height);\n\n        x = destinationFrame.x;\n        y = destinationFrame.y;\n\n        this.vertices[0] = x;\n        this.vertices[1] = y;\n\n        this.vertices[2] = x + destinationFrame.width;\n        this.vertices[3] = y;\n\n        this.vertices[4] = x + destinationFrame.width;\n        this.vertices[5] = y + destinationFrame.height;\n\n        this.vertices[6] = x;\n        this.vertices[7] = y + destinationFrame.height;\n\n        this.invalidate();\n\n        return this;\n    }\n\n    /**\n     * Legacy upload method, just marks buffers dirty.\n     * @returns - Returns itself.\n     */\n    invalidate(): this\n    {\n        this.vertexBuffer._updateID++;\n        this.uvBuffer._updateID++;\n\n        return this;\n    }\n}\n"],"names":["Geometry","Buffer"],"mappings":";;AASO,MAAM,eAAeA,SAAAA,SAC5B;AAAA,EAUI,cACA;AACU,aAED,KAAA,WAAW,IAAI,aAAa;AAAA,MAC7B;AAAA,MAAI;AAAA,MACJ;AAAA,MAAG;AAAA,MACH;AAAA,MAAG;AAAA,MACH;AAAA,MAAI;AAAA,IACP,CAAA,GAED,KAAK,MAAM,IAAI,aAAa;AAAA,MACxB;AAAA,MAAG;AAAA,MACH;AAAA,MAAG;AAAA,MACH;AAAA,MAAG;AAAA,MACH;AAAA,MAAG;AAAA,IAAA,CACN,GAED,KAAK,eAAe,IAAIC,OAAAA,OAAO,KAAK,QAAQ,GAC5C,KAAK,WAAW,IAAIA,OAAAA,OAAO,KAAK,GAAG,GAEnC,KAAK,aAAa,mBAAmB,KAAK,YAAY,EACjD,aAAa,iBAAiB,KAAK,QAAQ,EAC3C,SAAS,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAI,oBAA+B,kBACnC;AACQ,QAAA,IAAI,GACJ,IAAI;AAEH,WAAA,KAAA,IAAI,CAAC,IAAI,GACd,KAAK,IAAI,CAAC,IAAI,GAEd,KAAK,IAAI,CAAC,IAAI,IAAK,iBAAiB,QAAQ,mBAAmB,OAC/D,KAAK,IAAI,CAAC,IAAI,GAEd,KAAK,IAAI,CAAC,IAAI,IAAK,iBAAiB,QAAQ,mBAAmB,OAC/D,KAAK,IAAI,CAAC,IAAI,IAAK,iBAAi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