UNPKG

arcade-physics

Version:
48 lines 1.66 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/Rectangle")); /** * Calculates the bounding AABB rectangle of a polygon. * * @function Phaser.Geom.Polygon.GetAABB * @since 3.0.0 * * @generic {Phaser.Geom.Rectangle} O - [out,$return] * * @param {Phaser.Geom.Polygon} polygon - The polygon that should be calculated. * @param {(Phaser.Geom.Rectangle|object)} [out] - The rectangle or object that has x, y, width, and height properties to store the result. Optional. * * @return {(Phaser.Geom.Rectangle|object)} The resulting rectangle or object that is passed in with position and dimensions of the polygon's AABB. */ const GetAABB = (polygon, out) => { if (out === undefined) { out = new Rectangle_1.default(); } let minX = Infinity; let minY = Infinity; let maxX = -minX; let maxY = -minY; let p; for (let i = 0; i < polygon.points.length; i++) { p = polygon.points[i]; minX = Math.min(minX, p.x); minY = Math.min(minY, p.y); maxX = Math.max(maxX, p.x); maxY = Math.max(maxY, p.y); } out.x = minX; out.y = minY; out.width = maxX - minX; out.height = maxY - minY; return out; }; exports.default = GetAABB; //# sourceMappingURL=GetAABB.js.map