Mercurial > games > semicongine
annotate tests/test_matrix.nim @ 13:a571db114152
add: vector/matrix modules, tests, nim config script
author | Sam <sam@basx.dev> |
---|---|
date | Wed, 28 Dec 2022 11:42:21 +0700 |
parents | |
children | 617c6dcddbe2 |
rev | line source |
---|---|
13
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
1 import random |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
2 import math |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
3 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
4 import vector |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
5 import matrix |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
6 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
7 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
8 proc echoInfo(v: Vec) = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
9 echo v |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
10 echo " Length: ", v.length |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
11 echo " Normlized: ", v.normalized |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
12 echo " negated: ", -v |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
13 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
14 proc echoAdd[T, U](v1: T, v2: U) = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
15 echo v1, " + ", v2, " = ", v1 + v2 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
16 proc echoSub[T, U](v1: T, v2: U) = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
17 echo v1, " - ", v2, " = ", v1 - v2 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
18 proc echoMul[T, U](v1: T, v2: U) = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
19 echo v1, " * ", v2, " = ", v1 * v2 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
20 proc echoDiv[T, U](v1: T, v2: U) = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
21 echo v1, " / ", v2, " = ", v1 / v2 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
22 proc echoDot[T, U](v1: T, v2: U) = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
23 echo v1, " o ", v2, " = ", v1.dot(v2) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
24 proc echoCross[T, U](v1: T, v2: U) = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
25 echo v1, " x ", v2, " = ", v1.cross(v2) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
26 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
27 proc randVec2I(): auto = newVec2(rand(1 .. 10), rand(1 .. 10)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
28 proc randVec2F(): auto = newVec2(rand(10'f) + 0.01, rand(10'f) + 0.01) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
29 proc randVec3I(): auto = newVec3(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
30 proc randVec3F(): auto = newVec3(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
31 proc randVec4I(): auto = newVec4(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
32 proc randVec4F(): auto = newVec4(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
33 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
34 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
35 proc testVector() = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
36 echoInfo(randVec2I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
37 echoInfo(randVec2F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
38 echoInfo(randVec3I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
39 echoInfo(randVec3F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
40 echoInfo(randVec4I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
41 echoInfo(randVec4F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
42 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
43 # test math operations vector-vector |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
44 echoAdd(randVec2I(), randVec2I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
45 echoAdd(randVec2F(), randVec2F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
46 echoAdd(randVec3I(), randVec3I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
47 echoAdd(randVec3F(), randVec3F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
48 echoAdd(randVec4I(), randVec4I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
49 echoAdd(randVec4F(), randVec4F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
50 echoSub(randVec2I(), randVec2I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
51 echoSub(randVec2F(), randVec2F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
52 echoSub(randVec3I(), randVec3I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
53 echoSub(randVec3F(), randVec3F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
54 echoSub(randVec4I(), randVec4I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
55 echoSub(randVec4F(), randVec4F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
56 echoMul(randVec2I(), randVec2I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
57 echoMul(randVec2F(), randVec2F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
58 echoMul(randVec3I(), randVec3I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
59 echoMul(randVec3F(), randVec3F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
60 echoMul(randVec4I(), randVec4I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
61 echoMul(randVec4F(), randVec4F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
62 echoDiv(randVec2I(), randVec2I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
63 echoDiv(randVec2F(), randVec2F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
64 echoDiv(randVec3I(), randVec3I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
65 echoDiv(randVec3F(), randVec3F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
66 echoDiv(randVec4I(), randVec4I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
67 echoDiv(randVec4F(), randVec4F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
68 echoDot(randVec2I(), randVec2I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
69 echoDot(randVec2F(), randVec2F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
70 echoDot(randVec3I(), randVec3I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
71 echoDot(randVec3F(), randVec3F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
72 echoDot(randVec4I(), randVec4I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
73 echoDot(randVec4F(), randVec4F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
74 echoCross(randVec3I(), randVec3I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
75 echoCross(randVec3F(), randVec3F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
76 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
77 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
78 # test math operations vector-scalar |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
79 echoAdd(randVec2I(), rand(1 .. 10)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
80 echoAdd(randVec2F(), rand(10'f)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
81 echoAdd(randVec3I(), rand(1 .. 10)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
82 echoAdd(randVec3F(), rand(10'f)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
83 echoAdd(randVec4I(), rand(1 .. 10)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
84 echoAdd(randVec4F(), rand(10'f)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
85 echoSub(randVec2I(), rand(1 .. 10)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
86 echoSub(randVec2F(), rand(10'f)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
87 echoSub(randVec3I(), rand(1 .. 10)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
88 echoSub(randVec3F(), rand(10'f)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
89 echoSub(randVec4I(), rand(1 .. 10)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
90 echoSub(randVec4F(), rand(10'f)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
91 echoMul(randVec2I(), rand(1 .. 10)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
92 echoMul(randVec2F(), rand(10'f)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
93 echoMul(randVec3I(), rand(1 .. 10)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
94 echoMul(randVec3F(), rand(10'f)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
95 echoMul(randVec4I(), rand(1 .. 10)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
96 echoMul(randVec4F(), rand(10'f)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
97 echoDiv(randVec2I(), rand(1 .. 10)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
98 echoDiv(randVec2F(), rand(10'f)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
99 echoDiv(randVec3I(), rand(1 .. 10)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
100 echoDiv(randVec3F(), rand(10'f)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
101 echoDiv(randVec4I(), rand(1 .. 10)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
102 echoDiv(randVec4F(), rand(10'f)) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
103 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
104 # test math operations scalar-vector |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
105 echoAdd(rand(1 .. 10), randVec2I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
106 echoAdd(rand(10'f), randVec2F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
107 echoAdd(rand(1 .. 10), randVec3I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
108 echoAdd(rand(10'f), randVec3F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
109 echoAdd(rand(1 .. 10), randVec4I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
110 echoAdd(rand(10'f), randVec4F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
111 echoSub(rand(1 .. 10), randVec2I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
112 echoSub(rand(10'f), randVec2F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
113 echoSub(rand(1 .. 10), randVec3I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
114 echoSub(rand(10'f), randVec3F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
115 echoSub(rand(1 .. 10), randVec4I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
116 echoSub(rand(10'f), randVec4F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
117 echoMul(rand(1 .. 10), randVec2I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
118 echoMul(rand(10'f), randVec2F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
119 echoMul(rand(1 .. 10), randVec3I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
120 echoMul(rand(10'f), randVec3F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
121 echoMul(rand(1 .. 10), randVec4I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
122 echoMul(rand(10'f), randVec4F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
123 echoDiv(rand(1 .. 10), randVec2I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
124 echoDiv(rand(10'f), randVec2F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
125 echoDiv(rand(1 .. 10), randVec3I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
126 echoDiv(rand(10'f), randVec3F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
127 echoDiv(rand(1 .. 10), randVec4I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
128 echoDiv(rand(10'f), randVec4F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
129 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
130 # test attribute syntax sugar |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
131 echo "float2int ", to[int](randVec2F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
132 echo "int2float ", to[float](randVec2I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
133 echo "float2int ", to[int](randVec3F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
134 echo "int2float ", to[float](randVec3I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
135 echo "float2int ", to[int](randVec3F()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
136 echo "int2float ", to[float](randVec3I()) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
137 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
138 echo "V2I.xx: ", randVec2I().xx |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
139 echo "V2I.yx: ", randVec2I().xy |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
140 echo "V2F.xx: ", randVec2F().xx |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
141 echo "V2F.yx: ", randVec2F().yx |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
142 echo "V2I.rr: ", randVec2I().rr |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
143 echo "V2I.gr: ", randVec2I().gr |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
144 echo "V2F.rr: ", randVec2F().rr |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
145 echo "V2F.gr: ", randVec2F().gr |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
146 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
147 echo "V3I.yyy: ", randVec3I().yyy |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
148 echo "V3I.yxz: ", randVec3I().xyz |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
149 echo "V3F.yyy: ", randVec3F().yyy |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
150 echo "V3F.yxz: ", randVec3F().yxz |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
151 echo "V3I.ggg: ", randVec3I().ggg |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
152 echo "V3I.grb: ", randVec3I().grb |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
153 echo "V3F.ggg: ", randVec3F().ggg |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
154 echo "V3F.grb: ", randVec3F().grb |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
155 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
156 echo "V4I.zzzz: ", randVec4I().zzzz |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
157 echo "V4I.yxzw: ", randVec4I().xyzw |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
158 echo "V4F.zzzz: ", randVec4F().zzzz |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
159 echo "V4F.yxzw: ", randVec4F().yxzw |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
160 echo "V4I.bbbb: ", randVec4I().bbbb |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
161 echo "V4I.grba: ", randVec4I().grba |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
162 echo "V4F.bbbb: ", randVec4F().bbbb |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
163 echo "V4F.grba: ", randVec4F().grba |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
164 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
165 echo "X: ", X |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
166 echo "Y: ", Y |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
167 echo "Z: ", Z |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
168 echo "X: ", Xi |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
169 echo "Y: ", Yi |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
170 echo "Z: ", Zi |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
171 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
172 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
173 template withAllIntegerMats(stuff: untyped) = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
174 stuff(Mat22[int32]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
175 stuff(Mat23[int32]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
176 stuff(Mat32[int32]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
177 stuff(Mat33[int32]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
178 stuff(Mat34[int32]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
179 stuff(Mat43[int32]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
180 stuff(Mat44[int32]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
181 stuff(Mat22[int64]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
182 stuff(Mat23[int64]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
183 stuff(Mat32[int64]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
184 stuff(Mat33[int64]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
185 stuff(Mat34[int64]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
186 stuff(Mat43[int64]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
187 stuff(Mat44[int64]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
188 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
189 template withAllFloatMats(stuff: untyped) = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
190 stuff(Mat22[float32]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
191 stuff(Mat23[float32]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
192 stuff(Mat32[float32]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
193 stuff(Mat33[float32]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
194 stuff(Mat34[float32]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
195 stuff(Mat43[float32]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
196 stuff(Mat44[float32]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
197 stuff(Mat22[float64]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
198 stuff(Mat23[float64]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
199 stuff(Mat32[float64]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
200 stuff(Mat33[float64]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
201 stuff(Mat34[float64]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
202 stuff(Mat43[float64]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
203 stuff(Mat44[float64]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
204 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
205 template withAllMats(stuff: untyped) = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
206 stuff(Mat22[int]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
207 stuff(Mat23[int]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
208 stuff(Mat32[int]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
209 stuff(Mat33[int]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
210 stuff(Mat34[int]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
211 stuff(Mat43[int]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
212 stuff(Mat44[int]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
213 stuff(Mat22[float]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
214 stuff(Mat23[float]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
215 stuff(Mat32[float]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
216 stuff(Mat33[float]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
217 stuff(Mat34[float]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
218 stuff(Mat43[float]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
219 stuff(Mat44[float]) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
220 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
221 template testTranspose(t: typedesc) = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
222 echo "testTranspose: ", t |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
223 let m = t().randomized() |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
224 assert m == m.transposed().transposed() |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
225 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
226 template testAssignI(t: typedesc) = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
227 echo "testAssignI: ", t |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
228 var m = t() |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
229 for i in 0 ..< t.data.len: |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
230 m[rand(0 ..< m.rowCount), rand(0 ..< m.columnCount)] = rand(0'i32 .. 100'i32) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
231 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
232 template testAssignF(t: typedesc) = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
233 echo "testAssignF: ", t |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
234 var m = t() |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
235 for i in 0 ..< t.data.len: |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
236 m[rand(0 ..< m.rowCount), rand(0 ..< m.columnCount)] = rand(100'f) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
237 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
238 template testRowCols(t: typedesc) = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
239 echo "testRowCols: ", t |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
240 var m = t().randomized() |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
241 for i in 0 ..< m.rowCount: |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
242 echo m.row(i) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
243 for i in 0 ..< m.columnCount: |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
244 echo m.col(i) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
245 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
246 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
247 proc testMatrix() = |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
248 withAllMats(testTranspose) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
249 withAllIntegerMats(testAssignI) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
250 withAllFloatMats(testAssignF) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
251 withAllMats(testRowCols) |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
252 |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
253 randomize() |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
254 testVector() |
a571db114152
add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff
changeset
|
255 testMatrix() |