arcade-physics
Version:
Use Arcade Physics without Phaser.
53 lines • 2.13 kB
JavaScript
;
/**
* @author Florian Vazelle
* @author Geoffrey Glaive
* @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/Point"));
const LineToLine_1 = __importDefault(require("./LineToLine"));
const LineToRectangle_1 = __importDefault(require("./LineToRectangle"));
/**
* Checks for intersection between the Line and a Rectangle shape,
* and returns the intersection points as a Point object array.
*
* @function Phaser.Geom.Intersects.GetLineToRectangle
* @since 3.0.0
*
* @param {Phaser.Geom.Line} line - The Line to check for intersection.
* @param {(Phaser.Geom.Rectangle|object)} rect - The Rectangle to check for intersection.
* @param {array} [out] - An optional array in which to store the points of intersection.
*
* @return {array} An array with the points of intersection if objects intersect, otherwise an empty array.
*/
const GetLineToRectangle = (line, rect, out) => {
if (out === undefined) {
out = [];
}
if ((0, LineToRectangle_1.default)(line, rect)) {
const lineA = rect.getLineA();
const lineB = rect.getLineB();
const lineC = rect.getLineC();
const lineD = rect.getLineD();
const output = [new Point_1.default(), new Point_1.default(), new Point_1.default(), new Point_1.default()];
const result = [
(0, LineToLine_1.default)(lineA, line, output[0]),
(0, LineToLine_1.default)(lineB, line, output[1]),
(0, LineToLine_1.default)(lineC, line, output[2]),
(0, LineToLine_1.default)(lineD, line, output[3])
];
for (let i = 0; i < 4; i++) {
if (result[i]) {
out.push(output[i]);
}
}
}
return out;
};
exports.default = GetLineToRectangle;
//# sourceMappingURL=GetLineToRectangle.js.map