UNPKG

phaser

Version:

A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers from the team at Phaser Studio Inc.

36 lines (30 loc) 1.04 kB
/** * @author Richard Davey <rich@phaser.io> * @copyright 2013-2025 Phaser Studio Inc. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var PointToLine = require('./PointToLine'); /** * Checks if a Point is located on the given line segment. * * @function Phaser.Geom.Intersects.PointToLineSegment * @since 3.0.0 * * @param {Phaser.Geom.Point} point - The Point to check for intersection. * @param {Phaser.Geom.Line} line - The line segment to check for intersection. * * @return {boolean} `true` if the Point is on the given line segment, otherwise `false`. */ var PointToLineSegment = function (point, line) { if (!PointToLine(point, line)) { return false; } var xMin = Math.min(line.x1, line.x2); var xMax = Math.max(line.x1, line.x2); var yMin = Math.min(line.y1, line.y2); var yMax = Math.max(line.y1, line.y2); return ((point.x >= xMin && point.x <= xMax) && (point.y >= yMin && point.y <= yMax)); }; module.exports = PointToLineSegment;