@@ -240,14 +240,23 @@ status_t resize_spiral(
240240/*
241241 * given a pointer to a spiral spiral for which the length of all its lines are
242242 * not yet known, a perfection threshold (-1 for no perfection, or otherwise
243- * the maximmum line length at which to allow aggressive optimisation) and the
244- * index of the highest line to plot to, calculate the length needed for each
245- * line in the spiral up to this index (to avoid line overlap) and store these
246- * in a the spiral struct that is pointed to by the pointer
243+ * the maximmum line length at which to allow aggressive optimisation), the
244+ * index of the highest line to plot to and a pointer to a callback function,
245+ * calculate the length needed for each line in the spiral up to this index
246+ * (to avoid line overlap) and store these in a the spiral struct that is
247+ * pointed to by the pointer
248+ * the function pointer can be NULL, if it is not then it will be called every
249+ * time a new line of the spiral is solved. The function should be of return
250+ * type void and take three arguments: a pointer to a spiral_t struct, an
251+ * integer specifying the index of the latest solved line and an integer
252+ * specifying the index of the highest line that will be solved.
247253 * returns a status struct (used for error information)
248254 */
249255status_t plot_spiral (
250- spiral_t * spiral , int perfection_threshold , uint64_t max_line
256+ spiral_t * spiral , int perfection_threshold , uint64_t max_line ,
257+ void (* progress_callback )(
258+ spiral_t * spiral , uint64_t latest_line , uint64_t target_line
259+ )
251260) {
252261 // set up result status
253262 status_t result = {{0 , 0 , 0 }, 0 };
@@ -260,6 +269,10 @@ status_t plot_spiral(
260269 if (result .diagnostic != OPERATION_OK ) {
261270 return result ;
262271 }
272+ // call callback if given
273+ if (progress_callback != NULL ) {
274+ progress_callback (spiral , i , max_index );
275+ }
263276 }
264277 // all ok
265278 result .diagnostic = OPERATION_OK ;
0 commit comments