diff options
-rw-r--r-- | test/morpher/trianglemap.c | 57 |
1 files changed, 23 insertions, 34 deletions
diff --git a/test/morpher/trianglemap.c b/test/morpher/trianglemap.c index a00f89b..986e406 100644 --- a/test/morpher/trianglemap.c +++ b/test/morpher/trianglemap.c | |||
@@ -13,54 +13,44 @@ static inline bool vertices_equals(CartesianMapping maps[], | |||
13 | return mappings_equals(maps[0], m1) && mappings_equals(maps[1], m2) && mappings_equals(maps[2], m3); | 13 | return mappings_equals(maps[0], m1) && mappings_equals(maps[1], m2) && mappings_equals(maps[2], m3); |
14 | } | 14 | } |
15 | 15 | ||
16 | /* | 16 | static void test_trianglemap_to() { |
17 | * - | 17 | CartesianMapping A = m(50, 0), B = m(0, 100), C = m(100, 100), D = m(0, 200), E = m(100, 200); |
18 | * / \ t | 18 | TriangleMap *t = trianglemap_create(A, B, C); |
19 | * --- | 19 | TriangleMap *r = trianglemap_create(C, B, E); |
20 | * l |\| r | 20 | TriangleMap *l = trianglemap_create(B, D, E); |
21 | * --- | ||
22 | */ | ||
23 | static inline TriangleMap *create_test_map() { | ||
24 | TriangleMap *t = trianglemap_create(m(50, 0), m(0, 100), m(100, 100)); | ||
25 | TriangleMap *r = trianglemap_create(m(100, 100), m(0, 100), m(100, 200)); | ||
26 | TriangleMap *l = trianglemap_create(m(0, 100), m(0, 200), m(100, 200)); | ||
27 | trianglemap_set_neighbors(t, NULL, r, NULL, r); | 21 | trianglemap_set_neighbors(t, NULL, r, NULL, r); |
28 | trianglemap_set_neighbors(r, t, l, NULL, l); | 22 | trianglemap_set_neighbors(r, t, l, NULL, l); |
29 | trianglemap_set_neighbors(l, NULL, NULL, r, NULL); | 23 | trianglemap_set_neighbors(l, NULL, NULL, r, NULL); |
30 | return t; | ||
31 | } | ||
32 | |||
33 | static inline void free_map(TriangleMap *t) { | ||
34 | while (t != NULL) t = trianglemap_destroy(t); | ||
35 | } | ||
36 | |||
37 | static void test_triangle_to() { | ||
38 | TriangleMap *t = create_test_map(); | ||
39 | 24 | ||
40 | assert(trianglemap_to(t, v(80, 80)) == t); | 25 | assert(trianglemap_to(t, v(80, 80)) == t); |
41 | assert(trianglemap_to(t, v(0, 0)) == t->neighbors[0]); | 26 | assert(trianglemap_to(t, v(0, 0)) == t->neighbors[0]); |
42 | assert(trianglemap_to(t, v(55, 170)) == t->neighbors[1]); | 27 | assert(trianglemap_to(t, v(55, 170)) == t->neighbors[1]); |
43 | 28 | ||
44 | free_map(t); | 29 | while (t != NULL) t = trianglemap_destroy(t); |
45 | } | 30 | } |
46 | 31 | ||
47 | static void test_triangle_split() { | 32 | static void test_trianglemap_split() { |
48 | TriangleMap *t = create_test_map(); | 33 | CartesianMapping A = m(50, 0), B = m(0, 100), C = m(100, 100), D = m(0, 200), E = m(100, 200), F = m(90, 110); |
49 | TriangleMap *r = t->next; | 34 | TriangleMap *t = trianglemap_create(A, B, C); |
50 | TriangleMap *l = r->next; | 35 | TriangleMap *r = trianglemap_create(C, B, E); |
51 | TriangleMap *r1 = trianglemap_split(r, m(90, 110)); | 36 | TriangleMap *l = trianglemap_create(B, D, E); |
37 | trianglemap_set_neighbors(t, NULL, r, NULL, r); | ||
38 | trianglemap_set_neighbors(r, t, l, NULL, l); | ||
39 | trianglemap_set_neighbors(l, NULL, NULL, r, NULL); | ||
40 | |||
41 | TriangleMap *r1 = trianglemap_split(r, F); | ||
52 | TriangleMap *r2 = r1->next; | 42 | TriangleMap *r2 = r1->next; |
53 | TriangleMap *r3 = r2->next; | 43 | TriangleMap *r3 = r2->next; |
54 | 44 | ||
55 | assert(vertices_equals(r1->vertices, m(100, 100), m(0, 100), m(90, 110))); | 45 | assert(vertices_equals(r1->vertices, C, B, F)); |
56 | assert(vertices_equals(r2->vertices, m(0, 100), m(100, 200), m(90, 110))); | 46 | assert(vertices_equals(r2->vertices, B, E, F)); |
57 | assert(vertices_equals(r3->vertices, m(100, 200), m(100, 100), m(90, 110))); | 47 | assert(vertices_equals(r3->vertices, E, C, F)); |
58 | assert(neighbors_equals(r1->neighbors, t, r2, r3)); | 48 | assert(neighbors_equals(r1->neighbors, t, r2, r3)); |
59 | assert(neighbors_equals(r2->neighbors, l, r3, r1)); | 49 | assert(neighbors_equals(r2->neighbors, l, r3, r1)); |
60 | assert(neighbors_equals(r3->neighbors, NULL, r1, r2)); | 50 | assert(neighbors_equals(r3->neighbors, NULL, r1, r2)); |
61 | assert(t->neighbors[1] == r1 && l->neighbors[2] == r2); | 51 | assert(t->neighbors[1] == r1 && l->neighbors[2] == r2); |
62 | 52 | ||
63 | free_map(t); | 53 | while (t != NULL) t = trianglemap_destroy(t); |
64 | } | 54 | } |
65 | 55 | ||
66 | static void test_trianglemap_propagate_delaunay() { | 56 | static void test_trianglemap_propagate_delaunay() { |
@@ -83,13 +73,12 @@ static void test_trianglemap_propagate_delaunay() { | |||
83 | assert(quadrilateral_is_delaunay(triangle, triangle->neighbors[neighbor_index])); | 73 | assert(quadrilateral_is_delaunay(triangle, triangle->neighbors[neighbor_index])); |
84 | } | 74 | } |
85 | 75 | ||
86 | trianglemap_destroy(l); | 76 | while (l != NULL) l = trianglemap_destroy(l); |
87 | trianglemap_destroy(r); | ||
88 | } | 77 | } |
89 | 78 | ||
90 | int main(int argc, char **argv) { | 79 | int main(int argc, char **argv) { |
91 | test_triangle_to(); | 80 | test_trianglemap_to(); |
92 | test_triangle_split(); | 81 | test_trianglemap_split(); |
93 | test_trianglemap_propagate_delaunay(); | 82 | test_trianglemap_propagate_delaunay(); |
94 | return 0; | 83 | return 0; |
95 | } | 84 | } |