mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-27 15:29:26 -06:00
Adapting Lua functions to new codegen functionality Improve the documentation itself Add some styling to generated documentation Have parameter names for Lua-defined Lua function documentation Co-authored-by: Emma Broman <emma.broman@liu.se>
83 lines
4.1 KiB
C++
83 lines
4.1 KiB
C++
/*****************************************************************************************
|
|
* *
|
|
* OpenSpace *
|
|
* *
|
|
* Copyright (c) 2014-2022 *
|
|
* *
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
|
* software and associated documentation files (the "Software"), to deal in the Software *
|
|
* without restriction, including without limitation the rights to use, copy, modify, *
|
|
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
|
* permit persons to whom the Software is furnished to do so, subject to the following *
|
|
* conditions: *
|
|
* *
|
|
* The above copyright notice and this permission notice shall be included in all copies *
|
|
* or substantial portions of the Software. *
|
|
* *
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
|
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
|
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
|
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
|
****************************************************************************************/
|
|
|
|
namespace {
|
|
|
|
/**
|
|
* Returns the cartesian world position of a ra dec coordinate with distance. If the
|
|
* coordinate is given as strings the format should be ra 'XhYmZs' and dec 'XdYmZs'. If
|
|
* the coordinate is given as numbers the values should be in degrees.
|
|
*/
|
|
[[codegen::luawrap]] glm::dvec3 convertFromRaDec(
|
|
std::variant<double, std::string> rightAscension,
|
|
std::variant<double, std::string> declination,
|
|
double distance)
|
|
{
|
|
using namespace openspace;
|
|
|
|
glm::dvec2 degrees = glm::dvec2(0.0);
|
|
if (std::holds_alternative<double>(rightAscension) &&
|
|
std::holds_alternative<double>(declination))
|
|
{
|
|
degrees = glm::dvec2(
|
|
std::get<double>(rightAscension),
|
|
std::get<double>(declination)
|
|
);
|
|
}
|
|
else if (std::holds_alternative<std::string>(rightAscension) &&
|
|
std::holds_alternative<std::string>(declination))
|
|
{
|
|
degrees = icrsToDecimalDegrees(
|
|
std::get<std::string>(rightAscension),
|
|
std::get<std::string>(declination)
|
|
);
|
|
}
|
|
else {
|
|
throw ghoul::lua::LuaError(
|
|
"Ra and Dec have to be of the same type, either String or Number"
|
|
);
|
|
}
|
|
|
|
glm::dvec3 pos = icrsToGalacticCartesian(degrees.x, degrees.y, distance);
|
|
return pos;
|
|
}
|
|
|
|
/**
|
|
* Returns the formatted ra, dec strings and distance for a given cartesian world
|
|
* coordinate.
|
|
*/
|
|
[[codegen::luawrap]] std::tuple<std::string, std::string, double> convertToRaDec(double x,
|
|
double y,
|
|
double z)
|
|
{
|
|
using namespace openspace;
|
|
glm::dvec3 deg = galacticCartesianToIcrs(x, y, z);
|
|
std::pair<std::string, std::string> raDecPair = decimalDegreesToIcrs(deg.x, deg.y);
|
|
return { raDecPair.first, raDecPair.second, deg.z };
|
|
}
|
|
|
|
#include "spacemodule_lua_codegen.cpp"
|
|
|
|
} // namespace
|