arcade-physics
Version:
Use Arcade Physics without Phaser.
35 lines • 1.16 kB
JavaScript
;
/**
* @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 Point_1 = __importDefault(require("../point/Point"));
/**
* Returns a random point on a given Line.
*
* @function Phaser.Geom.Line.Random
* @since 3.0.0
*
* @generic {Phaser.Geom.Point} O - [out,$return]
*
* @param {Phaser.Geom.Line} line - The Line to calculate the random Point on.
* @param {(Phaser.Geom.Point|object)} [out] - An instance of a Point to be modified.
*
* @return {(Phaser.Geom.Point|object)} A random Point on the Line.
*/
const Random = (line, out) => {
if (out === undefined) {
out = new Point_1.default();
}
const t = Math.random();
out.x = line.x1 + t * (line.x2 - line.x1);
out.y = line.y1 + t * (line.y2 - line.y1);
return out;
};
exports.default = Random;
//# sourceMappingURL=Random.js.map