Skip to content

Commit 3a5b1f2

Browse files
committed
minor interface tweaks
1 parent 1af28bf commit 3a5b1f2

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

spawn2d.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static inline void rotate_point(float* x, float* y, float angle)
5555
}
5656

5757
//-------------------------------------------------------------------------------------------------------------------
58-
float spawn2d_compute_area(spawn2d_shape* shape)
58+
float spawn2d_compute_area(const spawn2d_shape* shape)
5959
{
6060
switch(shape->type)
6161
{
@@ -78,7 +78,7 @@ float spawn2d_compute_area(spawn2d_shape* shape)
7878
}
7979

8080
//-------------------------------------------------------------------------------------------------------------------
81-
bool spawn2d_point_in(spawn2d_shape* shape, float x, float y)
81+
bool spawn2d_point_in(const spawn2d_shape* shape, float x, float y)
8282
{
8383
switch(shape->type)
8484
{
@@ -120,7 +120,7 @@ bool spawn2d_point_in(spawn2d_shape* shape, float x, float y)
120120
}
121121

122122
//-------------------------------------------------------------------------------------------------------------------
123-
void spawn2d_sample_area(spawn2d_shape* shape, uint32_t* seed, float* x, float* y)
123+
void spawn2d_sample_area(const spawn2d_shape* shape, uint32_t* seed, float* x, float* y)
124124
{
125125
switch(shape->type)
126126
{

spawn2d.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ typedef struct spawn2d_shape
6161
//-------------------------------------------------------------------------------------------------------------------
6262
typedef struct spawn2d_context
6363
{
64-
spawn2d_shape* shapes;
64+
const spawn2d_shape* shapes;
6565
uint32_t num_shapes;
66-
spawn2d_shape* exclusions;
66+
const spawn2d_shape* exclusions;
6767
uint32_t num_exclusions;
68-
float* ctrl_points;
68+
const float* ctrl_points;
6969
uint32_t num_ctrl_points;
7070
float width;
7171
uint32_t num_tries_max;
@@ -109,23 +109,26 @@ uint32_t spawn2d_generate_in_shapes(spawn2d_context* ctx, float* points, uint32_
109109
// Returns the actual number of points spawned
110110
uint32_t spawn2d_generate_along_spline(spawn2d_context* ctx, float* points, uint32_t num_points);
111111

112+
113+
114+
112115
//-------------------------------------------------------------------------------------------------------------------
113116
// Internal helper functions (optional, not part of public API)
114117
//-------------------------------------------------------------------------------------------------------------------
115118

116119
//-------------------------------------------------------------------------------------------------------------------
117120
// Returns the area of the shape
118-
float spawn2d_compute_area(spawn2d_shape* shape);
121+
float spawn2d_compute_area(const spawn2d_shape* shape);
119122

120123
//-------------------------------------------------------------------------------------------------------------------
121124
// Returns true if the point is inside the shape
122-
bool spawn2d_point_in(spawn2d_shape* shape, float x, float y);
125+
bool spawn2d_point_in(const spawn2d_shape* shape, float x, float y);
123126

124127
//-------------------------------------------------------------------------------------------------------------------
125128
// Uniform area sampling
126129
// [seed] Random generator seed, cannot be zero, will be changed by this function
127130
// [x, y] Pointer to point coordinates
128-
void spawn2d_sample_area(spawn2d_shape* shape, uint32_t* seed, float* x, float* y);
131+
void spawn2d_sample_area(const spawn2d_shape* shape, uint32_t* seed, float* x, float* y);
129132

130133
//-------------------------------------------------------------------------------------------------------------------
131134
// Returns a random float in [0; 1[

test/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ TEST test_generate_generate_in_shapes(void)
235235
//-------------------------------------------------------------------------------------------------------------------
236236
TEST test_generate_along_spline(void)
237237
{
238-
uint32_t seed = 0xdeadbeef;
238+
uint32_t seed = 0xdeadbeef;
239239
spawn2d_context ctx =
240240
{
241241
.ctrl_points = (float[]){500.f, 300.f, 600.f, 500.f, 800.f, 700.f, 1100.f, 700.f, 1200.f, 500.f,

0 commit comments

Comments
 (0)