/* See LICENSE file for copyright and license details. */
#ifndef LIBRIFUNKTIONSTECKENSNITTSGLYFRASTERISERINGSPROGRAMBIBLIOTEKET_H
#define LIBRIFUNKTIONSTECKENSNITTSGLYFRASTERISERINGSPROGRAMBIBLIOTEKET_H
/* ^ < ^ < ^ ^ > ^ */
/* r t g r p b lib */
#include <stddef.h>
/**
* Object that the library draws on, is converted to
* an ink-level image using the `rtgrpblib_fill_shapes`
* function. This object also contain drawing
* configurations.
*/
typedef struct rtgrpblib_raster RTGRPBLIB_RASTER;
/**
* Create a buffer that the library can use for drawing
*
* @param width The width of the buffer
* @param height The height of the buffer
* @return Drawing buffer, which can be deallocated with (3),
* or `NULL` on failure
*
* @throws EINVAL `width` or `height` is zero
* @throws ENOMEM Cannot allocate enough memory
*
* @seealso rtgrpblib_reset_raster
*/
RTGRPBLIB_RASTER *rtgrpblib_create_raster(size_t width, size_t height);
/**
* Reshape and clear a drawing buffer
*
* @param raster The buffer to reshape and clear
* @param width The new width of the buffer
* @param height The new height of the buffer
* @return 0 on success, -1 on failure
*
* @throws EINVAL `width` or `height` is zero
* @throws EINVAL The buffers new area size exceeds its original area size
*/
int rtgrpblib_reset_raster(RTGRPBLIB_RASTER *raster, size_t width, size_t height);
/**
* Reconfigure a drawing buffer with a new draftness value
*
* When drawing a curve, the size of each step the library
* takes will be proportional to the draftness value, but
* will also depend on other factors. Doubling the draftness
* value with halve (disregarind overheads) the time it takes
* to draw any given curve.
*
* @param raster The drawing buffer to reconfigure
* @param draftness The new draftness value, must be positive
*/
void rtgrpblib_set_draftness(RTGRPBLIB_RASTER *raster, double draftness);
/**
* Create an image of the drawings applied to a drawing buffer
*
* All drawn shapes must be closed
*
* Shapes that are drawn in the same angular direction add to
* each other, shapes that are drawn in opposite angular
* directions subtract from each other
*
* @param image Output buffer, need not be initialised, but
* shall have an allocation size of `rowsize`
* multiplied by the height of `raster` and
* by `sizeof(double)`
* @param rowsize The number of elements in `image` per row,
* must be at least the width of `raster`
* @param raster The drawing buffer
*
* @seealso rtgrpblib_reset_raster
*/
void rtgrpblib_fill_shapes(double *restrict image, size_t rowsize, const RTGRPBLIB_RASTER *raster);
/**
* Draw a line between two points
*
* @param raster The drawing buffer
* @param x1, y1 The starting point
* @param x2, y2 The end point
*/
void rtgrpblib_draw_linear_bezier(RTGRPBLIB_RASTER *restrict raster,
double x1, double y1,
double x2, double y2);
/**
* Draw a quadratic bézier curve
*
* @param raster The drawing buffer
* @param x1, y1 The starting point
* @param x2, y2 The control point
* @param x3, y3 The end point
*/
void rtgrpblib_draw_quadratic_bezier(RTGRPBLIB_RASTER *restrict raster,
double x1, double y1,
double x2, double y2,
double x3, double y3);
/**
* Draw a cubic bézier curve
*
* @param raster The drawing buffer
* @param x1, y1 The starting point
* @param x2, y2 The first control point
* @param x3, y3 The second control point
* @param x4, y4 The end point
*/
void rtgrpblib_draw_cubic_bezier(RTGRPBLIB_RASTER *restrict raster, /* needed for OpenType */
double x1, double y1,
double x2, double y2,
double x3, double y3,
double x4, double y4);
/**
* Draw a cricular arc
*
* @param raster The drawing buffer
* @param x0, y0 The midpoint of the ellipse
* @param semiwidth Half the width of the ellipse
* @param semiheight Half the height of the ellipse
* @param start The angular starting point of the arc, in radians
* @param end The angular end point of the arc, in radians
*/
void rtgrpblib_draw_circular_arc(RTGRPBLIB_RASTER *restrict raster, /* needed for outline stoking */
double x0, double y0,
double semiwidth, double semiheight,
double start, double end);
#endif