From 78dd62283baf54ac8dd376762c60a06ec247c89d Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 30 May 2018 14:34:48 +1000 Subject: [PATCH] extent: add uniform sampler --- extent.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/extent.hpp b/extent.hpp index 79556dfe..14e4ebd3 100644 --- a/extent.hpp +++ b/extent.hpp @@ -21,6 +21,7 @@ #include "coord/base.hpp" #include "vector.hpp" #include "point.hpp" +#include "random.hpp" #include @@ -165,6 +166,25 @@ namespace util { }; + template + util::point + sample (util::extent shape) + { + return sample (shape, util::random::generator ()); + } + + + template + util::point + sample (util::extent shape, GeneratorT &&gen) + { + util::point p; + for (size_t i = 0; i < S; ++i) + p[i] = util::random::uniform (0, shape[i], gen); + return p; + } + + /////////////////////////////////////////////////////////////////////////// // convenience typedefs template using extent2 = extent<2,T>;