diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/blender/blender.c | 29 | ||||
-rw-r--r-- | test/common/geom.c | 21 | ||||
-rw-r--r-- | test/painter/color.c | 14 | ||||
-rw-r--r-- | test/painter/rasterizer.c | 27 |
4 files changed, 62 insertions, 29 deletions
diff --git a/test/blender/blender.c b/test/blender/blender.c deleted file mode 100644 index f42322f..0000000 --- a/test/blender/blender.c +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | #include "blender/blender.h" | ||
2 | #include <assert.h> | ||
3 | |||
4 | static void test_canvas_blending() { | ||
5 | Morphing *morphing; | ||
6 | Canvas origin, target, result; | ||
7 | CartesianVector sample_point = {13, 17}; | ||
8 | |||
9 | morphing = morphing_create(64, 64); | ||
10 | canvas_init(&origin, 64, 64); | ||
11 | canvas_init(&target, 64, 64); | ||
12 | canvas_init(&result, 64, 64); | ||
13 | |||
14 | canvas_set_pixel(&origin, sample_point, (Color) {{0xFF, 0xED, 0x00, 0x00}}); | ||
15 | canvas_set_pixel(&target, sample_point, (Color) {{0x00, 0x47, 0xAB, 0x00}}); | ||
16 | |||
17 | blender_blend_canvas(&result, &origin, &target, morphing, 0.125); | ||
18 | assert(color_equals(canvas_get_pixel(&result, sample_point), (Color) {{0xEE, 0xDF, 0x3C, 0x00}})); | ||
19 | |||
20 | canvas_free(&result); | ||
21 | canvas_free(&target); | ||
22 | canvas_free(&origin); | ||
23 | morphing_destroy(morphing); | ||
24 | } | ||
25 | |||
26 | int main(int argc, char **argv) { | ||
27 | test_canvas_blending(); | ||
28 | return 0; | ||
29 | } | ||
diff --git a/test/common/geom.c b/test/common/geom.c new file mode 100644 index 0000000..f05e0a1 --- /dev/null +++ b/test/common/geom.c | |||
@@ -0,0 +1,21 @@ | |||
1 | #include "common/geom.h" | ||
2 | #include <assert.h> | ||
3 | |||
4 | static void test_square_area() { | ||
5 | assert(square_area(v(0, 0), v(10, 0), v(10, 10)) == 100); | ||
6 | assert(square_area(v(0, 0), v(0, 10), v(10, 10)) == -100); | ||
7 | } | ||
8 | |||
9 | static void test_cartesian_barycentric_vectors() { | ||
10 | Triangle t = {{v(0, 0), v(10, 0), v(10, 10)}}; | ||
11 | CartesianVector c = v(3, 2); | ||
12 | BarycentricVector bv = cartesian_to_barycentric(t, c); | ||
13 | assert(barycentric_vector_equals(bv, b(0.7, 0.1))); | ||
14 | assert(vector_equals(barycentric_to_cartesian(t, bv), c)); | ||
15 | } | ||
16 | |||
17 | int main(int argc, char **argv) { | ||
18 | test_square_area(); | ||
19 | test_cartesian_barycentric_vectors(); | ||
20 | return 0; | ||
21 | } | ||
diff --git a/test/painter/color.c b/test/painter/color.c new file mode 100644 index 0000000..bdfe9b3 --- /dev/null +++ b/test/painter/color.c | |||
@@ -0,0 +1,14 @@ | |||
1 | #include "painter/color.h" | ||
2 | #include <assert.h> | ||
3 | |||
4 | static void test_color_blend() { | ||
5 | Color a = {{1, 10, 100, 200}}, b = {{100, 1, 200, 10}}; | ||
6 | assert(color_equals(color_blend(a, b, TIME_ORIGIN), a)); | ||
7 | assert(color_equals(color_blend(a, b, TIME_UNIT), b)); | ||
8 | assert(color_equals(color_blend(a, b, 0.25), (Color) {{50, 9, 132, 173}})); | ||
9 | } | ||
10 | |||
11 | int main(int argc, char **argv) { | ||
12 | test_color_blend(); | ||
13 | return 0; | ||
14 | } | ||
diff --git a/test/painter/rasterizer.c b/test/painter/rasterizer.c new file mode 100644 index 0000000..99a70b4 --- /dev/null +++ b/test/painter/rasterizer.c | |||
@@ -0,0 +1,27 @@ | |||
1 | #include "painter/rasterizer.h" | ||
2 | #include <assert.h> | ||
3 | |||
4 | static void test_rasterize() { | ||
5 | Morphing *morphing; | ||
6 | Canvas *origin, *target, *result; | ||
7 | CartesianVector sample_point = {13, 17}; | ||
8 | |||
9 | morphing = morphing_create(100, 100); | ||
10 | origin = canvas_create(100, 100); | ||
11 | target = canvas_create(100, 100); | ||
12 | canvas_set_pixel(origin, sample_point, (Color) {{0xFF, 0x00, 0xED, 0xFF}}); | ||
13 | canvas_set_pixel(target, sample_point, (Color) {{0xFF, 0xAB, 0x47, 0x00}}); | ||
14 | |||
15 | result = rasterize(origin, target, morphing, 0.125); | ||
16 | assert(color_equals(canvas_get_pixel(result, sample_point), (Color) {{0xFF, 0x3C, 0xDF, 0xEF}})); | ||
17 | |||
18 | canvas_destroy(result); | ||
19 | canvas_destroy(target); | ||
20 | canvas_destroy(origin); | ||
21 | morphing_destroy(morphing); | ||
22 | } | ||
23 | |||
24 | int main(int argc, char **argv) { | ||
25 | test_rasterize(); | ||
26 | return 0; | ||
27 | } | ||