Merge pull request #926 from MihailRis/update-heightmaps

add new methods to Heightmap
This commit is contained in:
MihailRis 2026-08-10 22:55:14 +03:00 • committed by GitHub
commit a4b2085afc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 62 additions and 23 deletions

View file

@ -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.

View file

@ -215,7 +215,26 @@ local map = Heightmap(ширина, высота)
Операции применяются ко всем значениям высоты.
```lua
-- Приведение к абсолютным значениям
map:abs()
-- Округление к меньшему целому
map:floor()
-- Округление к большему целому
map:ceil()
-- Округление к ближайшему целому
map:round()
-- Синус от значений высот (в радианах)
map:sin()
-- Косинус от значений высот (в радианах)
map:cos()
-- Тангенс от значений высот (в радианах)
map:tan()
```
Приводит значения высот к абсолютным.

View file

@ -264,6 +264,12 @@ static std::unordered_map<std::string, lua_CFunction> methods {
{"min", lua::wrap<l_binop_func<util::min>>},
{"max", lua::wrap<l_binop_func<util::max>>},
{"abs", lua::wrap<l_unaryop_func<util::abs>>},
{"floor", lua::wrap<l_unaryop_func<util::floor>>},
{"round", lua::wrap<l_unaryop_func<util::round>>},
{"ceil", lua::wrap<l_unaryop_func<util::ceil>>},
{"sin", lua::wrap<l_unaryop_func<util::sin>>},
{"cos", lua::wrap<l_unaryop_func<util::cos>>},
{"tan", lua::wrap<l_unaryop_func<util::tan>>},
{"resize", lua::wrap<l_resize>},
{"crop", lua::wrap<l_crop>},
{"at", lua::wrap<l_at>},

View file

@ -3,31 +3,26 @@
#include <glm/glm.hpp>
namespace util {
template<class T>
struct pow {
constexpr T operator()(T a, T b) const {
return glm::pow(a, b);
}
template<class T, T (*F)(T, T)>
struct binary_op {
constexpr T operator()(T a, T b) const { return F(a, b); }
};
template<class T>
struct min {
constexpr T operator()(T a, T b) const {
return glm::min(a, b);
}
template<class T> using pow = binary_op<T, glm::pow>;
template<class T> using min = binary_op<T, glm::min>;
template<class T> using max = binary_op<T, glm::max>;
template<class T, T (*F)(T)>
struct unary_op {
constexpr T operator()(T a) const { return F(a); }
};
template<class T>
struct max {
constexpr T operator()(T a, T b) const {
return glm::max(a, b);
}
};
template<class T>
struct abs {
constexpr T operator()(T a) const {
return glm::abs(a);
}
};
template<typename T> using abs = unary_op<T, glm::abs>;
template<typename T> using floor = unary_op<T, glm::floor>;
template<typename T> using round = unary_op<T, glm::round>;
template<typename T> using ceil = unary_op<T, glm::ceil>;
template<typename T> using sin = unary_op<T, glm::sin>;
template<typename T> using cos = unary_op<T, glm::cos>;
template<typename T> using tan = unary_op<T, glm::tan>;
}