Add point in box generation

This commit is contained in:
Nikita Lisitsa 2020-09-13 11:03:06 +03:00
parent b1963460c0
commit 150d96e74e

View file

@ -0,0 +1,42 @@
#pragma once
#include <psemek/geom/point.hpp>
#include <psemek/geom/box.hpp>
#include <random>
namespace psemek::pcg
{
template <typename T, std::size_t N>
struct box_point_distribution
{
std::uniform_real_distribution<T> d[N];
box_point_distribution(geom::box<T, N> const & b)
{
for (std::size_t i = 0; i < N; ++i)
{
d[i] = std::uniform_real_distribution<T>{b[i].min, b[i].max};
}
}
box_point_distribution()
{
for (std::size_t i = 0; i < N; ++i)
{
d[i] = std::uniform_real_distribution<T>{T{0}, T{1}};
}
}
template <typename RNG>
auto operator()(RNG && rng)
{
geom::point<T, N> p;
for (std::size_t i = 0; i < N; ++i)
p[i] = d[i](rng);
return p;
}
};
}