@@ -11,6 +11,7 @@ import org.luaj.vm2.lib.OneArgFunction
1111import org.luaj.vm2.lib.ThreeArgFunction
1212import org.luaj.vm2.lib.TwoArgFunction
1313import kotlin.math.abs
14+ import kotlin.math.atan2
1415import kotlin.math.floor
1516import kotlin.math.sqrt
1617import kotlin.random.Random
@@ -30,6 +31,7 @@ class MathLib : org.luaj.vm2.lib.MathLib() {
3031 math[" dst" ] = dst()
3132 math[" dst2" ] = dst2()
3233 math[" sign" ] = sign()
34+ math[" atan2" ] = atan2()
3335 math[" roverlap" ] = roverlap()
3436 math[" perlin" ] = perlin(Random .nextLong())
3537 return math
@@ -49,6 +51,24 @@ class MathLib : org.luaj.vm2.lib.MathLib() {
4951 }
5052 }
5153
54+ @TinyFunction(
55+ " Calculate the angle in radians between the positive x-axis and the point (x, y)." ,
56+ )
57+ internal inner class atan2 : TwoArgFunction () {
58+ @TinyCall(" Calculate the angle for the point (x, y). Please note the argument order: y then x." )
59+ override fun call (
60+ @TinyArg(" y" ) arg1 : LuaValue ,
61+ @TinyArg(" x" ) arg2 : LuaValue ,
62+ ): LuaValue {
63+ val y = arg1.todouble()
64+ val x = arg2.todouble()
65+
66+ val result = atan2(y, x)
67+
68+ return valueOf(result)
69+ }
70+ }
71+
5272 @TinyFunction(" Clamp the value between 2 values." , example = MATH_CLAMP_EXAMPLE )
5373 internal inner class clamp : ThreeArgFunction () {
5474 @TinyCall(" Clamp the value between a and b. If a is greater than b, then b will be returned." )
0 commit comments