UNPKG

arcade-physics

Version:
47 lines 1.75 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 Centroid_1 = __importDefault(require("./Centroid")); const Offset_1 = __importDefault(require("./Offset")); /** * @callback CenterFunction * * @param {Phaser.Geom.Triangle} triangle - The Triangle to return the center coordinates of. * * @return {Phaser.Math.Vector2} The center point of the Triangle according to the function. */ /** * Positions the Triangle so that it is centered on the given coordinates. * * @function Phaser.Geom.Triangle.CenterOn * @since 3.0.0 * * @generic {Phaser.Geom.Triangle} O - [triangle,$return] * * @param {Phaser.Geom.Triangle} triangle - The triangle to be positioned. * @param {number} x - The horizontal coordinate to center on. * @param {number} y - The vertical coordinate to center on. * @param {CenterFunction} [centerFunc] - The function used to center the triangle. Defaults to Centroid centering. * * @return {Phaser.Geom.Triangle} The Triangle that was centered. */ const CenterOn = (triangle, x, y, centerFunc) => { if (centerFunc === undefined) { centerFunc = Centroid_1.default; } // Get the center of the triangle const center = centerFunc(triangle); // Difference const diffX = x - center.x; const diffY = y - center.y; return (0, Offset_1.default)(triangle, diffX, diffY); }; exports.default = CenterOn; //# sourceMappingURL=CenterOn.js.map