arcade-physics
Version:
Use Arcade Physics without Phaser.
49 lines • 1.87 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 LineToCircle_1 = __importDefault(require("./LineToCircle"));
const Contains_1 = __importDefault(require("../triangle/Contains"));
/**
* Checks if a Triangle and a Circle intersect.
*
* A Circle intersects a Triangle if its center is located within it or if any of the Triangle's sides intersect the Circle. As such, the Triangle and the Circle are considered "solid" for the intersection.
*
* @function Phaser.Geom.Intersects.TriangleToCircle
* @since 3.0.0
*
* @param {Phaser.Geom.Triangle} triangle - The Triangle to check for intersection.
* @param {Phaser.Geom.Circle} circle - The Circle to check for intersection.
*
* @return {boolean} `true` if the Triangle and the `Circle` intersect, otherwise `false`.
*/
const TriangleToCircle = (triangle, circle) => {
// First the cheapest ones:
if (triangle.left > circle.right ||
triangle.right < circle.left ||
triangle.top > circle.bottom ||
triangle.bottom < circle.top) {
return false;
}
if ((0, Contains_1.default)(triangle, circle.x, circle.y)) {
return true;
}
if ((0, LineToCircle_1.default)(triangle.getLineA(), circle)) {
return true;
}
if ((0, LineToCircle_1.default)(triangle.getLineB(), circle)) {
return true;
}
if ((0, LineToCircle_1.default)(triangle.getLineC(), circle)) {
return true;
}
return false;
};
exports.default = TriangleToCircle;
//# sourceMappingURL=TriangleToCircle.js.map