build: add poisson sample demo

This commit is contained in:
Danny Robson 2018-04-19 13:49:55 +10:00
parent 89defb3bc2
commit 44ef094d04
2 changed files with 31 additions and 1 deletions

View File

@ -451,7 +451,7 @@ target_link_libraries(cruft-util dl)
###############################################################################
foreach (tool cpuid json-clean json-schema json-validate macro scratch)
foreach (tool cpuid json-clean json-schema json-validate poisson macro scratch)
add_executable (util_${tool} tools/${tool}.cpp)
set_target_properties (util_${tool} PROPERTIES OUTPUT_NAME ${tool})
target_link_libraries (util_${tool} cruft-util)

30
tools/poisson.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "cmdopt.hpp"
#include "geom/sample.hpp"
#include <cstdlib>
#include <iostream>
///////////////////////////////////////////////////////////////////////////////
int
main (int argc, char **argv)
{
util::extent2i area {256, 256};
float distance = 5.f;
int samples = 15;
util::cmdopt::parser opts;
opts.add<util::cmdopt::option::value<int>> ('w', "width", "width of the space to fill", area.w);
opts.add<util::cmdopt::option::value<int>> ('h', "height", "height of the space to fill", area.h);
opts.add<util::cmdopt::option::value<float>> ('d', "distance", "minimum distance between samples", distance);
opts.add<util::cmdopt::option::value<int>> ('s', "samples", "number of samples per iteration", samples);
opts.scan (argc, argv);
std::cout << "<svg height='" << area.h << "' width='" << area.h << "'>";
for (auto p: util::geom::poisson_sample (area, distance, samples))
std::cout << "<circle cx='" << p.x << "' cy='" << p.y << "' r='1' />";
std::cout << "</svg>";
return EXIT_SUCCESS;
}