Support non-modifying chunked_map::at
This commit is contained in:
parent
8284ea51bd
commit
7b84cb0b1f
1 changed files with 21 additions and 1 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
#include <psemek/geom/box.hpp>
|
#include <psemek/geom/box.hpp>
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace psemek::pcg
|
namespace psemek::pcg
|
||||||
{
|
{
|
||||||
|
|
@ -19,7 +20,7 @@ namespace psemek::pcg
|
||||||
, generator_(std::move(generator))
|
, generator_(std::move(generator))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
T const & operator()(geom::vector<int, N> p)
|
T & operator()(geom::point<int, N> p)
|
||||||
{
|
{
|
||||||
geom::vector<int, N> ip;
|
geom::vector<int, N> ip;
|
||||||
for (std::size_t i = 0; i < N; ++i)
|
for (std::size_t i = 0; i < N; ++i)
|
||||||
|
|
@ -45,6 +46,25 @@ namespace psemek::pcg
|
||||||
return it->second(t);
|
return it->second(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<T> at(geom::point<int, N> p) const
|
||||||
|
{
|
||||||
|
geom::vector<int, N> ip;
|
||||||
|
for (std::size_t i = 0; i < N; ++i)
|
||||||
|
{
|
||||||
|
ip[i] = (p[i] >= 0) ? (p[i] / chunk_size_) : -((- p[i] + chunk_size_ - 1) / chunk_size_);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto it = chunks_.find(ip);
|
||||||
|
if (it == chunks_.end())
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
std::array<std::size_t, N> t;
|
||||||
|
for (std::size_t i = 0; i < N; ++i)
|
||||||
|
t[i] = p[i] - ip[i] * chunk_size_;
|
||||||
|
|
||||||
|
return it->second(t);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int const chunk_size_;
|
int const chunk_size_;
|
||||||
generator_func generator_;
|
generator_func generator_;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue