diff --git a/doc/en/world-generator.md b/doc/en/world-generator.md index cd868b404..32c06b6e8 100644 --- a/doc/en/world-generator.md +++ b/doc/en/world-generator.md @@ -212,7 +212,26 @@ local map = Heightmap(width, height) Operations apply to all height values. ```lua +-- Convert to absolute values map:abs() + +-- Round down +map:floor() + +-- Round up +map:ceil() + +-- Round to the nearest integer +map:round() + +-- Sine of height values ​​(in radians) +map:sin() + +-- Cosine of height values ​​(in radians) +map:cos() + +-- Tangent of height values ​​(in radians) +map:tan() ``` Casts height values ​​to absolute. diff --git a/doc/ru/world-generator.md b/doc/ru/world-generator.md index 30e4b1098..cdb61678b 100644 --- a/doc/ru/world-generator.md +++ b/doc/ru/world-generator.md @@ -215,7 +215,26 @@ local map = Heightmap(ширина, высота) Операции применяются ко всем значениям высоты. ```lua +-- Приведение к абсолютным значениям map:abs() + +-- Округление к меньшему целому +map:floor() + +-- Округление к большему целому +map:ceil() + +-- Округление к ближайшему целому +map:round() + +-- Синус от значений высот (в радианах) +map:sin() + +-- Косинус от значений высот (в радианах) +map:cos() + +-- Тангенс от значений высот (в радианах) +map:tan() ``` Приводит значения высот к абсолютным. diff --git a/src/logic/scripting/lua/usertypes/lua_type_heightmap.cpp b/src/logic/scripting/lua/usertypes/lua_type_heightmap.cpp index 9286467d3..df2af6106 100644 --- a/src/logic/scripting/lua/usertypes/lua_type_heightmap.cpp +++ b/src/logic/scripting/lua/usertypes/lua_type_heightmap.cpp @@ -264,6 +264,12 @@ static std::unordered_map methods { {"min", lua::wrap>}, {"max", lua::wrap>}, {"abs", lua::wrap>}, + {"floor", lua::wrap>}, + {"round", lua::wrap>}, + {"ceil", lua::wrap>}, + {"sin", lua::wrap>}, + {"cos", lua::wrap>}, + {"tan", lua::wrap>}, {"resize", lua::wrap}, {"crop", lua::wrap}, {"at", lua::wrap}, diff --git a/src/util/functional_util.hpp b/src/util/functional_util.hpp index 2672c4fcf..874cc6709 100644 --- a/src/util/functional_util.hpp +++ b/src/util/functional_util.hpp @@ -3,31 +3,26 @@ #include namespace util { - template - struct pow { - constexpr T operator()(T a, T b) const { - return glm::pow(a, b); - } + template + struct binary_op { + constexpr T operator()(T a, T b) const { return F(a, b); } }; - template - struct min { - constexpr T operator()(T a, T b) const { - return glm::min(a, b); - } + template using pow = binary_op; + template using min = binary_op; + template using max = binary_op; + + + template + struct unary_op { + constexpr T operator()(T a) const { return F(a); } }; - template - struct max { - constexpr T operator()(T a, T b) const { - return glm::max(a, b); - } - }; - - template - struct abs { - constexpr T operator()(T a) const { - return glm::abs(a); - } - }; + template using abs = unary_op; + template using floor = unary_op; + template using round = unary_op; + template using ceil = unary_op; + template using sin = unary_op; + template using cos = unary_op; + template using tan = unary_op; }