UNPKG

arcade-physics

Version:
45 lines 1.86 kB
"use strict"; /** * @author Richard Davey <rich@photonstorm.com> * @copyright 2020 Photon Storm Ltd. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Rectangle_1 = __importDefault(require("./Rectangle")); const RectangleToRectangle_1 = __importDefault(require("../intersects/RectangleToRectangle")); /** * Takes two Rectangles and first checks to see if they intersect. * If they intersect it will return the area of intersection in the `out` Rectangle. * If they do not intersect, the `out` Rectangle will have a width and height of zero. * * @function Phaser.Geom.Rectangle.Intersection * @since 3.11.0 * * @generic {Phaser.Geom.Rectangle} O - [rect,$return] * * @param {Phaser.Geom.Rectangle} rectA - The first Rectangle to get the intersection from. * @param {Phaser.Geom.Rectangle} rectB - The second Rectangle to get the intersection from. * @param {Phaser.Geom.Rectangle} [out] - A Rectangle to store the intersection results in. * * @return {Phaser.Geom.Rectangle} The intersection result. If the width and height are zero, no intersection occurred. */ const Intersection = (rectA, rectB, out) => { if (out === undefined) { out = new Rectangle_1.default(); } if ((0, RectangleToRectangle_1.default)(rectA, rectB)) { out.x = Math.max(rectA.x, rectB.x); out.y = Math.max(rectA.y, rectB.y); out.width = Math.min(rectA.right, rectB.right) - out.x; out.height = Math.min(rectA.bottom, rectB.bottom) - out.y; } else { out.setEmpty(); } return out; }; exports.default = Intersection; //# sourceMappingURL=Intersection.js.map