UNPKG

arcade-physics

Version:
39 lines 1.4 kB
"use strict"; /** * @author Richard Davey <rich@photonstorm.com> * @copyright 2020 Photon Storm Ltd. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ Object.defineProperty(exports, "__esModule", { value: true }); /** * Merges a Rectangle with a list of points by repositioning and/or resizing it such that all points are located on or within its bounds. * * @function Phaser.Geom.Rectangle.MergePoints * @since 3.0.0 * * @generic {Phaser.Geom.Rectangle} O - [target,$return] * * @param {Phaser.Geom.Rectangle} target - The Rectangle which should be merged. * @param {Phaser.Geom.Point[]} points - An array of Points (or any object with public `x` and `y` properties) which should be merged with the Rectangle. * * @return {Phaser.Geom.Rectangle} The modified Rectangle. */ const MergePoints = (target, points) => { let minX = target.x; let maxX = target.right; let minY = target.y; let maxY = target.bottom; for (let i = 0; i < points.length; i++) { minX = Math.min(minX, points[i].x); maxX = Math.max(maxX, points[i].x); minY = Math.min(minY, points[i].y); maxY = Math.max(maxY, points[i].y); } target.x = minX; target.y = minY; target.width = maxX - minX; target.height = maxY - minY; return target; }; exports.default = MergePoints; //# sourceMappingURL=MergePoints.js.map