24 std::uniform_real_distribution<float> dis(-1.0f, 1.0f);
26 for (
size_t i = 0; i < T::size; i++)
39 template<AnyVec T, AnyVec U>
42 std::uniform_real_distribution<float> dis(0.0f, 1.0f);
44 for (
size_t i = 0; i < T::size; i++)
45 p[i] =
static_cast<typename T::type
>(from[i] + dis(gen) * (to[i] - from[i]));
58 template<AnyVec T, Primitive U>
61 std::uniform_real_distribution<float> dis(0.0f, 1.0f);
63 for (
size_t i = 0; i < T::size; i++)
64 p[i] =
static_cast<typename T::type
>(from + dis(gen) * (to - from));
106 template<Primitive U>
108 template<Primitive U>
110 template<Primitive U>
119 template<Primitive U>
121 template<Primitive U>
123 template<Primitive U>
132 template<Primitive U>
134 template<Primitive U>
136 template<Primitive U>
139 namespace poisson_disc
154 inline std::vector<U>
PoissonDisc(std::mt19937 &gen, U
const &from, U
const &to,
float min_distance,
size_t max_attempts = 30) noexcept
156 std::vector<U> result;
157 std::uniform_real_distribution<float> dist(0.0f, 1.0f);
158 std::vector<U> active;
160 active.push_back(result.back());
161 while (!active.empty())
163 std::uniform_int_distribution<size_t> dist2(0, active.size() - 1);
164 size_t index = dist2(gen);
165 U point = active[index];
167 for (
size_t i = 0; i < max_attempts; ++i)
170 if (new_point.x < from.x || new_point.x > to.x || new_point.y < from.y || new_point.y > to.y)
173 for (
auto const &p : result)
175 if (
distance(p, new_point) < min_distance)
184 result.push_back(new_point);
185 active.push_back(new_point);
191 active.erase(active.begin() + index);
154 inline std::vector<U>
PoissonDisc(std::mt19937 &gen, U
const &from, U
const &to,
float min_distance,
size_t max_attempts = 30) noexcept {
…}
141 namespace _detail {
…}
206 inline std::vector<vec2>
Generate(std::mt19937 &gen,
vec2 const &from,
vec2 const &to,
float min_distance,
size_t max_attempts = 30) noexcept
206 inline std::vector<vec2>
Generate(std::mt19937 &gen,
vec2 const &from,
vec2 const &to,
float min_distance,
size_t max_attempts = 30) noexcept {
…}
139 namespace poisson_disc {
…}
Provides various mathematical utilities, vector operations, and custom hash specializations.
vec< T::size, std::remove_const_t< typename T::type > > UnitRandom(std::mt19937 &gen) noexcept
Generates a unit vector with random direction.
vec< T::size, std::remove_const_t< typename T::type > > RandomVector(std::mt19937 &gen, U const &from, U const &to) noexcept
Generates a random vector between two other vectors.
std::vector< U > PoissonDisc(std::mt19937 &gen, U const &from, U const &to, float min_distance, size_t max_attempts=30) noexcept
Generates a set of points distributed according to Poisson Disk Sampling.
std::vector< vec2 > Generate(std::mt19937 &gen, vec2 const &from, vec2 const &to, float min_distance, size_t max_attempts=30) noexcept
Wrapper function for generating Poisson Disk sampled 2D points.
vec4 RandomVector4(std::mt19937 &gen, U const &from, U const &to) noexcept
ivec4 RandomIVector4(std::mt19937 &gen, U const &from, U const &to) noexcept
uivec3 RandomUVector3(std::mt19937 &gen, U const &from, U const &to) noexcept
vec2 RandomDirection2(std::mt19937 &gen) noexcept
Generates a random 2D float direction.
vec3 RandomVector3(std::mt19937 &gen, U const &from, U const &to) noexcept
ivec3 RandomIVector3(std::mt19937 &gen, U const &from, U const &to) noexcept
vec2 RandomVector2(std::mt19937 &gen, U const &from, U const &to) noexcept
vec4 RandomDirection4(std::mt19937 &gen) noexcept
Generates a random 4D float direction.
uivec2 RandomUVector2(std::mt19937 &gen, U const &from, U const &to) noexcept
dvec3 RandomDVector3(std::mt19937 &gen, U const &from, U const &to) noexcept
dvec4 RandomDVector4(std::mt19937 &gen, U const &from, U const &to) noexcept
dvec2 RandomDVector2(std::mt19937 &gen, U const &from, U const &to) noexcept
uivec4 RandomUVector4(std::mt19937 &gen, U const &from, U const &to) noexcept
ivec2 RandomIVector2(std::mt19937 &gen, U const &from, U const &to) noexcept
vec3 RandomDirection3(std::mt19937 &gen) noexcept
Generates a random 3D float direction.
constexpr std::remove_const_t< typename T::type > distance(T const &left, T const &right) noexcept
Compute the distance between two vectors.
vec< 4, unsigned int > uivec4
constexpr qua< T > normalize(qua< T > const &q) noexcept
Normalizes a quaternion.
vec< 3, unsigned int > uivec3
Definition of the mathematical vector with fixed size L and type T