extent: add uniform sampler

This commit is contained in:
Danny Robson 2018-05-30 14:34:48 +10:00
parent 5dadd8eb38
commit 78dd62283b

View File

@ -21,6 +21,7 @@
#include "coord/base.hpp"
#include "vector.hpp"
#include "point.hpp"
#include "random.hpp"
#include <cstddef>
@ -165,6 +166,25 @@ namespace util {
};
template <size_t S, typename T>
util::point<S,T>
sample (util::extent<S,T> shape)
{
return sample (shape, util::random::generator ());
}
template <size_t S, typename T, typename GeneratorT>
util::point<S,T>
sample (util::extent<S,T> shape, GeneratorT &&gen)
{
util::point<S,T> p;
for (size_t i = 0; i < S; ++i)
p[i] = util::random::uniform (0, shape[i], gen);
return p;
}
///////////////////////////////////////////////////////////////////////////
// convenience typedefs
template <typename T> using extent2 = extent<2,T>;