Mercurial > games > semicongine
comparison tests/test_matrix.nim @ 1136:71315636ba82
did: refactor naming in tons of places
author | sam <sam@basx.dev> |
---|---|
date | Tue, 04 Jun 2024 16:51:50 +0700 |
parents | 67081fbaf636 |
children |
comparison
equal
deleted
inserted
replaced
1135:74957cbf589b | 1136:71315636ba82 |
---|---|
21 proc echoDot[T, U](v1: T, v2: U) = | 21 proc echoDot[T, U](v1: T, v2: U) = |
22 echo v1, " o ", v2, " = ", v1.dot(v2) | 22 echo v1, " o ", v2, " = ", v1.dot(v2) |
23 proc echoCross[T, U](v1: T, v2: U) = | 23 proc echoCross[T, U](v1: T, v2: U) = |
24 echo v1, " x ", v2, " = ", v1.cross(v2) | 24 echo v1, " x ", v2, " = ", v1.cross(v2) |
25 | 25 |
26 proc randVec2I(): auto = newVec2(rand(1 .. 10), rand(1 .. 10)) | 26 proc randVec2I(): auto = NewVec2(rand(1 .. 10), rand(1 .. 10)) |
27 proc randVec2F(): auto = newVec2(rand(10'f) + 0.01, rand(10'f) + 0.01) | 27 proc randVec2F(): auto = NewVec2(rand(10'f) + 0.01, rand(10'f) + 0.01) |
28 proc randVec3I(): auto = newVec3(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) | 28 proc randVec3I(): auto = NewVec3(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) |
29 proc randVec3F(): auto = newVec3(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01) | 29 proc randVec3F(): auto = NewVec3(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01) |
30 proc randVec4I(): auto = newVec4(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) | 30 proc randVec4I(): auto = NewVec4(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) |
31 proc randVec4F(): auto = newVec4(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01) | 31 proc randVec4F(): auto = NewVec4(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01) |
32 | 32 |
33 | 33 |
34 template withAllIntegerMats(stuff: untyped) = | 34 template withAllIntegerMats(stuff: untyped) = |
35 stuff(TMat2[int32]) | 35 stuff(TMat2[int32]) |
36 stuff(TMat23[int32]) | 36 stuff(TMat23[int32]) |
79 stuff(TMat43[float]) | 79 stuff(TMat43[float]) |
80 stuff(TMat4[float]) | 80 stuff(TMat4[float]) |
81 | 81 |
82 template testTranspose(t: typedesc) = | 82 template testTranspose(t: typedesc) = |
83 echo "testTranspose: ", t | 83 echo "testTranspose: ", t |
84 let m = t().randomized() | 84 let m = t().Randomized() |
85 assert m == m.transposed().transposed() | 85 assert m == m.Transposed().Transposed() |
86 | |
87 template testInversed(t: typedesc) = | |
88 echo "testTranspose: ", t | |
89 let m = t().Randomized() | |
90 var unit = t() | |
91 for i in unit.RowCount: | |
92 unit[i][i] = 1 | |
93 assert m.Transposed() * m == unit | |
86 | 94 |
87 template testAssignI(t: typedesc) = | 95 template testAssignI(t: typedesc) = |
88 echo "testAssignI: ", t | 96 echo "testAssignI: ", t |
89 var m = t() | 97 var m = t() |
90 for i in 0 ..< t.data.len: | 98 for i in 0 ..< t.data.len: |
91 m[rand(0 ..< t.rowCount), rand(0 ..< t.columnCount)] = rand(0'i32 .. 100'i32) | 99 m[rand(0 ..< t.RowCount), rand(0 ..< t.ColumnCount)] = rand(0'i32 .. 100'i32) |
92 | 100 |
93 template testAssignF(t: typedesc) = | 101 template testAssignF(t: typedesc) = |
94 echo "testAssignF: ", t | 102 echo "testAssignF: ", t |
95 var m = t() | 103 var m = t() |
96 for i in 0 ..< t.data.len: | 104 for i in 0 ..< t.data.len: |
97 m[rand(0 ..< t.rowCount), rand(0 ..< t.columnCount)] = rand(100'f) | 105 m[rand(0 ..< t.RowCount), rand(0 ..< t.ColumnCount)] = rand(100'f) |
98 | 106 |
99 template testRowCols(t: typedesc) = | 107 template testRowCols(t: typedesc) = |
100 echo "testRowCols: ", t | 108 echo "testRowCols: ", t |
101 var m = t().randomized() | 109 var m = t().Randomized() |
102 for i in 0 ..< t.rowCount: | 110 for i in 0 ..< t.RowCount: |
103 echo m.row(i) | 111 echo m.Row(i) |
104 for i in 0 ..< t.columnCount: | 112 for i in 0 ..< t.ColumnCount: |
105 echo m.col(i) | 113 echo m.Col(i) |
106 | 114 |
107 | 115 |
108 proc testMatrix() = | 116 proc testMatrix() = |
109 withAllMats(testTranspose) | 117 withAllMats(testTranspose) |
110 withAllIntegerMats(testAssignI) | 118 withAllIntegerMats(testAssignI) |
130 echo Unit4i8 | 138 echo Unit4i8 |
131 echo Unit4i16 | 139 echo Unit4i16 |
132 echo Unit4i32 | 140 echo Unit4i32 |
133 echo Unit4i64 | 141 echo Unit4i64 |
134 | 142 |
135 echo TMat2[float32]().randomized() * One2.randomized() | 143 echo TMat2[float32]().Randomized() * One2.Randomized() |
136 echo TMat3[float32]().randomized() * One3.randomized() | 144 echo TMat3[float32]().Randomized() * One3.Randomized() |
137 echo TMat4[float32]().randomized() * One4.randomized() | 145 echo TMat4[float32]().Randomized() * One4.Randomized() |
138 | 146 |
139 echo float32(rand(1'f32)) * TMat2[float32]().randomized() | 147 echo float32(rand(1'f32)) * TMat2[float32]().Randomized() |
140 echo TMat2[float]().randomized() * rand(1'f) | 148 echo TMat2[float]().Randomized() * rand(1'f) |
141 echo TMat2[float]().randomized() * rand(1'f) | 149 echo TMat2[float]().Randomized() * rand(1'f) |
142 echo TMat23[float]().randomized() * rand(1'f) | 150 echo TMat23[float]().Randomized() * rand(1'f) |
143 echo TMat23[float]().randomized() * rand(1'f) | 151 echo TMat23[float]().Randomized() * rand(1'f) |
144 echo TMat3[float]().randomized() * rand(1'f) | 152 echo TMat3[float]().Randomized() * rand(1'f) |
145 echo TMat34[float]().randomized() * rand(1'f) | 153 echo TMat34[float]().Randomized() * rand(1'f) |
146 echo TMat43[float]().randomized() * rand(1'f) | 154 echo TMat43[float]().Randomized() * rand(1'f) |
147 echo TMat4[float]().randomized() * rand(1'f) | 155 echo TMat4[float]().Randomized() * rand(1'f) |
148 | 156 |
149 randomize() | 157 randomize() |
150 testMatrix() | 158 testMatrix() |