Mercurial > hg > dmlib
annotate tests/vecmattest.c @ 1432:a9516570cc26
Improve build, so that we can build the tools and tests with minimal
depencies (e.g. without libSDL linking when possible.) And this also on
Win32 MinGW.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 22 Nov 2017 01:33:21 +0200 |
parents | e2ac08228a0f |
children | d8a83582f78f |
rev | line source |
---|---|
1432
a9516570cc26
Improve build, so that we can build the tools and tests with minimal
Matti Hamalainen <ccr@tnsp.org>
parents:
651
diff
changeset
|
1 #include "dmtool.h" |
0 | 2 #include "dmlib.h" |
3 #include "dmvecmat.h" | |
4 | |
5 void printTest(const char *test, int expected, int result) | |
6 { | |
7 fprintf(stderr, "Test '%s': %s\n", test, | |
8 expected == result ? "OK" : "FAILED!"); | |
9 } | |
10 | |
11 #define tst(X, R) printTest(# X, (X), (R)) | |
12 | |
13 | |
14 void dm_vector_fprintf(FILE *f, const char *name, DMVector *v) | |
15 { | |
16 if (name != NULL) | |
17 fprintf(f, "%s=", name); | |
18 | |
19 fprintf(f, "[<%1.3f, %1.3f, %1.3f>=%1.3f]", v->x, v->y, v->z, dm_vector_length(v)); | |
20 | |
21 if (name != NULL) | |
22 fprintf(f, "\n"); | |
23 } | |
24 | |
25 | |
26 void dm_vector_printf(const char *name, DMVector *v) | |
27 { | |
28 dm_vector_fprintf(stdout, name, v); | |
29 } | |
30 | |
31 | |
32 void dm_matrix_fprintf(FILE *f, const char *name, DMMatrix *mat) | |
33 { | |
34 int i, j, k, pad = 0; | |
35 char *tmp = NULL; | |
36 | |
37 if (name != NULL) | |
38 { | |
39 tmp = dm_strdup_printf("%s=", name); | |
40 pad = strlen(tmp); | |
41 } | |
42 | |
43 for (i = 0; i < DM_MATRIX_SIZE; i++) | |
44 { | |
45 if (i == 1) | |
46 fputs(tmp, f); | |
47 else | |
48 for (k = 0; k < pad; k++) | |
49 fputc(' ', f); | |
50 | |
51 fprintf(f, "["); | |
52 for (j = 0; j < DM_MATRIX_SIZE; j++) | |
53 fprintf(f, "% 8.3f%s", mat->m[i][j], j < DM_MATRIX_SIZE - 1 ? " " : ""); | |
54 | |
55 fprintf(f, "]\n"); | |
56 } | |
57 } | |
58 | |
59 | |
60 void dm_matrix_printf(const char *name, DMMatrix *mat) | |
61 { | |
62 dm_matrix_fprintf(stdout, name, mat); | |
63 } | |
64 | |
65 | |
66 int main(int argc, char *argv[]) | |
67 { | |
239
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
68 DMVector a = { -5, 1, 17, 0 }, b = { 1, 2, 0.5, 0 }; |
0 | 69 DMMatrix m; |
70 | |
71 (void) argc; | |
72 (void) argv; | |
73 | |
74 dm_vector_printf("a", &a); | |
75 dm_vector_printf("b", &a); | |
76 | |
77 dm_matrix_rot_a(&m, 0.5, 0.9, 0.1); | |
78 dm_matrix_printf("m", &m); | |
79 | |
80 dm_vector_mul_by_mat(&b, &a, &m); | |
81 | |
82 dm_vector_printf("nb", &b); | |
83 | |
84 return 0; | |
85 } |