Skip to content

Commit 86498b7

Browse files
committed
Move bugfix logic to a function where it makes more sense to be
Moved it from resize_spiral() to suggest_resize()
1 parent ffb4cd3 commit 86498b7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

saxbospiral/solve.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ static length_t
9494
suggest_resize(spiral_t spiral, size_t index) {
9595
// check if collides or not, return same size if no collision
9696
if(spiral.collides != -1) {
97+
/*
98+
* if the colliding line's length is greater than 1, we cannot make any
99+
* intelligent suggestions on the length to extend the previous line to
100+
* (without the high likelihood of creating a line that wastes space),
101+
* so we just return the previous line's length +1
102+
*/
103+
if(spiral.lines[index].length > 1) {
104+
return spiral.lines[index - 1].length + 1;
105+
}
97106
// store the 'previous' and 'rigid' lines.
98107
line_t p = spiral.lines[index - 1];
99108
line_t r = spiral.lines[spiral.collides];
@@ -176,11 +185,7 @@ resize_spiral(spiral_t spiral, size_t index, length_t length) {
176185
* function to get the suggested length to resize the previous
177186
* segment to
178187
*/
179-
if(current_length == 1) {
180-
current_length = suggest_resize(spiral, current_index);
181-
} else {
182-
current_length = spiral.lines[current_index - 1].length + 1;
183-
}
188+
current_length = suggest_resize(spiral, current_index);
184189
current_index--;
185190
} else if(current_index != index) {
186191
/*

0 commit comments

Comments
 (0)