From b2abc7e7f83cb1b08097579c3cdfa892351f1c77 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 27 Oct 2020 15:31:09 +1000 Subject: [PATCH] g/s/surface: test first poisson candidate against AcceptT --- geom/sample/surface.hpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/geom/sample/surface.hpp b/geom/sample/surface.hpp index 36931be4..f3e86229 100644 --- a/geom/sample/surface.hpp +++ b/geom/sample/surface.hpp @@ -55,7 +55,7 @@ namespace cruft::geom::sample { GeneratorT &&gen, AcceptT &&accept, DistanceT &&minimum_distance, - std::size_t candidates_count + std::size_t const candidates_count ) { using point_type = decltype (sampler.eval (gen)); using value_type = typename point_type::value_type; @@ -63,9 +63,20 @@ namespace cruft::geom::sample { std::vector selected; std::vector candidates; - // prime the found elements list with an initial point we can - // perform distance calculations on - selected.push_back (sampler.eval (gen)); + // Prime the found elements list with an initial point we can + // perform distance calculations on. + for (std::size_t i = 0; i < candidates_count; ++i) { + auto const p = sampler.eval (gen); + if (!accept (p)) + continue; + + selected.push_back (sampler.eval (gen)); + break; + } + + // We couldn't find an initial candidate so abort. + if (selected.empty ()) + return selected; // keep trying to add one more new point while (1) {