UNPKG

arcade-physics

Version:
39 lines 1.35 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 const_1 = __importDefault(require("../../math/const")); const Angle_1 = __importDefault(require("./Angle")); const Point_1 = __importDefault(require("../point/Point")); /** * Calculate the normal of the given line. * * The normal of a line is a vector that points perpendicular from it. * * @function Phaser.Geom.Line.GetNormal * @since 3.0.0 * * @generic {Phaser.Geom.Point} O - [out,$return] * * @param {Phaser.Geom.Line} line - The line to calculate the normal of. * @param {(Phaser.Geom.Point|object)} [out] - An optional point object to store the normal in. * * @return {(Phaser.Geom.Point|object)} The normal of the Line. */ const GetNormal = (line, out) => { if (out === undefined) { out = new Point_1.default(); } const a = (0, Angle_1.default)(line) - const_1.default.TAU; out.x = Math.cos(a); out.y = Math.sin(a); return out; }; exports.default = GetNormal; //# sourceMappingURL=GetNormal.js.map