Mercurial > games > semicongine
diff 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 |
line wrap: on
line diff
--- a/tests/test_matrix.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/tests/test_matrix.nim Tue Jun 04 16:51:50 2024 +0700 @@ -23,12 +23,12 @@ proc echoCross[T, U](v1: T, v2: U) = echo v1, " x ", v2, " = ", v1.cross(v2) -proc randVec2I(): auto = newVec2(rand(1 .. 10), rand(1 .. 10)) -proc randVec2F(): auto = newVec2(rand(10'f) + 0.01, rand(10'f) + 0.01) -proc randVec3I(): auto = newVec3(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) -proc randVec3F(): auto = newVec3(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01) -proc randVec4I(): auto = newVec4(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) -proc randVec4F(): auto = newVec4(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01) +proc randVec2I(): auto = NewVec2(rand(1 .. 10), rand(1 .. 10)) +proc randVec2F(): auto = NewVec2(rand(10'f) + 0.01, rand(10'f) + 0.01) +proc randVec3I(): auto = NewVec3(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) +proc randVec3F(): auto = NewVec3(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01) +proc randVec4I(): auto = NewVec4(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) +proc randVec4F(): auto = NewVec4(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01) template withAllIntegerMats(stuff: untyped) = @@ -81,28 +81,36 @@ template testTranspose(t: typedesc) = echo "testTranspose: ", t - let m = t().randomized() - assert m == m.transposed().transposed() + let m = t().Randomized() + assert m == m.Transposed().Transposed() + +template testInversed(t: typedesc) = + echo "testTranspose: ", t + let m = t().Randomized() + var unit = t() + for i in unit.RowCount: + unit[i][i] = 1 + assert m.Transposed() * m == unit template testAssignI(t: typedesc) = echo "testAssignI: ", t var m = t() for i in 0 ..< t.data.len: - m[rand(0 ..< t.rowCount), rand(0 ..< t.columnCount)] = rand(0'i32 .. 100'i32) + m[rand(0 ..< t.RowCount), rand(0 ..< t.ColumnCount)] = rand(0'i32 .. 100'i32) template testAssignF(t: typedesc) = echo "testAssignF: ", t var m = t() for i in 0 ..< t.data.len: - m[rand(0 ..< t.rowCount), rand(0 ..< t.columnCount)] = rand(100'f) + m[rand(0 ..< t.RowCount), rand(0 ..< t.ColumnCount)] = rand(100'f) template testRowCols(t: typedesc) = echo "testRowCols: ", t - var m = t().randomized() - for i in 0 ..< t.rowCount: - echo m.row(i) - for i in 0 ..< t.columnCount: - echo m.col(i) + var m = t().Randomized() + for i in 0 ..< t.RowCount: + echo m.Row(i) + for i in 0 ..< t.ColumnCount: + echo m.Col(i) proc testMatrix() = @@ -132,19 +140,19 @@ echo Unit4i32 echo Unit4i64 - echo TMat2[float32]().randomized() * One2.randomized() - echo TMat3[float32]().randomized() * One3.randomized() - echo TMat4[float32]().randomized() * One4.randomized() + echo TMat2[float32]().Randomized() * One2.Randomized() + echo TMat3[float32]().Randomized() * One3.Randomized() + echo TMat4[float32]().Randomized() * One4.Randomized() - echo float32(rand(1'f32)) * TMat2[float32]().randomized() - echo TMat2[float]().randomized() * rand(1'f) - echo TMat2[float]().randomized() * rand(1'f) - echo TMat23[float]().randomized() * rand(1'f) - echo TMat23[float]().randomized() * rand(1'f) - echo TMat3[float]().randomized() * rand(1'f) - echo TMat34[float]().randomized() * rand(1'f) - echo TMat43[float]().randomized() * rand(1'f) - echo TMat4[float]().randomized() * rand(1'f) + echo float32(rand(1'f32)) * TMat2[float32]().Randomized() + echo TMat2[float]().Randomized() * rand(1'f) + echo TMat2[float]().Randomized() * rand(1'f) + echo TMat23[float]().Randomized() * rand(1'f) + echo TMat23[float]().Randomized() * rand(1'f) + echo TMat3[float]().Randomized() * rand(1'f) + echo TMat34[float]().Randomized() * rand(1'f) + echo TMat43[float]().Randomized() * rand(1'f) + echo TMat4[float]().Randomized() * rand(1'f) randomize() testMatrix()