@@ -35,9 +35,9 @@ extern "C" {
35
35
&& !defined(TPH_POISSON_FLOOR )
36
36
#define TPH_POISSON_REAL_TYPE float
37
37
#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_))
41
41
#endif
42
42
43
43
typedef TPH_POISSON_REAL_TYPE tph_poisson_real ;
@@ -53,13 +53,21 @@ typedef void (*tph_poisson_free_fn)(void *ptr, ptrdiff_t size, void *ctx);
53
53
54
54
#pragma pack(push, 1)
55
55
56
+ /**
57
+ * Allocator interface. Must provide malloc and free functions.
58
+ * Context is optional and may be NULL.
59
+ */
56
60
struct tph_poisson_allocator_
57
61
{
58
62
tph_poisson_malloc_fn malloc ;
59
63
tph_poisson_free_fn free ;
60
64
void * ctx ;
61
65
};
62
66
67
+ /**
68
+ * Parameters used when creating a Poisson disk sampling.
69
+ * bounds_min/max are assumed to point to arrays of length ndims.
70
+ */
63
71
struct tph_poisson_args_
64
72
{
65
73
const tph_poisson_real * bounds_min ;
@@ -70,6 +78,11 @@ struct tph_poisson_args_
70
78
uint32_t max_sample_attempts ;
71
79
};
72
80
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
+ */
73
86
struct tph_poisson_sampling_
74
87
{
75
88
tph_poisson_sampling_internal * internal ;
@@ -108,7 +121,7 @@ struct tph_poisson_sampling_
108
121
* - an invalid allocator is provided.
109
122
* TPH_POISSON_OVERFLOW - The number of samples exceeds the maximum number.
110
123
*
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
112
125
* using the tph_poisson_destroy function.
113
126
*
114
127
* @param sampling Sampling to store samples.
@@ -166,12 +179,12 @@ extern const tph_poisson_real *tph_poisson_get_samples(const tph_poisson_samplin
166
179
167
180
#ifndef TPH_POISSON_MEMCPY
168
181
#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_ ))
170
183
#endif
171
184
172
185
#ifndef TPH_POISSON_MEMSET
173
186
#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_ ))
175
188
#endif
176
189
177
190
/*
@@ -186,8 +199,8 @@ extern const tph_poisson_real *tph_poisson_get_samples(const tph_poisson_samplin
186
199
#endif
187
200
#if !defined(TPH_POISSON_MALLOC ) && !defined(TPH_POISSON_FREE )
188
201
#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_))
191
204
#endif
192
205
/* clang-format on */
193
206
@@ -207,6 +220,13 @@ static TPH_POISSON_INLINE void tph_poisson_free(void *ptr, ptrdiff_t size, void
207
220
TPH_POISSON_FREE (ptr );
208
221
}
209
222
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
+
210
230
/**
211
231
* @brief Returns a pointer aligned to the provided alignment. The address pointed
212
232
* 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
223
243
return (void * )(((uintptr_t )ptr + (alignment - 1 )) & ~(alignment - 1 ));
224
244
}
225
245
226
- static tph_poisson_allocator tph_poisson_default_alloc = { tph_poisson_malloc ,
227
- tph_poisson_free ,
228
- /*.ctx=*/ NULL };
229
-
230
246
/*
231
247
* PSEUDO-RANDOM NUMBER GENERATION
232
248
*/
@@ -250,7 +266,7 @@ static uint64_t tph_poisson_splitmix64(tph_poisson_splitmix64_state *state)
250
266
return result ^ (result >> 31 );
251
267
}
252
268
253
- typedef struct
269
+ typedef struct tph_poisson_xoshiro256p_state_
254
270
{
255
271
uint64_t s [4 ];
256
272
} tph_poisson_xoshiro256p_state ;
0 commit comments