Mercurial > games > semicongine
comparison tests/test_vector.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 | c73224f9d38f |
children |
comparison
equal
deleted
inserted
replaced
1135:74957cbf589b | 1136:71315636ba82 |
---|---|
3 import semicongine | 3 import semicongine |
4 | 4 |
5 | 5 |
6 proc echoInfo[T](v: TVec2[T] or TVec3[T] or TVec4[T]) = | 6 proc echoInfo[T](v: TVec2[T] or TVec3[T] or TVec4[T]) = |
7 echo v | 7 echo v |
8 echo " Length: ", v.length | 8 echo " Length: ", v.Length |
9 when T is SomeFloat: | 9 when T is SomeFloat: |
10 echo " Normlized: ", v.normalized | 10 echo " Normlized: ", v.Normalized |
11 echo " negated: ", -v | 11 echo " negated: ", -v |
12 | 12 |
13 proc echoAdd[T, U](v1: T, v2: U) = | 13 proc echoAdd[T, U](v1: T, v2: U) = |
14 echo v1, " + ", v2, " = ", v1 + v2 | 14 echo v1, " + ", v2, " = ", v1 + v2 |
15 proc echoSub[T, U](v1: T, v2: U) = | 15 proc echoSub[T, U](v1: T, v2: U) = |
17 proc echoMul[T, U](v1: T, v2: U) = | 17 proc echoMul[T, U](v1: T, v2: U) = |
18 echo v1, " * ", v2, " = ", v1 * v2 | 18 echo v1, " * ", v2, " = ", v1 * v2 |
19 proc echoDiv[T, U](v1: T, v2: U) = | 19 proc echoDiv[T, U](v1: T, v2: U) = |
20 echo v1, " / ", v2, " = ", v1 / v2 | 20 echo v1, " / ", v2, " = ", v1 / v2 |
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( | 29 proc randVec3F(): auto = NewVec3(rand(10'f) + 0.01, rand(10'f) + 0.01, rand( |
30 10'f) + 0.01) | 30 10'f) + 0.01) |
31 proc randVec4I(): auto = newVec4(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10), | 31 proc randVec4I(): auto = NewVec4(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10), |
32 rand(1 .. 10)) | 32 rand(1 .. 10)) |
33 proc randVec4F(): auto = newVec4(rand(10'f) + 0.01, rand(10'f) + 0.01, rand( | 33 proc randVec4F(): auto = NewVec4(rand(10'f) + 0.01, rand(10'f) + 0.01, rand( |
34 10'f) + 0.01, rand(10'f) + 0.01) | 34 10'f) + 0.01, rand(10'f) + 0.01) |
35 | 35 |
36 | 36 |
37 proc testVector() = | 37 proc testVector() = |
38 echoInfo(randVec2I()) | 38 echoInfo(randVec2I()) |
128 echoDiv(rand(10'f), randVec3F()) | 128 echoDiv(rand(10'f), randVec3F()) |
129 echoDiv(rand(1 .. 10), randVec4I()) | 129 echoDiv(rand(1 .. 10), randVec4I()) |
130 echoDiv(rand(10'f), randVec4F()) | 130 echoDiv(rand(10'f), randVec4F()) |
131 | 131 |
132 # test attribute syntax sugar | 132 # test attribute syntax sugar |
133 echo "float2int ", to[int](randVec2F()) | 133 echo "float2int ", To[int](randVec2F()) |
134 echo "int2float ", to[float](randVec2I()) | 134 echo "int2float ", To[float](randVec2I()) |
135 echo "float2int ", to[int](randVec3F()) | 135 echo "float2int ", To[int](randVec3F()) |
136 echo "int2float ", to[float](randVec3I()) | 136 echo "int2float ", To[float](randVec3I()) |
137 echo "float2int ", to[int](randVec3F()) | 137 echo "float2int ", To[int](randVec3F()) |
138 echo "int2float ", to[float](randVec3I()) | 138 echo "int2float ", To[float](randVec3I()) |
139 | 139 |
140 echo "V3I.x: ", randVec3I().x | 140 echo "V3I.x: ", randVec3I().x |
141 echo "V3I.y: ", randVec3I().y | 141 echo "V3I.y: ", randVec3I().y |
142 echo "V3F.z: ", randVec3F().z | 142 echo "V3F.z: ", randVec3F().z |
143 echo "V3I.r: ", randVec3I().r | 143 echo "V3I.r: ", randVec3I().r |
144 echo "V3I.g: ", randVec3I().g | 144 echo "V3I.g: ", randVec3I().g |
145 echo "V3F.b: ", randVec3F().b | 145 echo "V3F.b: ", randVec3F().b |
146 | 146 |
147 # test setters | 147 # test setters |
148 var v1 = randVec2I(); v1.x = 1 ; v1.y = 2 ; v1.r = 3 ; v1.g = 4 | 148 var v1 = randVec2I(); v1.x = 1; v1.y = 2; v1.r = 3; v1.g = 4 |
149 v1.xy = randVec2I() ; v1.yx = randVec2I() ; v1.rg = randVec2I() ; v1.gr = randVec2I() | 149 v1.xy = randVec2I(); v1.yx = randVec2I(); v1.rg = randVec2I(); v1.gr = randVec2I() |
150 var v2 = randVec2F(); v2.x = 1.0 ; v2.y = 2.0 ; v2.r = 3.0 ; v2.g = 4.0 | 150 var v2 = randVec2F(); v2.x = 1.0; v2.y = 2.0; v2.r = 3.0; v2.g = 4.0 |
151 v2.xy = randVec2F() ; v2.yx = randVec2F() ; v2.rg = randVec2F() ; v2.gr = randVec2F() | 151 v2.xy = randVec2F(); v2.yx = randVec2F(); v2.rg = randVec2F(); v2.gr = randVec2F() |
152 | 152 |
153 var v3 = randVec3I(); v3.x = 1 ; v3.y = 2 ; v3.z = 3 ; v3.r = 4 ; v3.g = 5 ; v3.b = 6 | 153 var v3 = randVec3I(); v3.x = 1; v3.y = 2; v3.z = 3; v3.r = 4; v3.g = 5; v3.b = 6 |
154 v3.xyz = randVec3I() ; v3.rgb = randVec3I() | 154 v3.xyz = randVec3I(); v3.rgb = randVec3I() |
155 var v4 = randVec3F(); v4.x = 1.0 ; v4.y = 2.0 ; v4.z = 3.0 ; v4.r = 4.0 ; v4.g = 5.0 ; v4.b = 6.0 | 155 var v4 = randVec3F(); v4.x = 1.0; v4.y = 2.0; v4.z = 3.0; v4.r = 4.0; v4.g = 5.0; v4.b = 6.0 |
156 v4.xyz = randVec3F() ; v4.rgb = randVec3F() | 156 v4.xyz = randVec3F(); v4.rgb = randVec3F() |
157 | 157 |
158 var v5 = randVec4I(); v5.x = 1 ; v5.y = 2 ; v5.z = 3; v5.w = 4 ; v5.r = 5 ; v5.g = 6 ; v5.b = 7 ; v5.a = 8 | 158 var v5 = randVec4I(); v5.x = 1; v5.y = 2; v5.z = 3; v5.w = 4; v5.r = 5; v5.g = 6; v5.b = 7; v5.a = 8 |
159 v5.xyzw = randVec4I() ; v5.rgba = randVec4I() | 159 v5.xyzw = randVec4I(); v5.rgba = randVec4I() |
160 var v6 = randVec4F(); v6.x = 1.0 ; v6.y = 2.0 ; v6.z = 3.0 ; v6.w = 4.0 ; v6.r = 5.0 ; v6.g = 6.0 ; v6.b = 7.0 ; v6.a = 8.0 | 160 var v6 = randVec4F(); v6.x = 1.0; v6.y = 2.0; v6.z = 3.0; v6.w = 4.0; v6.r = 5.0; v6.g = 6.0; v6.b = 7.0; v6.a = 8.0 |
161 v6.xyzw = randVec4F() ; v6.rgba = randVec4F() | 161 v6.xyzw = randVec4F(); v6.rgba = randVec4F() |
162 | 162 |
163 echo "V2I.xx: ", randVec2I().xx | 163 echo "V2I.xx: ", randVec2I().xx |
164 echo "V2I.yx: ", randVec2I().xy | 164 echo "V2I.yx: ", randVec2I().xy |
165 echo "V2F.xx: ", randVec2F().xx | 165 echo "V2F.xx: ", randVec2F().xx |
166 echo "V2F.yx: ", randVec2F().yx | 166 echo "V2F.yx: ", randVec2F().yx |