annotate src/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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 std/strutils
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
3 import std/typetraits
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
4
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
5 import ./vector
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 type
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
8 # layout is row-first
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
9 # having an object instead of directly aliasing the array seems a bit ugly at
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
10 # first, but is necessary to be able to work correctly with distinguished
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
11 # types (i.e. Mat23 and Mat32 would be an alias for the same type array[6, T]
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
12 # which prevents the type system from identifying the correct type at times)
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 # Though, great news is that objects have zero overhead!
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
15 Mat22*[T: SomeNumber] = object
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
16 data: array[4, T]
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
17 Mat23*[T: SomeNumber] = object
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
18 data: array[6, T]
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
19 Mat32*[T: SomeNumber] = object
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
20 data: array[6, T]
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
21 Mat33*[T: SomeNumber] = object
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
22 data: array[9, T]
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
23 Mat34*[T: SomeNumber] = object
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
24 data: array[12, T]
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
25 Mat43*[T: SomeNumber] = object
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
26 data: array[12, T]
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
27 Mat44*[T: SomeNumber] = object
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
28 data: array[16, T]
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
29 MatMM* = Mat22|Mat33|Mat44
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
30 MatMN* = Mat23|Mat32|Mat34|Mat43
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
31 Mat* = MatMM|MatMN
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
32 IntegerMat = Mat22[SomeInteger]|Mat33[SomeInteger]|Mat44[SomeInteger]|Mat23[SomeInteger]|Mat32[SomeInteger]|Mat34[SomeInteger]|Mat43[SomeInteger]
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
33 FloatMat = Mat22[SomeFloat]|Mat33[SomeFloat]|Mat44[SomeFloat]|Mat23[SomeFloat]|Mat32[SomeFloat]|Mat34[SomeFloat]|Mat43[SomeFloat]
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
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
36 func rowCount*(m: Mat22): int = 2
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
37 func columnCount*(m: Mat22): int = 2
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
38 func rowCount*(m: Mat23): int = 2
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
39 func columnCount*(m: Mat23): int = 3
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
40 func rowCount*(m: Mat32): int = 3
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
41 func columnCount*(m: Mat32): int = 2
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
42 func rowCount*(m: Mat33): int = 3
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
43 func columnCount*(m: Mat33): int = 3
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
44 func rowCount*(m: Mat34): int = 3
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
45 func columnCount*(m: Mat34): int = 4
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
46 func rowCount*(m: Mat43): int = 4
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
47 func columnCount*(m: Mat43): int = 3
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
48 func rowCount*(m: Mat44): int = 4
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
49 func columnCount*(m: Mat44): int = 4
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
50
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
51
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
52 func toString[T](value: T): string =
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
53 var
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
54 strvalues: seq[string]
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
55 maxwidth = 0
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
56
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
57 for n in value.data:
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
58 let strval = $n
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
59 strvalues.add(strval)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
60 if strval.len > maxwidth:
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
61 maxwidth = strval.len
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
62
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
63 for i in 0 ..< strvalues.len:
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
64 let filler = " ".repeat(maxwidth - strvalues[i].len)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
65 if i mod value.columnCount == value.columnCount - 1:
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
66 result &= filler & strvalues[i] & "\n"
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
67 else:
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
68 if i mod value.columnCount == 0:
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
69 result &= " "
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
70 result &= filler & strvalues[i] & " "
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
71 result = $T & "\n" & result
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
72
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
73 func `$`*(v: Mat22[SomeNumber]): string = toString[Mat22[SomeNumber]](v)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
74 func `$`*(v: Mat23[SomeNumber]): string = toString[Mat23[SomeNumber]](v)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
75 func `$`*(v: Mat32[SomeNumber]): string = toString[Mat32[SomeNumber]](v)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
76 func `$`*(v: Mat33[SomeNumber]): string = toString[Mat33[SomeNumber]](v)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
77 func `$`*(v: Mat34[SomeNumber]): string = toString[Mat34[SomeNumber]](v)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
78 func `$`*(v: Mat43[SomeNumber]): string = toString[Mat43[SomeNumber]](v)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
79 func `$`*(v: Mat44[SomeNumber]): string = toString[Mat44[SomeNumber]](v)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
80
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
81 func `[]`*[T: Mat](m: T, row, col: int): auto = m.data[col + row * m.columnCount]
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
82 proc `[]=`*[T: Mat, U](m: var T, row, col: int, value: U) = m.data[col + row * m.columnCount] = value
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
83
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
84 func row*[T: Mat22](m: T, i: 0..1): auto = Vec2([m[i, 0], m[i, 1]])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
85 func row*[T: Mat32](m: T, i: 0..2): auto = Vec2([m[i, 0], m[i, 1]])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
86 func row*[T: Mat23](m: T, i: 0..1): auto = Vec3([m[i, 0], m[i, 1], m[i, 2]])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
87 func row*[T: Mat33](m: T, i: 0..2): auto = Vec3([m[i, 0], m[i, 1], m[i, 2]])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
88 func row*[T: Mat43](m: T, i: 0..3): auto = Vec3([m[i, 0], m[i, 1], m[i, 2]])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
89 func row*[T: Mat34](m: T, i: 0..2): auto = Vec4([m[i, 0], m[i, 1], m[i, 2], m[i, 3]])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
90 func row*[T: Mat44](m: T, i: 0..3): auto = Vec4([m[i, 0], m[i, 1], m[i, 2], m[i, 3]])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
91
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
92 func col*[T: Mat22](m: T, i: 0..1): auto = Vec2([m[0, i], m[1, i]])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
93 func col*[T: Mat23](m: T, i: 0..2): auto = Vec2([m[0, i], m[1, i]])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
94 func col*[T: Mat32](m: T, i: 0..1): auto = Vec3([m[0, i], m[1, i], m[2, i]])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
95 func col*[T: Mat33](m: T, i: 0..2): auto = Vec3([m[0, i], m[1, i], m[2, i]])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
96 func col*[T: Mat34](m: T, i: 0..3): auto = Vec3([m[0, i], m[1, i], m[2, i]])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
97 func col*[T: Mat43](m: T, i: 0..2): auto = Vec4([m[0, i], m[1, i], m[2, i], m[3, i]])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
98 func col*[T: Mat44](m: T, i: 0..3): auto = Vec4([m[0, i], m[1, i], m[2, i], m[3, i]])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
99
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
100 func transposed*[T](m: Mat22[T]): Mat22[T] = Mat22[T](data: [
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
101 m[0, 0], m[1, 0],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
102 m[0, 1], m[1, 1],
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 func transposed*[T](m: Mat23[T]): Mat32[T] = Mat32[T](data: [
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
105 m[0, 0], m[1, 0],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
106 m[0, 1], m[1, 1],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
107 m[0, 2], m[1, 2],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
108 ])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
109 func transposed*[T](m: Mat32[T]): Mat23[T] = Mat23[T](data: [
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
110 m[0, 0], m[1, 0], m[2, 0],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
111 m[0, 1], m[1, 1], m[2, 1],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
112 ])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
113 func transposed*[T](m: Mat33[T]): Mat33[T] = Mat33[T](data: [
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
114 m[0, 0], m[1, 0], m[2, 0],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
115 m[0, 1], m[1, 1], m[2, 1],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
116 m[0, 2], m[1, 2], m[2, 2],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
117 ])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
118 func transposed*[T](m: Mat43[T]): Mat34[T] = Mat34[T](data: [
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
119 m[0, 0], m[1, 0], m[2, 0], m[3, 0],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
120 m[0, 1], m[1, 1], m[2, 1], m[3, 1],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
121 m[0, 2], m[1, 2], m[2, 2], m[3, 2],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
122 ])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
123 func transposed*[T](m: Mat34[T]): Mat43[T] = Mat43[T](data: [
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
124 m[0, 0], m[1, 0], m[2, 0],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
125 m[0, 1], m[1, 1], m[2, 1],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
126 m[0, 2], m[1, 2], m[2, 2],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
127 m[0, 3], m[1, 3], m[2, 3],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
128 ])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
129 func transposed*[T](m: Mat44[T]): Mat44[T] = Mat44[T](data: [
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
130 m[0, 0], m[1, 0], m[2, 0], m[3, 0],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
131 m[0, 1], m[1, 1], m[2, 1], m[3, 1],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
132 m[0, 2], m[1, 2], m[2, 2], m[3, 2],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
133 m[0, 3], m[1, 3], m[2, 3], m[3, 3],
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
134 ])
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
135
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
136 # call e.g. Mat32[int]().initRandom() to get a random matrix
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
137 template makeRandomInit(mattype: typedesc) =
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
138 proc randomized*[T: SomeInteger](m: mattype[T]): mattype[T] =
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
139 for i in 0 ..< result.data.len:
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
140 result.data[i] = rand(low(typeof(m.data[0])) .. high(typeof(m.data[0])))
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
141 proc randomized*[T: SomeFloat](m: mattype[T]): mattype[T] =
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
142 for i in 0 ..< result.data.len:
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
143 result.data[i] = rand(1.0)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
144
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
145 makeRandomInit(Mat22)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
146 makeRandomInit(Mat23)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
147 makeRandomInit(Mat32)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
148 makeRandomInit(Mat33)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
149 makeRandomInit(Mat34)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
150 makeRandomInit(Mat43)
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
151 makeRandomInit(Mat44)