poisson-tool: use function objects for distances
This commit is contained in:
parent
864c0ecf58
commit
63cf40eeca
@ -94,11 +94,11 @@ namespace util::geom {
|
||||
/// furthest from all selected points.
|
||||
///
|
||||
/// \return a vector of the computed points
|
||||
template <typename SamplerT, typename GeneratorT>
|
||||
template <typename SamplerT, typename DistanceT, typename GeneratorT>
|
||||
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]);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "cmdopt.hpp"
|
||||
#include "geom/sample.hpp"
|
||||
#include "functor.hpp"
|
||||
#include "geom/aabb.hpp"
|
||||
#include "geom/sample.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
@ -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 << "<svg height='" << area.h << "' width='" << area.h << "'>";
|
||||
for (auto p: util::geom::surface::poisson (util::geom::surface::sampler (area),
|
||||
std::default_random_engine (),
|
||||
distance,
|
||||
util::functor::constant (distance),
|
||||
samples))
|
||||
{
|
||||
std::cout << "<circle cx='" << p.x << "' cy='" << p.y << "' r='1' />";
|
||||
|
Loading…
Reference in New Issue
Block a user