summaryrefslogtreecommitdiffstatsci
path: root/tests/random_rects.c
blob: 34f351204b35328e89ce5d489e2febc388cceabb (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "test.h"

/*void drawRandomRect (VkvgContext ctx) {
	float w = (float)test_width;
	float h = (float)test_height;
	randomize_color(ctx);

	float z = truncf((0.5f*w*rand()/RAND_MAX)+1.f);
	float v = truncf((0.5f*w*rand()/RAND_MAX)+1.f);
	float x = truncf((w-z)*rand()/RAND_MAX);
	float y = truncf((h-v)*rand()/RAND_MAX);

	vkvg_rectangle(ctx, x, y, z, v);
}*/
static vkvg_fill_rule_t fill_rule = VKVG_FILL_RULE_NON_ZERO;
static float line_width = 5.f;
static float shape_size = 0.1f;

void _shape_fill(shape_t shape){
	vkvg_surface_clear(surf);
	VkvgContext ctx = vkvg_create(surf);
	vkvg_set_fill_rule(ctx, fill_rule);
	for (uint32_t i=0; i<test_size; i++) {
		draw_random_shape(ctx, shape, shape_size);
		vkvg_fill(ctx);
	}
	vkvg_destroy(ctx);
}
void _shape_stroke(shape_t shape){
	vkvg_surface_clear (surf);
	VkvgContext ctx = vkvg_create(surf);
	vkvg_set_line_width (ctx, line_width);
	vkvg_set_fill_rule(ctx, fill_rule);
	for (uint32_t i=0; i<test_size; i++) {
		draw_random_shape(ctx, shape, shape_size);
		vkvg_stroke (ctx);
	}
	vkvg_destroy(ctx);
}
void _shape_fill_stroke(shape_t shape){
	vkvg_surface_clear(surf);
	VkvgContext ctx = vkvg_create(surf);
	vkvg_set_line_width (ctx, line_width);
	vkvg_set_fill_rule(ctx, fill_rule);
	for (uint32_t i=0; i<test_size; i++) {
		draw_random_shape(ctx, shape, shape_size);
		vkvg_fill_preserve(ctx);
		vkvg_stroke(ctx);
	}
	vkvg_destroy(ctx);
}

void rectangles_fill () {
	_shape_fill(SHAPE_RECTANGLE);
}
void rectangles_stroke () {
	_shape_stroke(SHAPE_RECTANGLE);
}
void rectangles_fill_stroke () {
	_shape_fill_stroke(SHAPE_RECTANGLE);
}
void rounded_rects_fill () {
	_shape_fill(SHAPE_ROUNDED_RECTANGLE);
}
void rounded_rects_stroke () {
	_shape_stroke(SHAPE_ROUNDED_RECTANGLE);
}
void rounded_rects_fill_stroke () {
	_shape_fill_stroke(SHAPE_ROUNDED_RECTANGLE);
}
void circles_fill () {
	_shape_fill(SHAPE_CIRCLE);
}
void circles_stroke () {
	_shape_stroke(SHAPE_CIRCLE);
}
void circles_fill_stroke () {
	_shape_fill_stroke(SHAPE_CIRCLE);
}
void stars_fill () {
	_shape_fill(SHAPE_STAR);
}
void stars_stroke () {
	_shape_stroke(SHAPE_STAR);
}
void stars_fill_stroke () {
	_shape_fill_stroke(SHAPE_STAR);
}
void random_fill () {
	_shape_fill(SHAPE_RANDOM);
}
void random_stroke () {
	_shape_stroke(SHAPE_RANDOM);
}
void random_fill_stroke () {
	_shape_fill_stroke(SHAPE_RANDOM);
}

int main(int argc, char *argv[]) {

	PERFORM_TEST (rectangles_fill, argc, argv);
	PERFORM_TEST (rectangles_stroke, argc, argv);
	PERFORM_TEST (rectangles_fill_stroke, argc, argv);

	PERFORM_TEST (rounded_rects_fill, argc, argv);
	PERFORM_TEST (rounded_rects_stroke, argc, argv);
	PERFORM_TEST (rounded_rects_fill_stroke, argc, argv);

	PERFORM_TEST (circles_fill, argc, argv);
	PERFORM_TEST (circles_stroke, argc, argv);
	PERFORM_TEST (circles_fill_stroke, argc, argv);

	PERFORM_TEST (stars_fill, argc, argv);
	PERFORM_TEST (stars_stroke, argc, argv);
	PERFORM_TEST (stars_fill_stroke, argc, argv);

	PERFORM_TEST (random_fill, argc, argv);
	PERFORM_TEST (random_stroke, argc, argv);
	PERFORM_TEST (random_fill_stroke, argc, argv);

	return 0;
}