From a626ba277760481a46a4445db8e1da7d47f42392 Mon Sep 17 00:00:00 2001 From: samme Date: Fri, 24 Apr 2020 13:26:42 -0700 Subject: [PATCH] Add Math#RotateTo --- src/math/RotateTo.js | 31 +++++++++++++++++++++++++++++++ src/math/index.js | 1 + 2 files changed, 32 insertions(+) create mode 100644 src/math/RotateTo.js diff --git a/src/math/RotateTo.js b/src/math/RotateTo.js new file mode 100644 index 000000000..f89dcc457 --- /dev/null +++ b/src/math/RotateTo.js @@ -0,0 +1,31 @@ +/** + * @author samme + * @copyright 2020 Photon Storm Ltd. + * @license {@link https://opensource.org/licenses/MIT|MIT License} + */ + +/** + * Position a `point` at the given `angle` and `distance` to (`x`, `y`). + * + * @function Phaser.Math.RotateTo + * @since 3.24.0 + * + * @generic {Phaser.Math.Vector2Like} T - [point,$return] + * + * @param {Phaser.Math.Vector2Like} point - The point to be positioned. + * @param {number} x - The horizontal coordinate to position from. + * @param {number} y - The vertical coordinate to position from. + * @param {number} angle - The angle of rotation in radians. + * @param {number} distance - The distance from (x, y) to place the point at. + * + * @return {Phaser.Math.Vector2Like} The given point. + */ +var RotateTo = function (point, x, y, angle, distance) +{ + point.x = x + (distance * Math.cos(angle)); + point.y = y + (distance * Math.sin(angle)); + + return point; +}; + +module.exports = RotateTo; diff --git a/src/math/index.js b/src/math/index.js index 11a3b1350..3c87cf098 100644 --- a/src/math/index.js +++ b/src/math/index.js @@ -52,6 +52,7 @@ var PhaserMath = { Rotate: require('./Rotate'), RotateAround: require('./RotateAround'), RotateAroundDistance: require('./RotateAroundDistance'), + RotateTo: require('./RotateTo'), RoundAwayFromZero: require('./RoundAwayFromZero'), RoundTo: require('./RoundTo'), SinCosTableGenerator: require('./SinCosTableGenerator'),