g/sample/surface: add region sampling

This commit is contained in:
Danny Robson 2019-08-21 08:27:07 +10:00
parent f551e48ddb
commit 70c523d029

View File

@ -14,6 +14,7 @@
#include "../../coord/fwd.hpp"
#include "../../extent.hpp"
#include "../../region.hpp"
#include "../../random.hpp"
#include <cstddef>
@ -102,4 +103,35 @@ namespace cruft::geom::sample {
class surface<extent<2,T>> :
public volume<extent<2,T>>
{ using volume<extent<2,T>>::volume; };
/// A surface sampler specialisation for 2d regions
///
/// We encapsulate an extent sampler and an offset, then mainly pass off
/// the work to the extent sampler.
template <typename T>
class surface<region<2,T>> {
public:
using shape_type = region<2,T>;
surface (shape_type const &_shape)
: m_extent (_shape.e)
, m_offset (_shape.p.template as<vector> ())
{ ; }
template <typename GeneratorT>
decltype(auto)
eval (GeneratorT &&gen)
{
return m_extent.eval (
std::forward<GeneratorT> (gen)
) + m_offset;
}
private:
surface<extent<2,T>> m_extent;
cruft::vector<2,T> m_offset;
};
}