UNPKG

arcade-physics

Version:
43 lines 1.65 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 LineToLine_1 = __importDefault(require("./LineToLine")); /** * Checks if a Triangle and a Line intersect. * * The Line intersects the Triangle if it starts inside of it, ends inside of it, or crosses any of the Triangle's sides. Thus, the Triangle is considered "solid". * * @function Phaser.Geom.Intersects.TriangleToLine * @since 3.0.0 * * @param {Phaser.Geom.Triangle} triangle - The Triangle to check with. * @param {Phaser.Geom.Line} line - The Line to check with. * * @return {boolean} `true` if the Triangle and the Line intersect, otherwise `false`. */ const TriangleToLine = (triangle, line) => { // If the Triangle contains either the start or end point of the line, it intersects if (triangle.contains(line.x1, line.y1) || triangle.contains(line.x2, line.y2)) { return true; } // Now check the line against each line of the Triangle if ((0, LineToLine_1.default)(triangle.getLineA(), line)) { return true; } if ((0, LineToLine_1.default)(triangle.getLineB(), line)) { return true; } if ((0, LineToLine_1.default)(triangle.getLineC(), line)) { return true; } return false; }; exports.default = TriangleToLine; //# sourceMappingURL=TriangleToLine.js.map