diff --git a/libs/pcg/include/psemek/pcg/sample.hpp b/libs/pcg/include/psemek/pcg/sample.hpp index 9443c155..66940ad8 100644 --- a/libs/pcg/include/psemek/pcg/sample.hpp +++ b/libs/pcg/include/psemek/pcg/sample.hpp @@ -5,6 +5,21 @@ namespace psemek::pcg { + template + void sample(Gen && gen, gfx::basic_pixmap & result) + { + for (std::size_t j = 0; j < result.height(); ++j) + { + for (std::size_t i = 0; i < result.width(); ++i) + { + float ti = (i + 0.5f) / result.width(); + float tj = (j + 0.5f) / result.height(); + + result(i, j) = gen(ti, tj); + } + } + } + template auto sample(Gen && gen, std::size_t width, std::size_t height) { @@ -12,18 +27,9 @@ namespace psemek::pcg gfx::basic_pixmap result({width, height}); - for (std::size_t j = 0; j < height; ++j) - { - for (std::size_t i = 0; i < width; ++i) - { - float ti = (i + 0.5f) / width; - float tj = (j + 0.5f) / height; - - result(i, j) = gen(ti, tj); - } - } - + sample(std::forward(gen), result); return result; } + }