From 63cf40eeca21876bdc18a58cc82e010894f4a446 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 27 Apr 2018 16:33:18 +1000 Subject: [PATCH] poisson-tool: use function objects for distances --- geom/sample.hpp | 8 ++++---- tools/poisson.cpp | 12 +++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/geom/sample.hpp b/geom/sample.hpp index f313032d..f88fb1b5 100644 --- a/geom/sample.hpp +++ b/geom/sample.hpp @@ -94,11 +94,11 @@ namespace util::geom { /// furthest from all selected points. /// /// \return a vector of the computed points - template + template auto poisson (SamplerT const &target, GeneratorT &&gen, - float minimum_distance, + DistanceT &&minimum_distance, size_t candidates_count) { @@ -138,7 +138,7 @@ namespace util::geom { d = util::min (d, distance (p, q)); // record if it's the furthest away - if (d > best_distance) { + if (d > best_distance && d > minimum_distance (p)) { best_distance = d; best_index = i; } @@ -146,7 +146,7 @@ namespace util::geom { // if we didn't find a suitable point then we give up and // return the points we found, otherwise record the best point - if (best_distance < minimum_distance) + if (best_distance <= 0) break; selected.push_back (candidates[best_index]); diff --git a/tools/poisson.cpp b/tools/poisson.cpp index 35c44899..b858044a 100644 --- a/tools/poisson.cpp +++ b/tools/poisson.cpp @@ -1,6 +1,7 @@ #include "cmdopt.hpp" -#include "geom/sample.hpp" +#include "functor.hpp" #include "geom/aabb.hpp" +#include "geom/sample.hpp" #include #include @@ -30,6 +31,12 @@ private: /////////////////////////////////////////////////////////////////////////////// +struct height { + float + operator() (util::point2f p) const { return std::pow (p.y / 100, 3.f); } +}; + + int main (int argc, char **argv) { @@ -45,11 +52,10 @@ main (int argc, char **argv) opts.scan (argc, argv); - std::cout << ""; for (auto p: util::geom::surface::poisson (util::geom::surface::sampler (area), std::default_random_engine (), - distance, + util::functor::constant (distance), samples)) { std::cout << "";