Switch lazy perlin arguments from vectors to points
This commit is contained in:
parent
445ac3419e
commit
4e5ed4edad
1 changed files with 9 additions and 8 deletions
|
|
@ -7,6 +7,7 @@
|
|||
#include <psemek/geom/box.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <optional>
|
||||
|
||||
namespace psemek::pcg
|
||||
{
|
||||
|
|
@ -15,7 +16,7 @@ namespace psemek::pcg
|
|||
{
|
||||
|
||||
template <typename T, std::size_t N, typename F, typename G>
|
||||
T perlin_impl(geom::vector<T, N> p, int grid_size, F && grid_at, G && bound)
|
||||
T perlin_impl(geom::point<T, N> p, int grid_size, F && grid_at, G && bound)
|
||||
{
|
||||
geom::vector<int, N> ip;
|
||||
for (std::size_t i = 0; i < N; ++i)
|
||||
|
|
@ -24,7 +25,7 @@ namespace psemek::pcg
|
|||
}
|
||||
ip = bound(ip);
|
||||
|
||||
geom::vector<T, N> t = (p - geom::cast<T>(ip) * T(grid_size)) / T(grid_size);
|
||||
geom::vector<T, N> t = (p - p.zero() - geom::cast<T>(ip) * T(grid_size)) / T(grid_size);
|
||||
|
||||
T values[1 << N];
|
||||
|
||||
|
|
@ -73,7 +74,7 @@ namespace psemek::pcg
|
|||
, subgrid_(std::move(subgrid))
|
||||
{}
|
||||
|
||||
T operator()(geom::vector<T, N> p) const;
|
||||
T operator()(geom::point<T, N> p) const;
|
||||
|
||||
private:
|
||||
int grid_size_;
|
||||
|
|
@ -94,7 +95,7 @@ namespace psemek::pcg
|
|||
, gen_(std::move(generator))
|
||||
{}
|
||||
|
||||
T operator()(geom::vector<T, N> p) const;
|
||||
T operator()(geom::point<T, N> p) const;
|
||||
|
||||
auto subview(geom::box<T, N> const & box) const;
|
||||
|
||||
|
|
@ -136,7 +137,7 @@ namespace psemek::pcg
|
|||
grid_.resize(dims);
|
||||
}
|
||||
|
||||
T operator()(geom::vector<T, N> p) const;
|
||||
T operator()(geom::point<T, N> p) const;
|
||||
|
||||
private:
|
||||
int const grid_size_;
|
||||
|
|
@ -158,7 +159,7 @@ namespace psemek::pcg
|
|||
};
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
T lazy_perlin_view<T, N>::operator()(geom::vector<T, N> p) const
|
||||
T lazy_perlin_view<T, N>::operator()(geom::point<T, N> p) const
|
||||
{
|
||||
return detail::perlin_impl(p, grid_size_, [this](auto const & c){
|
||||
return subgrid_(c - origin_);
|
||||
|
|
@ -173,7 +174,7 @@ namespace psemek::pcg
|
|||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
T lazy_perlin<T, N>::operator()(geom::vector<T, N> p) const
|
||||
T lazy_perlin<T, N>::operator()(geom::point<T, N> p) const
|
||||
{
|
||||
return detail::perlin_impl(p, grid_size_, [this](auto const & c){ return grid_at(c); }, [](auto const & p){ return p; });
|
||||
}
|
||||
|
|
@ -203,7 +204,7 @@ namespace psemek::pcg
|
|||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
T bounded_lazy_perlin<T, N>::operator()(geom::vector<T, N> p) const
|
||||
T bounded_lazy_perlin<T, N>::operator()(geom::point<T, N> p) const
|
||||
{
|
||||
return detail::perlin_impl(p, grid_size_, [this](auto const & c){ return grid_at(c); }, [this](auto p){
|
||||
for (std::size_t i = 0; i < N; ++i)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue