libsxbp  v0.27
Experimental generation of 2D spiralling lines based on input binary data.
Functions
solve.h File Reference

This compilation unit provides functions for calculating the length of all lines in a spiral such that the length of each line is at least 1 and none of them collide. More...

#include <stdint.h>
#include "saxbospiral.h"
Include dependency graph for solve.h:

Go to the source code of this file.

Functions

sxbp_status_t sxbp_resize_spiral (sxbp_spiral_t *spiral, uint32_t index, sxbp_length_t length, sxbp_length_t perfection_threshold)
 Attempt to set a given line of a spiral to a given length. More...
 
sxbp_status_t sxbp_plot_spiral (sxbp_spiral_t *spiral, sxbp_length_t perfection_threshold, uint32_t max_line, void(*progress_callback)(sxbp_spiral_t *spiral, uint32_t latest_line, uint32_t target_line, void *progress_callback_user_data), void *progress_callback_user_data)
 Solve the given incomplete spiral such that each line has a length of at least 1 unit. More...
 

Detailed Description

This compilation unit provides functions for calculating the length of all lines in a spiral such that the length of each line is at least 1 and none of them collide.

Author
Joshua Saxby <joshua.a.saxby+TNOPLuc8vM==.com
Date
2016, 2017

Function Documentation

sxbp_status_t sxbp_plot_spiral ( sxbp_spiral_t *  spiral,
sxbp_length_t  perfection_threshold,
uint32_t  max_line,
void(*)(sxbp_spiral_t *spiral, uint32_t latest_line, uint32_t target_line, void *progress_callback_user_data)  progress_callback,
void *  progress_callback_user_data 
)

Solve the given incomplete spiral such that each line has a length of at least 1 unit.

This function will solve a given spiral such that each line of the spiral has a length of at least 1 unit, and that none of these lines collide with one another. The algorithm operates recursively on the spiral to achieve this. A spiral at any point of completion may be passed to this function and the algorithm will solve just the parts which have yet to be solved if partial work has already been done to solve the spiral. A progress callback may optionally also be given to the function. If this is non-NULL, then this callback function will be called every time the algorithm finds the length of another line. Once this function has finished, it may be possible to render the spiral.

Parameters
[in,out]spiralThe spiral to solve. Function operates on the spiral in-place (mutating operation).
perfection_thresholdThe maximum line length of colliding lines at which aggressive optimisations are allowed (or 0 to disable these optimisations completely).
max_lineThe index of the highest line to plot to.
progress_callbackAn optional function pointer to use as a callback which gets called every time a new line length is successfully found. The signature of the callback should be like so:
1 void callback_name(
2  sxbp_spiral_t* spiral, uint32_t latest_line, uint32_t target_line,
3  void* progress_callback_user_data
4 )
If a callback is not required, this argument should be NULL. The callback takes four arguments, where:
  • spiral is the spiral being solved
  • latest_line is the index of the latest line to be solved
  • target_line is the index of the highest line that will be solved
  • progress_callback_user_data is a void pointer to some data of user-defined type.
progress_callback_user_dataAn optional void pointer to a user-defined type, useful for passing context or state to the callback function if it needs to do something requiring file handles or some other context handle. This argument should be NULL if not required.
Warning
No assumptions are made on the data type of the variable to which progress_callback_user_data points to (if any). Hence, responsibility for type-safety is placed on the user.
Returns
SXBP_OPERATION_OK on success.
Any other failure code on failure.
Warning
This function may take a VERY VERY LONG TIME to run. This means on a magnitude of anything from minutes to months.
Note
Asserts:
  • That spiral->lines is not NULL
Todo:
Improve the efficiency of this function so that it runs much faster.
sxbp_status_t sxbp_resize_spiral ( sxbp_spiral_t *  spiral,
uint32_t  index,
sxbp_length_t  length,
sxbp_length_t  perfection_threshold 
)

Attempt to set a given line of a spiral to a given length.

If this cannot be done because the operation would cause a line collision, then backtrack and re-size the previous lines recursively until a non-colliding conclusion can be found.

Parameters
[in,out]spiralThe spiral for which the line should be resized.
indexThe index of the line to resize.
lengthThe length to attempt to resize the line to.
perfection_thresholdThe maximum line length of colliding lines at which aggressive optimisations are allowed (or 0 to disable these optimisations completely).
Returns
SXBP_OPERATION_OK on success.
Any other failure code on failure.
Note
Asserts:
  • That spiral->lines is not NULL
  • That index is less than spiral->size
Deprecated:
This function is deprecated from the public interface and will be removed from the public interface in a future version (v1.0 at the latest).