arcade-physics
Version:
Use Arcade Physics without Phaser.
47 lines • 1.77 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 Point_1 = __importDefault(require("../point/Point"));
const DegToRad_1 = __importDefault(require("../../math/DegToRad"));
/**
* Returns a Point from the perimeter of a Rectangle based on the given angle.
*
* @function Phaser.Geom.Rectangle.PerimeterPoint
* @since 3.0.0
*
* @generic {Phaser.Geom.Point} O - [out,$return]
*
* @param {Phaser.Geom.Rectangle} rectangle - The Rectangle to get the perimeter point from.
* @param {number} angle - The angle of the point, in degrees.
* @param {Phaser.Geom.Point} [out] - The Point object to store the position in. If not given, a new Point instance is created.
*
* @return {Phaser.Geom.Point} A Point object holding the coordinates of the Rectangle perimeter.
*/
const PerimeterPoint = (rectangle, angle, out) => {
if (out === undefined) {
out = new Point_1.default();
}
angle = (0, DegToRad_1.default)(angle);
const s = Math.sin(angle);
const c = Math.cos(angle);
let dx = c > 0 ? rectangle.width / 2 : rectangle.width / -2;
let dy = s > 0 ? rectangle.height / 2 : rectangle.height / -2;
if (Math.abs(dx * s) < Math.abs(dy * c)) {
dy = (dx * s) / c;
}
else {
dx = (dy * c) / s;
}
out.x = dx + rectangle.centerX;
out.y = dy + rectangle.centerY;
return out;
};
exports.default = PerimeterPoint;
//# sourceMappingURL=PerimeterPoint.js.map