UNPKG

arcade-physics

Version:
44 lines 2.13 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 Circumference_1 = __importDefault(require("./Circumference")); const CircumferencePoint_1 = __importDefault(require("./CircumferencePoint")); const FromPercent_1 = __importDefault(require("../../math/FromPercent")); const const_1 = __importDefault(require("../../math/const")); /** * Returns an array of Point objects containing the coordinates of the points around the circumference of the Circle, * based on the given quantity or stepRate values. * * @function Phaser.Geom.Circle.GetPoints * @since 3.0.0 * * @param {Phaser.Geom.Circle} circle - The Circle to get the points from. * @param {number} quantity - The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. * @param {number} [stepRate] - Sets the quantity by getting the circumference of the circle and dividing it by the stepRate. * @param {array} [output] - An array to insert the points in to. If not provided a new array will be created. * * @return {Phaser.Geom.Point[]} An array of Point objects pertaining to the points around the circumference of the circle. */ const GetPoints = (circle, quantity, stepRate, out) => { if (out === undefined) { out = []; } // If quantity is a falsey value (false, null, 0, undefined, etc) then we calculate it based on the stepRate instead. if (!quantity && stepRate > 0) { quantity = (0, Circumference_1.default)(circle) / stepRate; } for (let i = 0; i < quantity; i++) { const angle = (0, FromPercent_1.default)(i / quantity, 0, const_1.default.PI2); out.push((0, CircumferencePoint_1.default)(circle, angle)); } return out; }; exports.default = GetPoints; //# sourceMappingURL=GetPoints.js.map