Skip to content

Commit 40b2c62

Browse files
authored
Merge pull request #95 from saxbophone/josh/93-resume-from-saved-progress
Fix a bug where plot_spiral() would always start from line 0
2 parents 212c64d + 3522c2e commit 40b2c62

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

saxbospiral/solve.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ sxbp_status_t sxbp_resize_spiral(
243243
* index of the highest line to plot to and a pointer to a callback function,
244244
* calculate the length needed for each line in the spiral up to this index
245245
* (to avoid line overlap) and store these in a the spiral struct that is
246-
* pointed to by the pointer
246+
* pointed to by the pointer. If the spiral has some lines already solved, the
247+
* algorithm will start at the next unsolved line.
247248
* the function pointer can be NULL, if it is not then it will be called every
248249
* time a new line of the spiral is solved. The function should be of return
249250
* type void and take three arguments: a pointer to a spiral_t struct, an
@@ -261,8 +262,8 @@ sxbp_status_t sxbp_plot_spiral(
261262
sxbp_status_t result = {{0, 0, 0}, 0};
262263
// get index of highest line to plot
263264
uint64_t max_index = (max_line > spiral->size) ? spiral->size : max_line;
264-
// calculate the length of each line
265-
for(size_t i = 0; i < max_index; i++) {
265+
// calculate the length of each line within range solved_count -> max_index
266+
for(size_t i = spiral->solved_count; i < max_index; i++) {
266267
result = sxbp_resize_spiral(spiral, i, 1, perfection_threshold);
267268
// catch and return error if any
268269
if(result.diagnostic != SXBP_OPERATION_OK) {

saxbospiral/solve.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ sxbp_status_t sxbp_resize_spiral(
3030
* index of the highest line to plot to and a pointer to a callback function,
3131
* calculate the length needed for each line in the spiral up to this index
3232
* (to avoid line overlap) and store these in a the spiral struct that is
33-
* pointed to by the pointer
33+
* pointed to by the pointer. If the spiral has some lines already solved, the
34+
* algorithm will start at the next unsolved line.
3435
* the function pointer can be NULL, if it is not then it will be called every
3536
* time a new line of the spiral is solved. The function should be of return
3637
* type void and take three arguments: a pointer to a spiral_t struct, an

0 commit comments

Comments
 (0)