File tree 5 files changed +94
-0
lines changed
5 files changed +94
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author samme
3
+ * @copyright 2025 Phaser Studio Inc.
4
+ * @license {@link https://opensource.org/licenses/MIT|MIT License }
5
+ */
6
+
7
+ var NormalizeAngle = require ( './Normalize' ) ;
8
+
9
+ /**
10
+ * Gets the shortest nonnegative angular distance from angle1 to angle2.
11
+ *
12
+ * @function Phaser.Math.Angle.GetClockwiseDistance
13
+ * @since 4.0.0
14
+ *
15
+ * @param {number } angle1 - The starting angle in radians.
16
+ * @param {number } angle2 - The target angle in radians.
17
+ *
18
+ * @return {number } The distance in radians, in the range [0, 2pi).
19
+ */
20
+ var GetClockwiseDistance = function ( angle1 , angle2 )
21
+ {
22
+ return NormalizeAngle ( angle2 - angle1 ) ;
23
+ } ;
24
+
25
+ module . exports = GetClockwiseDistance ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author samme
3
+ * @copyright 2025 Phaser Studio Inc.
4
+ * @license {@link https://opensource.org/licenses/MIT|MIT License }
5
+ */
6
+
7
+ var MATH_CONST = require ( '../const' ) ;
8
+ var NormalizeAngle = require ( './Normalize' ) ;
9
+
10
+ var TAU = MATH_CONST . TAU ;
11
+
12
+ /**
13
+ * Gets the shortest nonpositive angular distance from angle1 to angle2.
14
+ *
15
+ * @function Phaser.Math.Angle.GetCounterClockwiseDistance
16
+ * @since 4.0.0
17
+ *
18
+ * @param {number } angle1 - The starting angle in radians.
19
+ * @param {number } angle2 - The target angle in radians.
20
+ *
21
+ * @return {number } The distance in radians, in the range (-2pi, 0].
22
+ */
23
+ var GetCounterClockwiseDistance = function ( angle1 , angle2 )
24
+ {
25
+ var distance = NormalizeAngle ( angle2 - angle1 ) ;
26
+
27
+ if ( distance > 0 )
28
+ {
29
+ distance -= TAU ;
30
+ }
31
+
32
+ return distance ;
33
+ } ;
34
+
35
+ module . exports = GetCounterClockwiseDistance ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author samme
3
+ * @copyright 2025 Phaser Studio Inc.
4
+ * @license {@link https://opensource.org/licenses/MIT|MIT License }
5
+ */
6
+
7
+ var WrapAngle = require ( './Wrap' ) ;
8
+
9
+ /**
10
+ * Gets the shortest signed angular distance from angle1 to angle2.
11
+ * A positive distance is a clockwise rotation.
12
+ * A negative distance is a counter-clockwise rotation.
13
+ *
14
+ * For calculation in degrees use {@link Phaser.Math.Angle.ShortestBetween} instead.
15
+ *
16
+ * @function Phaser.Math.Angle.GetShortestDistance
17
+ * @since 4.0.0
18
+ *
19
+ * @param {number } angle1 - The first angle in radians.
20
+ * @param {number } angle2 - The second angle in radians.
21
+ *
22
+ * @return {number } The distance in radians, in the range [-pi, pi).
23
+ */
24
+ var GetShortestDistance = function ( angle1 , angle2 )
25
+ {
26
+ return WrapAngle ( angle2 - angle1 ) ;
27
+ } ;
28
+
29
+ module . exports = GetShortestDistance ;
Original file line number Diff line number Diff line change 15
15
* greater than 0 then it's a counter-clockwise rotation, if < 0 then it's
16
16
* a clockwise rotation.
17
17
*
18
+ * For calculation in radians use {@link Phaser.Math.Angle.GetShortestDistance} instead.
19
+ *
18
20
* @function Phaser.Math.Angle.ShortestBetween
19
21
* @since 3.0.0
20
22
*
Original file line number Diff line number Diff line change @@ -15,6 +15,9 @@ module.exports = {
15
15
BetweenPointsY : require ( './BetweenPointsY' ) ,
16
16
BetweenY : require ( './BetweenY' ) ,
17
17
CounterClockwise : require ( './CounterClockwise' ) ,
18
+ GetClockwiseDistance : require ( './GetClockwiseDistance' ) ,
19
+ GetCounterClockwiseDistance : require ( './GetCounterClockwiseDistance' ) ,
20
+ GetShortestDistance : require ( './GetShortestDistance' ) ,
18
21
Normalize : require ( './Normalize' ) ,
19
22
Random : require ( './Random' ) ,
20
23
RandomDegrees : require ( './RandomDegrees' ) ,
You can’t perform that action at this time.
0 commit comments