From a1aa0c69497f02813d71df84f2ef4e9cd043b873 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 1 May 2018 16:02:55 +1000 Subject: [PATCH] geom/sample: make the extent surface sampler public --- geom/sample.hpp | 32 ++++++++++++++++++++++++++++++++ tools/poisson.cpp | 28 ---------------------------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/geom/sample.hpp b/geom/sample.hpp index c0c9e61e..41f1d6a0 100644 --- a/geom/sample.hpp +++ b/geom/sample.hpp @@ -23,6 +23,7 @@ #include +#include /////////////////////////////////////////////////////////////////////////////// namespace util::geom { @@ -87,6 +88,37 @@ namespace util::geom { template sampler (ShapeT const&) -> sampler>; + + //--------------------------------------------------------------------- + template + class sampler> { + public: + sampler (util::extent _target): + target (_target) + { ; } + + template + util::point + operator() (GeneratorT &&gen) const noexcept + { + util::point p; + + for (size_t i = 0; i < S; ++i) { + if constexpr (std::is_floating_point_v) { + p[i] = std::uniform_real_distribution (0, target[i]) (gen); + } else { + CHECK_GE (target[i], T{1}); + p[i] = std::uniform_int_distribution (0, target[i] - 1) (gen); + } + } + + return p; + } + + private: + util::extent target; + }; + /// approximate a poisson disc sampling through mitchell's best candidate. /// /// try to keep adding a new point to a set. each new point is the diff --git a/tools/poisson.cpp b/tools/poisson.cpp index b858044a..ae919904 100644 --- a/tools/poisson.cpp +++ b/tools/poisson.cpp @@ -8,35 +8,7 @@ #include -template -class util::geom::surface::sampler> { -public: - sampler (util::extent _target): - target (_target) - { ; } - - template - util::point - operator() (GeneratorT &&gen) const noexcept - { - util::point p; - for (size_t i = 0; i < S; ++i) - p[i] = std::uniform_real_distribution (0, target[i]) (gen); - return p; - } - -private: - util::extent target; -}; - - /////////////////////////////////////////////////////////////////////////////// -struct height { - float - operator() (util::point2f p) const { return std::pow (p.y / 100, 3.f); } -}; - - int main (int argc, char **argv) {