@@ -35,9 +35,9 @@ extern "C" {
3535 && !defined(TPH_POISSON_FLOOR )
3636#define TPH_POISSON_REAL_TYPE float
3737#include <math.h>
38- #define TPH_POISSON_SQRT sqrtf
39- #define TPH_POISSON_CEIL ceilf
40- #define TPH_POISSON_FLOOR floorf
38+ #define TPH_POISSON_SQRT ( _X_ ) sqrtf((_X_))
39+ #define TPH_POISSON_CEIL ( _X_ ) ceilf((_X_))
40+ #define TPH_POISSON_FLOOR ( _X_ ) floorf((_X_))
4141#endif
4242
4343typedef TPH_POISSON_REAL_TYPE tph_poisson_real ;
@@ -53,13 +53,21 @@ typedef void (*tph_poisson_free_fn)(void *ptr, ptrdiff_t size, void *ctx);
5353
5454#pragma pack(push, 1)
5555
56+ /**
57+ * Allocator interface. Must provide malloc and free functions.
58+ * Context is optional and may be NULL.
59+ */
5660struct tph_poisson_allocator_
5761{
5862 tph_poisson_malloc_fn malloc ;
5963 tph_poisson_free_fn free ;
6064 void * ctx ;
6165};
6266
67+ /**
68+ * Parameters used when creating a Poisson disk sampling.
69+ * bounds_min/max are assumed to point to arrays of length ndims.
70+ */
6371struct tph_poisson_args_
6472{
6573 const tph_poisson_real * bounds_min ;
@@ -70,6 +78,11 @@ struct tph_poisson_args_
7078 uint32_t max_sample_attempts ;
7179};
7280
81+ /**
82+ * Result of creating a Poisson disk sampling.
83+ * Use with tph_poisson_get_samples to retrieve sample positions.
84+ * Memory must be freed after use by calling tph_poisson_destroy.
85+ */
7386struct tph_poisson_sampling_
7487{
7588 tph_poisson_sampling_internal * internal ;
@@ -108,7 +121,7 @@ struct tph_poisson_sampling_
108121 * - an invalid allocator is provided.
109122 * TPH_POISSON_OVERFLOW - The number of samples exceeds the maximum number.
110123 *
111- * Note that when an error is returned the sampling does not need to be destroyed
124+ * Note that when an error is returned the sampling doesn't need to be destroyed
112125 * using the tph_poisson_destroy function.
113126 *
114127 * @param sampling Sampling to store samples.
@@ -166,12 +179,12 @@ extern const tph_poisson_real *tph_poisson_get_samples(const tph_poisson_samplin
166179
167180#ifndef TPH_POISSON_MEMCPY
168181#include <string.h>
169- #define TPH_POISSON_MEMCPY (dst , src , n ) memcpy((dst ), (src ), (n ))
182+ #define TPH_POISSON_MEMCPY (_DST_ , _SRC_ , _N_ ) memcpy((_DST_ ), (_SRC_ ), (_N_ ))
170183#endif
171184
172185#ifndef TPH_POISSON_MEMSET
173186#include <string.h>
174- #define TPH_POISSON_MEMSET (s , c , n ) memset((s ), (c ), (n ))
187+ #define TPH_POISSON_MEMSET (_S_ , _C_ , _N_ ) memset((_S_ ), (_C_ ), (_N_ ))
175188#endif
176189
177190/*
@@ -186,8 +199,8 @@ extern const tph_poisson_real *tph_poisson_get_samples(const tph_poisson_samplin
186199#endif
187200#if !defined(TPH_POISSON_MALLOC ) && !defined(TPH_POISSON_FREE )
188201#include <stdlib.h>
189- #define TPH_POISSON_MALLOC malloc
190- #define TPH_POISSON_FREE free
202+ #define TPH_POISSON_MALLOC ( _SIZE_ ) malloc((_SIZE_))
203+ #define TPH_POISSON_FREE ( _PTR_ ) free((_PTR_))
191204#endif
192205/* clang-format on */
193206
@@ -207,6 +220,13 @@ static TPH_POISSON_INLINE void tph_poisson_free(void *ptr, ptrdiff_t size, void
207220 TPH_POISSON_FREE (ptr );
208221}
209222
223+ /**
224+ * Default allocator used when no custom allocator is provided.
225+ */
226+ static tph_poisson_allocator tph_poisson_default_alloc = { tph_poisson_malloc ,
227+ tph_poisson_free ,
228+ /*.ctx=*/ NULL };
229+
210230/**
211231 * @brief Returns a pointer aligned to the provided alignment. The address pointed
212232 * to is a multiple of the alignment. Assumes that alignment is a power of two (which
@@ -223,10 +243,6 @@ static TPH_POISSON_INLINE void *tph_poisson_align(void *const ptr, const size_t
223243 return (void * )(((uintptr_t )ptr + (alignment - 1 )) & ~(alignment - 1 ));
224244}
225245
226- static tph_poisson_allocator tph_poisson_default_alloc = { tph_poisson_malloc ,
227- tph_poisson_free ,
228- /*.ctx=*/ NULL };
229-
230246/*
231247 * PSEUDO-RANDOM NUMBER GENERATION
232248 */
@@ -250,7 +266,7 @@ static uint64_t tph_poisson_splitmix64(tph_poisson_splitmix64_state *state)
250266 return result ^ (result >> 31 );
251267}
252268
253- typedef struct
269+ typedef struct tph_poisson_xoshiro256p_state_
254270{
255271 uint64_t s [4 ];
256272} tph_poisson_xoshiro256p_state ;
0 commit comments