mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 03:29:44 -06:00
Enable both strings and numbers to lua ra dec conversion function
This commit is contained in:
@@ -32,16 +32,32 @@
|
||||
namespace openspace::space::luascriptfunctions {
|
||||
|
||||
int convertFromRaDec(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 3, "lua::convertFromRaDec");
|
||||
ghoul::lua::checkArgumentsAndThrow(L, { 3, 4 }, "lua::convertFromRaDec");
|
||||
|
||||
glm::dvec2 degrees = glm::dvec2(0.0);
|
||||
bool isDegrees = true;
|
||||
if (lua_type(L, 1) == LUA_TSTRING && lua_type(L, 2) == LUA_TSTRING) {
|
||||
std::string s_ra = ghoul::lua::value<std::string>(L, 1);
|
||||
std::string s_dec = ghoul::lua::value<std::string>(L, 2);
|
||||
degrees = icrsToDecimalDegrees(s_ra, s_dec);
|
||||
}
|
||||
else if (lua_type(L, 1) == LUA_TNUMBER && lua_type(L, 2) == LUA_TNUMBER) {
|
||||
degrees.x = ghoul::lua::value<double>(L, 1);
|
||||
degrees.y = ghoul::lua::value<double>(L, 2);
|
||||
if (lua_gettop(L) >= 4) {
|
||||
isDegrees = ghoul::lua::value<bool>(L, 4);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw ghoul::lua::LuaRuntimeException("lua::convertFromRaDec: Ra and Dec have to "
|
||||
"be of the same type, either String or Number"
|
||||
);
|
||||
}
|
||||
|
||||
std::string ra = ghoul::lua::value<std::string>(L, 1);
|
||||
std::string dec = ghoul::lua::value<std::string>(L, 2);
|
||||
double distance = ghoul::lua::value<double>(L, 3);
|
||||
lua_settop(L, 0);
|
||||
|
||||
glm::dvec2 degrees = icrsToDecimalDegrees(ra, dec);
|
||||
glm::dvec3 pos = icrsToGalacticCartesian(degrees.x, degrees.y, distance);
|
||||
|
||||
glm::dvec3 pos = icrsToGalacticCartesian(degrees.x, degrees.y, distance, isDegrees);
|
||||
ghoul::lua::push(L, pos);
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 1, "Incorrect number of items left on stack");
|
||||
@@ -57,7 +73,8 @@ int convertToRaDec(lua_State* L) {
|
||||
lua_settop(L, 0);
|
||||
|
||||
glm::dvec3 degrees = galacticCartesianToIcrs(x, y, z);
|
||||
std::pair<std::string, std::string> raDecPair = decimalDegreesToIcrs(degrees.x, degrees.y);
|
||||
std::pair<std::string, std::string> raDecPair
|
||||
= decimalDegreesToIcrs(degrees.x, degrees.y);
|
||||
|
||||
ghoul::lua::push(L, raDecPair.first); // Ra
|
||||
ghoul::lua::push(L, raDecPair.second); // Dec
|
||||
|
||||
Reference in New Issue
Block a user