From b406bc1ec410795b1a349fd064a81162d608bc6e Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 6 Sep 2025 11:41:28 +0300 Subject: [PATCH] fix: C++ vecn functions precision loss --- src/logic/scripting/lua/libs/libvecn.cpp | 34 ++++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/logic/scripting/lua/libs/libvecn.cpp b/src/logic/scripting/lua/libs/libvecn.cpp index 0533525b..8d811857 100644 --- a/src/logic/scripting/lua/libs/libvecn.cpp +++ b/src/logic/scripting/lua/libs/libvecn.cpp @@ -32,7 +32,7 @@ static int l_mix(lua::State* L) { template class Op> static int l_binop(lua::State* L) { uint argc = lua::check_argc(L, 2, 3); - auto a = lua::tovec(L, 1); + auto a = lua::tovec(L, 1); if (lua::isnumber(L, 2)) { // scalar second operand overload auto b = lua::tonumber(L, 2); @@ -45,10 +45,10 @@ static int l_binop(lua::State* L) { } return 1; } else { - return lua::setvec(L, 3, op(a, glm::vec(b))); + return lua::setvec(L, 3, op(a, glm::vec(b))); } } else { - auto b = lua::tovec(L, 2); + auto b = lua::tovec(L, 2); Op op; if (argc == 2) { lua::createtable(L, n, 0); @@ -63,10 +63,10 @@ static int l_binop(lua::State* L) { } } -template (*func)(const glm::vec&)> +template (*func)(const glm::vec&)> static int l_unaryop(lua::State* L) { uint argc = lua::check_argc(L, 1, 2); - auto vec = func(lua::tovec(L, 1)); + auto vec = func(lua::tovec(L, 1)); switch (argc) { case 1: lua::createtable(L, n, 0); @@ -81,25 +81,25 @@ static int l_unaryop(lua::State* L) { return 0; } -template &)> +template &)> static int l_scalar_op(lua::State* L) { lua::check_argc(L, 1); - auto vec = lua::tovec(L, 1); + auto vec = lua::tovec(L, 1); return lua::pushnumber(L, func(vec)); } template static int l_distance(lua::State* L) { lua::check_argc(L, 2); - auto a = lua::tovec(L, 1); - auto b = lua::tovec(L, 2); + auto a = lua::tovec(L, 1); + auto b = lua::tovec(L, 2); return lua::pushnumber(L,glm::distance(a, b)); } template static int l_pow(lua::State* L) { uint argc = lua::check_argc(L, 2, 3); - auto a = lua::tovec(L, 1); + auto a = lua::tovec(L, 1); if (lua::isnumber(L, 2)) { auto b = lua::tonumber(L, 2); @@ -111,10 +111,10 @@ static int l_pow(lua::State* L) { } return 1; } else { - return lua::setvec(L, 3, pow(a, glm::vec(b))); + return lua::setvec(L, 3, pow(a, glm::vec(b))); } } else { - auto b = lua::tovec(L, 2); + auto b = lua::tovec(L, 2); if (argc == 2) { lua::createtable(L, n, 0); for (uint i = 0; i < n; i++) { @@ -131,15 +131,15 @@ static int l_pow(lua::State* L) { template static int l_dot(lua::State* L) { lua::check_argc(L, 2); - const auto& a = lua::tovec(L, 1); - const auto& b = lua::tovec(L, 2); + auto a = lua::tovec(L, 1); + auto b = lua::tovec(L, 2); return lua::pushnumber(L, glm::dot(a, b)); } template static int l_inverse(lua::State* L) { uint argc = lua::check_argc(L, 1, 2); - auto vec = lua::tovec(L, 1); + auto vec = lua::tovec(L, 1); switch (argc) { case 1: lua::createtable(L, n, 0); @@ -163,7 +163,7 @@ static int l_spherical_rand(lua::State* L) { return lua::setvec( L, 2, - glm::sphericalRand(static_cast(lua::tonumber(L, 1))) + glm::sphericalRand(lua::tonumber(L, 1)) ); } return 0; @@ -186,7 +186,7 @@ static int l_vec2_angle(lua::State* L) { template static int l_tostring(lua::State* L) { lua::check_argc(L, 1); - auto vec = lua::tovec(L, 1); + auto vec = lua::tovec(L, 1); std::stringstream ss; ss << "vec" << std::to_string(n) << "{"; for (int i = 0; i < n; i++) {