Skip to content

Commit d5105b2

Browse files
committed
Fixed bug where wrong type used for perfection threshold argument
This was previously `int` and has been changed to `sxbp_length_t` The functionality of the function has been modified accordingly - -1 used to be the value used to request 'no perfection' but this is now 0. It makes sense because the perfection threshold works by setting a number at or below which potentially imperfect optimisations are allowed (based on collider line length). If this is set to 0, they can never happen. Fixes #117
1 parent 0508bdd commit d5105b2

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

saxbospiral/solve.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static bool spiral_collides(sxbp_spiral_t* spiral, size_t index) {
110110
/*
111111
* given a spiral struct that is known to collide, the index of the 'last'
112112
* segment in the spiral (i.e. the one that was found to be colliding) and a
113-
* perfection threshold (-1 for no perfection, or otherwise the maximmum line
113+
* perfection threshold (0 for no perfection, or otherwise the maximmum line
114114
* length at which to allow aggressive optimisation), return a suggested length
115115
* to set the segment before this line to.
116116
*
@@ -131,7 +131,7 @@ static bool spiral_collides(sxbp_spiral_t* spiral, size_t index) {
131131
* - That index is less than spiral.size
132132
*/
133133
static sxbp_length_t suggest_resize(
134-
sxbp_spiral_t spiral, size_t index, int perfection_threshold
134+
sxbp_spiral_t spiral, size_t index, sxbp_length_t perfection_threshold
135135
) {
136136
// preconditional assertions
137137
assert(spiral.lines != NULL);
@@ -140,7 +140,7 @@ static sxbp_length_t suggest_resize(
140140
// check if collides or not, return same size if no collision
141141
if(spiral.collides) {
142142
/*
143-
* if the perfection threshold is -1, then we can just use our
143+
* if the perfection threshold is 0, then we can just use our
144144
* suggestion, as perfection is disabled.
145145
* otherwise, if the colliding line's length is greater than our
146146
* perfection threshold, we cannot make any intelligent suggestions on
@@ -149,8 +149,8 @@ static sxbp_length_t suggest_resize(
149149
* the previous line's length +1
150150
*/
151151
if(
152-
(perfection_threshold != -1) &&
153-
(spiral.lines[index].length > (sxbp_length_t)perfection_threshold)
152+
(perfection_threshold > 0) &&
153+
(spiral.lines[index].length > perfection_threshold)
154154
) {
155155
return spiral.lines[index - 1].length + 1;
156156
}
@@ -207,7 +207,7 @@ static sxbp_length_t suggest_resize(
207207

208208
/*
209209
* given a pointer to a spiral struct, the index of one of it's lines and a
210-
* target length to set that line to and a perfection threshold (-1 for no
210+
* target length to set that line to and a perfection threshold (0 for no
211211
* perfection, or otherwise the maximmum line length at which to allow
212212
* aggressive optimisation) attempt to set the target line to that length,
213213
* back-tracking to resize the previous line if it collides.
@@ -219,7 +219,7 @@ static sxbp_length_t suggest_resize(
219219
*/
220220
sxbp_status_t sxbp_resize_spiral(
221221
sxbp_spiral_t* spiral, uint64_t index, sxbp_length_t length,
222-
int perfection_threshold
222+
sxbp_length_t perfection_threshold
223223
) {
224224
// preconditional assertions
225225
assert(spiral->lines != NULL);
@@ -282,7 +282,7 @@ sxbp_status_t sxbp_resize_spiral(
282282

283283
/*
284284
* given a pointer to a spiral spiral for which the length of all its lines are
285-
* not yet known, a perfection threshold (-1 for no perfection, or otherwise
285+
* not yet known, a perfection threshold (0 for no perfection, or otherwise
286286
* the maximmum line length at which to allow aggressive optimisation), the
287287
* index of the highest line to plot to, a pointer to a callback function and
288288
* a void pointer to a user-defined data struct for use with the callback,
@@ -303,7 +303,7 @@ sxbp_status_t sxbp_resize_spiral(
303303
* - That spiral->lines is not NULL
304304
*/
305305
sxbp_status_t sxbp_plot_spiral(
306-
sxbp_spiral_t* spiral, int perfection_threshold, uint64_t max_line,
306+
sxbp_spiral_t* spiral, sxbp_length_t perfection_threshold, uint64_t max_line,
307307
void(* progress_callback)(
308308
sxbp_spiral_t* spiral, uint64_t latest_line, uint64_t target_line,
309309
void* progress_callback_user_data

saxbospiral/solve.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extern "C"{
3636

3737
/*
3838
* given a pointer to a spiral struct, the index of one of it's lines and a
39-
* target length to set that line to and a perfection threshold (-1 for no
39+
* target length to set that line to and a perfection threshold (0 for no
4040
* perfection, or otherwise the maximmum line length at which to allow
4141
* aggressive optimisation) attempt to set the target line to that length,
4242
* back-tracking to resize the previous line if it collides.
@@ -48,12 +48,12 @@ extern "C"{
4848
*/
4949
sxbp_status_t sxbp_resize_spiral(
5050
sxbp_spiral_t* spiral, uint64_t index, sxbp_length_t length,
51-
int perfection_threshold
51+
sxbp_length_t perfection_threshold
5252
);
5353

5454
/*
5555
* given a pointer to a spiral spiral for which the length of all its lines are
56-
* not yet known, a perfection threshold (-1 for no perfection, or otherwise
56+
* not yet known, a perfection threshold (0 for no perfection, or otherwise
5757
* the maximmum line length at which to allow aggressive optimisation), the
5858
* index of the highest line to plot to, a pointer to a callback function and
5959
* a void pointer to a user-defined data struct for use with the callback,
@@ -74,7 +74,7 @@ sxbp_status_t sxbp_resize_spiral(
7474
* - That spiral->lines is not NULL
7575
*/
7676
sxbp_status_t sxbp_plot_spiral(
77-
sxbp_spiral_t* spiral, int perfection_threshold, uint64_t max_line,
77+
sxbp_spiral_t* spiral, sxbp_length_t perfection_threshold, uint64_t max_line,
7878
void(* progress_callback)(
7979
sxbp_spiral_t* spiral, uint64_t latest_line, uint64_t target_line,
8080
void* progress_callback_user_data

0 commit comments

Comments
 (0)