Mercurial > hg > dmlib
annotate tests/vecmattest.c @ 2298:b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
dmGrowBufConstCopyOffsSize().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 04 Jul 2019 10:54:16 +0300 |
parents | 186cf6a7d634 |
children |
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 | |
1433 | 5 |
0 | 6 void printTest(const char *test, int expected, int result) |
7 { | |
8 fprintf(stderr, "Test '%s': %s\n", test, | |
9 expected == result ? "OK" : "FAILED!"); | |
10 } | |
11 | |
12 #define tst(X, R) printTest(# X, (X), (R)) | |
13 | |
14 | |
15 void dm_vector_fprintf(FILE *f, const char *name, DMVector *v) | |
16 { | |
17 if (name != NULL) | |
18 fprintf(f, "%s=", name); | |
19 | |
20 fprintf(f, "[<%1.3f, %1.3f, %1.3f>=%1.3f]", v->x, v->y, v->z, dm_vector_length(v)); | |
21 | |
22 if (name != NULL) | |
23 fprintf(f, "\n"); | |
24 } | |
25 | |
26 | |
27 void dm_vector_printf(const char *name, DMVector *v) | |
28 { | |
29 dm_vector_fprintf(stdout, name, v); | |
30 } | |
31 | |
32 | |
33 void dm_matrix_fprintf(FILE *f, const char *name, DMMatrix *mat) | |
34 { | |
35 int i, j, k, pad = 0; | |
36 char *tmp = NULL; | |
37 | |
38 if (name != NULL) | |
39 { | |
40 tmp = dm_strdup_printf("%s=", name); | |
41 pad = strlen(tmp); | |
42 } | |
43 | |
44 for (i = 0; i < DM_MATRIX_SIZE; i++) | |
45 { | |
46 if (i == 1) | |
47 fputs(tmp, f); | |
48 else | |
49 for (k = 0; k < pad; k++) | |
50 fputc(' ', f); | |
51 | |
52 fprintf(f, "["); | |
53 for (j = 0; j < DM_MATRIX_SIZE; j++) | |
54 fprintf(f, "% 8.3f%s", mat->m[i][j], j < DM_MATRIX_SIZE - 1 ? " " : ""); | |
2046 | 55 |
0 | 56 fprintf(f, "]\n"); |
57 } | |
58 } | |
59 | |
60 | |
61 void dm_matrix_printf(const char *name, DMMatrix *mat) | |
62 { | |
63 dm_matrix_fprintf(stdout, name, mat); | |
64 } | |
65 | |
66 | |
67 int main(int argc, char *argv[]) | |
68 { | |
239
07c4f1a7ddc6
Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
69 DMVector a = { -5, 1, 17, 0 }, b = { 1, 2, 0.5, 0 }; |
0 | 70 DMMatrix m; |
71 | |
72 (void) argc; | |
2046 | 73 (void) argv; |
0 | 74 |
75 dm_vector_printf("a", &a); | |
76 dm_vector_printf("b", &a); | |
2046 | 77 |
0 | 78 dm_matrix_rot_a(&m, 0.5, 0.9, 0.1); |
79 dm_matrix_printf("m", &m); | |
80 | |
81 dm_vector_mul_by_mat(&b, &a, &m); | |
2046 | 82 |
0 | 83 dm_vector_printf("nb", &b); |
2046 | 84 |
0 | 85 return 0; |
86 } |