-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
53 lines (45 loc) · 1.22 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef UTILS_H
#define UTILS_H
#include <stdlib.h>
#include <string.h>
#include <cairo.h>
#include <ctype.h>
#define ASSERT_MSG(expression, msg, code)\
if (!(expression)) {\
fprintf(stderr, "Assertion error at %s:%d: %s\n", __FILE__, __LINE__, (msg));\
exit(code);\
}
typedef struct {
double x, y;
} point_t;
/**
* Computes the middle point between a and b and stores it in dest.
*
* Returns:
* 0 in case of success
* 1 if dest == NULL.
*/
int point_middle(point_t a, point_t b, point_t *dest);
/**
* Converts the standard RGBA format #AABBCCDD to Cairo's format in float
* values, such that 0 <= f <= 1 for every float number f representing a
* channel value.
*
* Returns:
* 0 on success;
* 1 if rgbain is an invalid string
*/
int std_rgba_to_cairo_rgba(char *rgbain, float rgbaout[]);
void cairo_triangle(cairo_t*, point_t a, point_t b, point_t c);
/**
* Draws a Sierpinski triangle with depth depth to cr.
*/
void cairo_sierpinski_triangle(
cairo_t *cr, point_t a, point_t b, point_t c, int depth
);
/**
* Automates the process of picking arbitrary points a, b and c choosing
* them at aesthetically pleasing coordinates.
*/
void cairo_sierpinski_triangle_auto(cairo_t *cr, int depth);
#endif // UTILS_H