Skip to content

Commit 48a9aaf

Browse files
committed
Some small optimisations in sxbp_figure_collides_with_callback()
Once I figured out the source of my woes and corrected it, I've since been able to refactor that function nicer
1 parent 44c7ad8 commit 48a9aaf

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

sxbp/refine_figure_grow_from_start.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,24 +135,30 @@ static bool sxbp_figure_collides_with_callback(
135135
// cast void pointer to a pointer to our context structure
136136
figure_collides_with_context* callback_data =
137137
(figure_collides_with_context*)data;
138-
/*
139-
* if a pixel would be plotted at a location that isn't NULL, then stop and
140-
* set collider to point to the location that would have been plotted to
141-
* --this is the line that would be collided with
142-
*/
143-
if (callback_data->map->cells[location.x][location.y] != NULL) {
144-
// the thing we collided with is the pointer at this location, store it!
145-
*callback_data->collider = callback_data->map->cells[location.x][location.y];
146-
// halt walking early by returning false
138+
// if the line's ID is greater than the max line we want, we can quit NOW
139+
if (line->id > callback_data->max_line) {
147140
return false;
148141
} else {
149142
/*
150-
* otherwise, we haven't collided yet so mark the cell with a pointer to
151-
* the current line
143+
* if a pixel would be plotted at a location that isn't NULL, then stop
144+
* and set collider to point to the location that would have been
145+
* plotted to --this is the line that would be collided with
152146
*/
153-
callback_data->map->cells[location.x][location.y] = line;
154-
// only continue if it's not the last line
155-
return !(line->id > callback_data->max_line);
147+
if (callback_data->map->cells[location.x][location.y] != NULL) {
148+
// the line we collided with is the pointer in this cell, store it!
149+
*callback_data->collider =
150+
callback_data->map->cells[location.x][location.y];
151+
// halt walking early by returning false
152+
return false;
153+
} else {
154+
/*
155+
* otherwise, we haven't collided yet so mark the cell with a
156+
* pointer to the current line
157+
*/
158+
callback_data->map->cells[location.x][location.y] = line;
159+
// tell sxbp_walk_figure() that we want to continue!
160+
return true;
161+
}
156162
}
157163
}
158164

0 commit comments

Comments
 (0)