{"version":3,"file":"rectangleExtras.mjs","sources":["../../src/math-extras/rectangleExtras.ts"],"sourcesContent":["import { Rectangle } from '../maths/shapes/Rectangle';\n\nexport const rectangleExtraMixins: Partial<Rectangle> = {\n    /**\n     * Determines whether the `other` Rectangle is contained within `this` Rectangle object.\n     * Rectangles that occupy the same space are considered to be containing each other.\n     * Rectangles without area (width or height equal to zero) can't contain anything,\n     * not even other arealess rectangles.\n     *\n     * _Note: Only available with **pixi.js/math-extras**._\n     * @method containsRect\n     * @memberof maths.Rectangle#\n     * @param {Rectangle} other - The Rectangle to fit inside `this`.\n     * @returns {boolean} A value of `true` if `this` Rectangle contains `other`; otherwise `false`.\n     */\n    containsRect(other: Rectangle): boolean\n    {\n        if (other.width <= 0 || other.height <= 0)\n        {\n            return other.x > this.x && other.y > this.y && other.right < this.right && other.bottom < this.bottom;\n        }\n\n        return other.x >= this.x && other.y >= this.y && other.right <= this.right && other.bottom <= this.bottom;\n    },\n    /**\n     * Accepts `other` Rectangle and returns true if the given Rectangle is equal to `this` Rectangle.\n     *\n     * _Note: Only available with **pixi.js/math-extras**._\n     * @method equals\n     * @memberof maths.Rectangle#\n     * @param {Rectangle} other - The Rectangle to compare with `this`\n     * @returns {boolean} Returns true if all `x`, `y`, `width`, and `height` are equal.\n     */\n    equals(other: Rectangle): boolean\n    {\n        if (other === this)\n        {\n            return true;\n        }\n\n        return (\n            other\n            && this.x === other.x\n            && this.y === other.y\n            && this.width === other.width\n            && this.height === other.height\n        );\n    },\n\n    /**\n     * If the area of the intersection between the Rectangles `other` and `this` is not zero,\n     * returns the area of intersection as a Rectangle object. Otherwise, return an empty Rectangle\n     * with its properties set to zero.\n     * Rectangles without area (width or height equal to zero) can't intersect or be intersected\n     * and will always return an empty rectangle with its properties set to zero.\n     *\n     * _Note: Only available with **pixi.js/math-extras**._\n     * @method intersection\n     * @memberof maths.Rectangle#\n     * @param {Rectangle} other - The Rectangle to intersect with `this`.\n     * @param {Rectangle} [outRect] - A Rectangle object in which to store the value,\n     * optional (otherwise will create a new Rectangle).\n     * @returns {Rectangle} The intersection of `this` and `other`.\n     */\n    intersection<T extends Rectangle>(other: Rectangle, outRect?: T): T\n    {\n        if (!outRect)\n        {\n            outRect = new Rectangle() as T;\n        }\n\n        const x0 = this.x < other.x ? other.x : this.x;\n        const x1 = this.right > other.right ? other.right : this.right;\n\n        if (x1 <= x0)\n        {\n            outRect.x = outRect.y = outRect.width = outRect.height = 0;\n\n            return outRect;\n        }\n\n        const y0 = this.y < other.y ? other.y : this.y;\n        const y1 = this.bottom > other.bottom ? other.bottom : this.bottom;\n\n        if (y1 <= y0)\n        {\n            outRect.x = outRect.y = outRect.width = outRect.height = 0;\n\n            return outRect;\n        }\n\n        outRect.x = x0;\n        outRect.y = y0;\n        outRect.width = x1 - x0;\n        outRect.height = y1 - y0;\n\n        return outRect;\n    },\n\n    /**\n     * Adds `this` and `other` Rectangles together to create a new Rectangle object filling\n     * the horizontal and vertical space between the two rectangles.\n     *\n     * _Note: Only available with **pixi.js/math-extras**._\n     * @method union\n     * @memberof maths.Rectangle#\n     * @param {Rectangle} other - The Rectangle to unite with `this`.\n     * @param {Rectangle} [outRect] - A Rectangle object in which to store the value,\n     * optional (otherwise will create a new Rectangle).\n     * @returns {Rectangle} The union of `this` and `other`.\n     */\n    union<T extends Rectangle>(other: Rectangle, outRect?: T): T\n    {\n        if (!outRect)\n        {\n            outRect = new Rectangle() as T;\n        }\n\n        const x1 = Math.min(this.x, other.x);\n        const x2 = Math.max(this.x + this.width, other.x + other.width);\n        const y1 = Math.min(this.y, other.y);\n        const y2 = Math.max(this.y + this.height, other.y + other.height);\n\n        outRect.x = x1;\n        outRect.y = y1;\n        outRect.width = x2 - x1;\n        outRect.height = y2 - y1;\n\n        return outRect;\n    },\n};\n"],"names":[],"mappings":";;;AAEO,MAAM,oBAA2C,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAapD,aAAa,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