Skip to content

Commit

Permalink
added more 'requires' constraints; updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
dsecrieru committed Mar 27, 2023
1 parent 4ac71dd commit bebcc68
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

A header-only, C++20 implementation of Robert Bridson's *Fast Poisson Disk Sampling* (2007), for the 2-dimensional case.
More details in the original paper: https://www.cs.ubc.ca/~rbridson/docs/bridson-siggraph07-poissondisk.pdf
What I wanted, that is a bit different from other implementations that I've seen, is the possibility to parametrize the point type.

In the future, I might add more implementations.

Built and tested on:
- Windows 10, VS 2017, compiler version 19.35.32215
Expand Down Expand Up @@ -43,4 +46,4 @@ Implementation | points | ms
martynafford | ~9774 | 23.91
dsecrieru | ~9970 | 21

This is a good one, very similar in performance, with some interesting ideas that inspired me to incorporate (local lambdas, configuration pack).
This is a good one, very similar in performance, with some interesting ideas that inspired me to incorporate (local lambdas, configuration pack, random picking from active list might not be necessary).
4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "pds_Bridson.hpp"

struct point2d {
float x, y;
float x, y;

point2d() = delete;
point2d(float x_, float y_) : x(x_), y(y_) {}
Expand All @@ -34,7 +34,7 @@ void bench(const blue_noise::bridson_2d::config& conf) {
const auto avg_count = std::reduce(sample_counts.begin(), sample_counts.end()) / float(runs);
const auto avg_duration = std::reduce(durations.begin(), durations.end()) / float(runs);

std::cout << std::format("generated avg of {:6.0f} points in ~{:3}\n", avg_count, avg_duration);
std::cout << std::format("generated approx {:6.0f} points in ~{:3}\n", avg_count, avg_duration);
}

int main() {
Expand Down
5 changes: 4 additions & 1 deletion pds_Bridson.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ struct config {
*
*/
template<typename point_t, typename rng_t>
requires std::uniform_random_bit_generator<rng_t>
requires requires (point_t p) {
requires std::is_floating_point<decltype(p.x)>::value;
requires std::is_floating_point<decltype(p.y)>::value;
} && std::uniform_random_bit_generator<rng_t>
std::vector<point_t> poisson_disc_sampling(const config& conf, rng_t& rng) {
const auto cell_size = conf.min_dist / std::numbers::sqrt2_v<float_t>;
const auto grid_w = static_cast<integral_t>(std::ceil(conf.w / cell_size));
Expand Down

0 comments on commit bebcc68

Please sign in to comment.