UNPKG

arcade-physics

Version:
41 lines 1.63 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 Point_1 = __importDefault(require("./Point")); const GetMagnitudeSq_1 = __importDefault(require("./GetMagnitudeSq")); /** * Calculates the vector projection of `pointA` onto the nonzero `pointB`. This is the * orthogonal projection of `pointA` onto a straight line parallel to `pointB`. * * @function Phaser.Geom.Point.Project * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {Phaser.Geom.Point} pointA - Point A, to be projected onto Point B. * @param {Phaser.Geom.Point} pointB - Point B, to have Point A projected upon it. * @param {Phaser.Geom.Point} [out] - The Point object to store the position in. If not given, a new Point instance is created. * * @return {Phaser.Geom.Point} A Point object holding the coordinates of the vector projection of `pointA` onto `pointB`. */ const Project = (pointA, pointB, out) => { if (out === undefined) { out = new Point_1.default(); } const dot = pointA.x * pointB.x + pointA.y * pointB.y; const amt = dot / (0, GetMagnitudeSq_1.default)(pointB); if (amt !== 0) { out.x = amt * pointB.x; out.y = amt * pointB.y; } return out; }; exports.default = Project; //# sourceMappingURL=Project.js.map