Add point in box generation
This commit is contained in:
parent
b1963460c0
commit
150d96e74e
1 changed files with 42 additions and 0 deletions
42
libs/pcg/include/psemek/pcg/random/point_box.hpp
Normal file
42
libs/pcg/include/psemek/pcg/random/point_box.hpp
Normal 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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue