geom/sample: make the extent surface sampler public
This commit is contained in:
parent
8b47a2e350
commit
a1aa0c6949
@ -23,6 +23,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include <random>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace util::geom {
|
||||
@ -87,6 +88,37 @@ namespace util::geom {
|
||||
template <typename ShapeT>
|
||||
sampler (ShapeT const&) -> sampler<std::decay_t<ShapeT>>;
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
template <size_t S, typename T>
|
||||
class sampler<util::extent<S,T>> {
|
||||
public:
|
||||
sampler (util::extent<S,T> _target):
|
||||
target (_target)
|
||||
{ ; }
|
||||
|
||||
template <typename GeneratorT>
|
||||
util::point<S,T>
|
||||
operator() (GeneratorT &&gen) const noexcept
|
||||
{
|
||||
util::point<S,T> p;
|
||||
|
||||
for (size_t i = 0; i < S; ++i) {
|
||||
if constexpr (std::is_floating_point_v<T>) {
|
||||
p[i] = std::uniform_real_distribution<T> (0, target[i]) (gen);
|
||||
} else {
|
||||
CHECK_GE (target[i], T{1});
|
||||
p[i] = std::uniform_int_distribution<T> (0, target[i] - 1) (gen);
|
||||
}
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
private:
|
||||
util::extent<S,T> 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
|
||||
|
@ -8,35 +8,7 @@
|
||||
#include <random>
|
||||
|
||||
|
||||
template <size_t S>
|
||||
class util::geom::surface::sampler<util::extent<S,float>> {
|
||||
public:
|
||||
sampler (util::extent<S,float> _target):
|
||||
target (_target)
|
||||
{ ; }
|
||||
|
||||
template <typename GeneratorT>
|
||||
util::point<S,float>
|
||||
operator() (GeneratorT &&gen) const noexcept
|
||||
{
|
||||
util::point<S,float> p;
|
||||
for (size_t i = 0; i < S; ++i)
|
||||
p[i] = std::uniform_real_distribution<float> (0, target[i]) (gen);
|
||||
return p;
|
||||
}
|
||||
|
||||
private:
|
||||
util::extent<S,float> target;
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
struct height {
|
||||
float
|
||||
operator() (util::point2f p) const { return std::pow (p.y / 100, 3.f); }
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user