diff options
Diffstat (limited to 'test/common/geom.c')
-rw-r--r-- | test/common/geom.c | 21 |
1 files changed, 21 insertions, 0 deletions
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 | } | ||