Mercurial > games > semicongine
annotate semiconginev2/core/vector.nim @ 1254:b0f4c8ccd49a
did: stuff to test gltf importer
author | sam <sam@basx.dev> |
---|---|
date | Sat, 27 Jul 2024 20:47:54 +0700 |
parents | c4f98eb4bb05 |
children |
rev | line source |
---|---|
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
1 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
2 type |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
3 TVec1*[T: SomeNumber] = array[1, T] |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
4 TVec2*[T: SomeNumber] = array[2, T] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
5 TVec3*[T: SomeNumber] = array[3, T] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
6 TVec4*[T: SomeNumber] = array[4, T] |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
7 TVec* = TVec1|TVec2|TVec3|TVec4 |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
8 Vec1f* = TVec1[float32] |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
9 Vec2f* = TVec2[float32] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
10 Vec3f* = TVec3[float32] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
11 Vec4f* = TVec4[float32] |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
12 Vec1i* = TVec1[int32] |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
13 Vec2i* = TVec2[int32] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
14 Vec3i* = TVec3[int32] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
15 Vec4i* = TVec4[int32] |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
16 Vec1u* = TVec1[uint32] |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
17 Vec2u* = TVec2[uint32] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
18 Vec3u* = TVec3[uint32] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
19 Vec4u* = TVec4[uint32] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
20 |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
21 converter ToVec1*[T: SomeNumber](orig: TVec3[T]|TVec4[T]): TVec1[T] = |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
22 TVec1[T]([orig[0]]) |
1136 | 23 converter ToVec2*[T: SomeNumber](orig: TVec3[T]|TVec4[T]): TVec2[T] = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
24 TVec2[T]([orig[0], orig[1]]) |
1136 | 25 converter ToVec3*[T: SomeNumber](orig: TVec4[T]): TVec3[T] = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
26 TVec3[T]([orig[0], orig[1], orig[2]]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
27 |
1136 | 28 func ToVec4*[T: SomeNumber](orig: TVec3[T], value: T = default(T)): TVec4[T] = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
29 TVec4[T]([orig[0], orig[1], orig[2], value]) |
1136 | 30 func ToVec3*[T: SomeNumber](orig: TVec2[T], value: T = default(T)): TVec3[T] = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
31 TVec3[T]([orig[0], orig[1], value]) |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
32 func ToVec2*[T: SomeNumber](orig: TVec1[T], value: T = default(T)): TVec2[T] = |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
33 TVec2[T]([orig[0], value]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
34 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
35 # define some often used constants |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
36 func ConstOne1[T: SomeNumber](): auto {.compiletime.} = TVec1[T]([T(1)]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
37 func ConstOne2[T: SomeNumber](): auto {.compiletime.} = TVec2[T]([T(1), T(1)]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
38 func ConstOne3[T: SomeNumber](): auto {.compiletime.} = TVec3[T]([T(1), T(1), T(1)]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
39 func ConstOne4[T: SomeNumber](): auto {.compiletime.} = TVec4[T]([T(1), T(1), T(1), T(1)]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
40 func ConstX[T: SomeNumber](): auto {.compiletime.} = TVec3[T]([T(1), T(0), T(0)]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
41 func ConstY[T: SomeNumber](): auto {.compiletime.} = TVec3[T]([T(0), T(1), T(0)]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
42 func ConstZ[T: SomeNumber](): auto {.compiletime.} = TVec3[T]([T(0), T(0), T(1)]) |
1254 | 43 func ConstR[T: SomeNumber](): auto {.compiletime.} = TVec4[T]([T(1), T(0), T(0), T(1)]) |
44 func ConstG[T: SomeNumber](): auto {.compiletime.} = TVec4[T]([T(0), T(1), T(0), T(1)]) | |
45 func ConstB[T: SomeNumber](): auto {.compiletime.} = TVec4[T]([T(0), T(0), T(1), T(1)]) | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
46 |
1136 | 47 func NewVec2f*(x = 0'f32, y = 0'f32): auto = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
48 Vec2f([x, y]) |
1136 | 49 func NewVec3f*(x = 0'f32, y = 0'f32, z = 0'f32): auto = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
50 Vec3f([x, y, z]) |
1136 | 51 func NewVec4f*(x = 0'f32, y = 0'f32, z = 0'f32, a = 0'f32): auto = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
52 Vec4f([x, y, z, a]) |
1136 | 53 func NewVec2i*(x = 0'i32, y = 0'i32): auto = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
54 Vec2i([x, y]) |
1136 | 55 func NewVec3i*(x = 0'i32, y = 0'i32, z = 0'i32): auto = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
56 Vec3i([x, y, z]) |
1136 | 57 func NewVec4i*(x = 0'i32, y = 0'i32, z = 0'i32, a = 0'i32): auto = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
58 Vec4i([x, y, z, a]) |
1136 | 59 func NewVec2u*(x = 0'u32, y = 0'u32): auto = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
60 Vec2u([x, y]) |
1136 | 61 func NewVec3u*(x = 0'u32, y = 0'u32, z = 0'u32): auto = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
62 Vec3u([x, y, z]) |
1136 | 63 func NewVec4u*(x = 0'u32, y = 0'u32, z = 0'u32, a = 0'u32): auto = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
64 Vec4u([x, y, z, a]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
65 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
66 # generates constants: Xf, Xf32, Xf64, Xi, Xi8, Xi16, Xi32, Xi64 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
67 # Also for Y, Z, R, G, B and One |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
68 # not sure if this is necessary or even a good idea... |
1190
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
1185
diff
changeset
|
69 macro generateAllVectorConsts() = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
70 result = newStmtList() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
71 for component in ["X", "Y", "Z", "R", "G", "B", "One2", "One3", "One4"]: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
72 for theType in ["int", "int8", "int16", "int32", "int64", "float", "float32", "float64"]: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
73 var typename = theType[0 .. 0] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
74 if theType[^2].isDigit: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
75 typename = typename & theType[^2] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
76 if theType[^1].isDigit: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
77 typename = typename & theType[^1] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
78 result.add( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
79 newConstStmt( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
80 postfix(ident(component & typename), "*"), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
81 newCall(nnkBracketExpr.newTree(ident("Const" & component), ident(theType))) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
82 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
83 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
84 |
1190
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
1185
diff
changeset
|
85 generateAllVectorConsts() |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
86 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
87 const X* = ConstX[float32]() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
88 const Y* = ConstY[float32]() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
89 const Z* = ConstZ[float32]() |
1254 | 90 const R* = ConstR[float32]() |
91 const G* = ConstG[float32]() | |
92 const B* = ConstB[float32]() | |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
93 const One1* = ConstOne1[float32]() |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
94 const One2* = ConstOne2[float32]() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
95 const One3* = ConstOne3[float32]() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
96 const One4* = ConstOne4[float32]() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
97 |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
98 func NewVec1*[T](x: T): auto = TVec1([x]) |
1136 | 99 func NewVec2*[T](x, y: T): auto = TVec2([x, y]) |
100 func NewVec3*[T](x, y, z: T): auto = TVec3([x, y, z]) | |
101 func NewVec4*[T](x, y, z, w: T): auto = TVec4([x, y, z, w]) | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
102 |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
103 func To*[T](v: TVec1): auto = TVec1([T(v[0])]) |
1136 | 104 func To*[T](v: TVec2): auto = TVec2([T(v[0]), T(v[1])]) |
105 func To*[T](v: TVec3): auto = TVec3([T(v[0]), T(v[1]), T(v[2])]) | |
106 func To*[T](v: TVec4): auto = TVec4([T(v[0]), T(v[1]), T(v[2]), T(v[3])]) | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
107 |
1253 | 108 func toVecString[T: TVec](value: T): string = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
109 var items: seq[string] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
110 for item in value: |
1004 | 111 items.add(&"{item.float:.5f}") |
997
fe48fb1bdfda
fix: ortho projection matrix (hopefully), better string output for matrix and vector
sam <sam@basx.dev>
parents:
920
diff
changeset
|
112 & "(" & join(items, " ") & ")" |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
113 |
1253 | 114 func `$`*(v: TVec1[SomeNumber]): string = toVecString[TVec1[SomeNumber]](v) |
115 func `$`*(v: TVec2[SomeNumber]): string = toVecString[TVec2[SomeNumber]](v) | |
116 func `$`*(v: TVec3[SomeNumber]): string = toVecString[TVec3[SomeNumber]](v) | |
117 func `$`*(v: TVec4[SomeNumber]): string = toVecString[TVec4[SomeNumber]](v) | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
118 |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
119 func Length*(vec: TVec1): auto = vec[0] |
1136 | 120 func Length*(vec: TVec2[SomeFloat]): auto = sqrt(vec[0] * vec[0] + vec[1] * vec[1]) |
121 func Length*(vec: TVec2[SomeInteger]): auto = sqrt(float(vec[0] * vec[0] + vec[1] * vec[1])) | |
122 func Length*(vec: TVec3[SomeFloat]): auto = sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]) | |
123 func Length*(vec: TVec3[SomeInteger]): auto = sqrt(float(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2])) | |
124 func Length*(vec: TVec4[SomeFloat]): auto = sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] + vec[3] * vec[3]) | |
125 func Length*(vec: TVec4[SomeInteger]): auto = sqrt(float(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] + vec[3] * vec[3])) | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
126 |
1136 | 127 func Normal*[T: SomeFloat](vec: TVec2[T]): auto = |
1005
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
128 TVec2[T]([vec[1], -vec[0]]) |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
129 |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
130 func Normalized*[T: SomeFloat](vec: TVec1[T]): auto = |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
131 return T(1) |
1136 | 132 func Normalized*[T: SomeFloat](vec: TVec2[T]): auto = |
133 let l = vec.Length | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
134 if l == 0: vec |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
135 else: TVec2[T]([vec[0] / l, vec[1] / l]) |
1136 | 136 func Normalized*[T: SomeFloat](vec: TVec3[T]): auto = |
137 let l = vec.Length | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
138 if l == 0: return vec |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
139 else: TVec3[T]([vec[0] / l, vec[1] / l, vec[2] / l]) |
1136 | 140 func Normalized*[T: SomeFloat](vec: TVec4[T]): auto = |
141 let l = vec.Length | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
142 if l == 0: return vec |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
143 else: TVec4[T]([vec[0] / l, vec[1] / l, vec[2] / l, vec[3] / l]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
144 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
145 # scalar operations |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
146 func `+`*(a: TVec1, b: SomeNumber): auto = TVec1([a[0] + b]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
147 func `+`*(a: TVec2, b: SomeNumber): auto = TVec2([a[0] + b, a[1] + b]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
148 func `+`*(a: TVec3, b: SomeNumber): auto = TVec3([a[0] + b, a[1] + b, a[2] + b]) |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
149 func `+`*(a: TVec4, b: SomeNumber): auto = TVec4([a[0] + b, a[1] + b, a[2] + b, a[3] + b]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
150 func `-`*(a: TVec1, b: SomeNumber): auto = TVec1([a[0] - b]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
151 func `-`*(a: TVec2, b: SomeNumber): auto = TVec2([a[0] - b, a[1] - b]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
152 func `-`*(a: TVec3, b: SomeNumber): auto = TVec3([a[0] - b, a[1] - b, a[2] - b]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
153 func `-`*(a: TVec4, b: SomeNumber): auto = TVec4([a[0] - b, a[1] - b, a[2] - b, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
154 a[3] - b]) |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
155 func `*`*(a: TVec1, b: SomeNumber): auto = TVec1([a[0] * b]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
156 func `*`*(a: TVec2, b: SomeNumber): auto = TVec2([a[0] * b, a[1] * b]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
157 func `*`*(a: TVec3, b: SomeNumber): auto = TVec3([a[0] * b, a[1] * b, a[2] * b]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
158 func `*`*(a: TVec4, b: SomeNumber): auto = TVec4([a[0] * b, a[1] * b, a[2] * b, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
159 a[3] * b]) |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
160 func `/`*[T: SomeInteger](a: TVec1[T], b: SomeInteger): auto = TVec1([a[0] div b]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
161 func `/`*[T: SomeFloat](a: TVec1[T], b: SomeFloat): auto = TVec1([a[0] / b]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
162 func `/`*[T: SomeInteger](a: TVec2[T], b: SomeInteger): auto = TVec2([a[0] div b, a[1] div b]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
163 func `/`*[T: SomeFloat](a: TVec2[T], b: SomeFloat): auto = TVec2([a[0] / b, a[1] / b]) |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
164 func `/`*[T: SomeInteger](a: TVec3[T], b: SomeInteger): auto = TVec3([a[0] div b, a[1] div b, a[2] div b]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
165 func `/`*[T: SomeFloat](a: TVec3[T], b: SomeFloat): auto = TVec3([a[0] / b, a[1] / b, a[2] / b]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
166 func `/`*[T: SomeInteger](a: TVec4[T], b: SomeInteger): auto = TVec4([a[0] div b, a[1] div b, a[2] div b, a[3] div b]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
167 func `/`*[T: SomeFloat](a: TVec4[T], b: SomeFloat): auto = TVec4([a[0] / b, a[1] / b, a[2] / b, a[3] / b]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
168 |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
169 func `+`*(a: SomeNumber, b: TVec1): auto = TVec1([a + b[0]]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
170 func `+`*(a: SomeNumber, b: TVec2): auto = TVec2([a + b[0], a + b[1]]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
171 func `+`*(a: SomeNumber, b: TVec3): auto = TVec3([a + b[0], a + b[1], a + b[2]]) |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
172 func `+`*(a: SomeNumber, b: TVec4): auto = TVec4([a + b[0], a + b[1], a + b[2], a + b[3]]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
173 func `-`*(a: SomeNumber, b: TVec1): auto = TVec1([a - b[0]]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
174 func `-`*(a: SomeNumber, b: TVec2): auto = TVec2([a - b[0], a - b[1]]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
175 func `-`*(a: SomeNumber, b: TVec3): auto = TVec3([a - b[0], a - b[1], a - b[2]]) |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
176 func `-`*(a: SomeNumber, b: TVec4): auto = TVec4([a - b[0], a - b[1], a - b[2], a - b[3]]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
177 func `*`*(a: SomeNumber, b: TVec1): auto = TVec1([a * b[0]]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
178 func `*`*(a: SomeNumber, b: TVec2): auto = TVec2([a * b[0], a * b[1]]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
179 func `*`*(a: SomeNumber, b: TVec3): auto = TVec3([a * b[0], a * b[1], a * b[2]]) |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
180 func `*`*(a: SomeNumber, b: TVec4): auto = TVec4([a * b[0], a * b[1], a * b[2], a * b[3]]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
181 func `/`*[T: SomeInteger](a: SomeInteger, b: TVec1[T]): auto = TVec1([a div b[0]]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
182 func `/`*[T: SomeFloat](a: SomeFloat, b: TVec1[T]): auto = TVec1([a / b[0]]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
183 func `/`*[T: SomeInteger](a: SomeInteger, b: TVec2[T]): auto = TVec2([a div b[0], a div b[1]]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
184 func `/`*[T: SomeFloat](a: SomeFloat, b: TVec2[T]): auto = TVec2([a / b[0], a / b[1]]) |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
185 func `/`*[T: SomeInteger](a: SomeInteger, b: TVec3[T]): auto = TVec3([a div b[0], a div b[1], a div b[2]]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
186 func `/`*[T: SomeFloat](a: SomeFloat, b: TVec3[T]): auto = TVec3([a / b[0], a / b[1], a / b[2]]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
187 func `/`*[T: SomeInteger](a: SomeInteger, b: TVec4[T]): auto = TVec4([a div b[ |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
188 0], a div b[1], a div b[2], a div b[3]]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
189 func `/`*[T: SomeFloat](a: SomeFloat, b: TVec4[T]): auto = TVec4([a / b[0], a / |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
190 b[1], a / b[2], a / b[3]]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
191 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
192 # compontent-wise operations |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
193 func `+`*(a, b: TVec1): auto = TVec1([a[0] + b[0]]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
194 func `+`*(a, b: TVec2): auto = TVec2([a[0] + b[0], a[1] + b[1]]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
195 func `+`*(a, b: TVec3): auto = TVec3([a[0] + b[0], a[1] + b[1], a[2] + b[2]]) |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
196 func `+`*(a, b: TVec4): auto = TVec4([a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
197 func `-`*(a: TVec1): auto = TVec1([-a[0]]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
198 func `-`*(a: TVec2): auto = TVec2([-a[0], -a[1]]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
199 func `-`*(a: TVec3): auto = TVec3([-a[0], -a[1], -a[2]]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
200 func `-`*(a: TVec4): auto = TVec4([-a[0], -a[1], -a[2], -a[3]]) |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
201 func `-`*(a, b: TVec1): auto = TVec1([a[0] - b[0]]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
202 func `-`*(a, b: TVec2): auto = TVec2([a[0] - b[0], a[1] - b[1]]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
203 func `-`*(a, b: TVec3): auto = TVec3([a[0] - b[0], a[1] - b[1], a[2] - b[2]]) |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
204 func `-`*(a, b: TVec4): auto = TVec4([a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3]]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
205 func `*`*(a, b: TVec1): auto = TVec1([a[0] * b[0]]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
206 func `*`*(a, b: TVec2): auto = TVec2([a[0] * b[0], a[1] * b[1]]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
207 func `*`*(a, b: TVec3): auto = TVec3([a[0] * b[0], a[1] * b[1], a[2] * b[2]]) |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
208 func `*`*(a, b: TVec4): auto = TVec4([a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
209 func `/`*[T: SomeInteger](a, b: TVec1[T]): auto = TVec1([a[0] div b[0]]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
210 func `/`*[T: SomeFloat](a, b: TVec1[T]): auto = TVec1([a[0] / b[0]]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
211 func `/`*[T: SomeInteger](a, b: TVec2[T]): auto = TVec2([a[0] div b[0], a[1] div b[1]]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
212 func `/`*[T: SomeFloat](a, b: TVec2[T]): auto = TVec2([a[0] / b[0], a[1] / b[1]]) |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
213 func `/`*[T: SomeInteger](a, b: TVec3[T]): auto = TVec3([a[0] div b[0], a[1] div b[1], a[2] div b[2]]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
214 func `/`*[T: SomeFloat](a, b: TVec3[T]): auto = TVec3([a[0] / b[0], a[1] / b[1], a[2] / b[2]]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
215 func `/`*[T: SomeInteger](a, b: TVec4[T]): auto = TVec4([a[0] div b[0], a[1] div b[1], a[2] div b[2], a[3] div b[3]]) |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
216 func `/`*[T: SomeFloat](a, b: TVec4[T]): auto = TVec4([a[0] / b[0], a[1] / b[1], a[2] / b[2], a[3] / b[3]]) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
217 |
1005
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
218 # assignment operations, scalar |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
219 func `+=`*(a: var TVec1, b: SomeNumber) = a = a + b |
1005
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
220 func `+=`*(a: var TVec2, b: SomeNumber) = a = a + b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
221 func `+=`*(a: var TVec3, b: SomeNumber) = a = a + b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
222 func `+=`*(a: var TVec4, b: SomeNumber) = a = a + b |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
223 func `-=`*(a: var TVec1, b: SomeNumber) = a = a - b |
1005
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
224 func `-=`*(a: var TVec2, b: SomeNumber) = a = a - b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
225 func `-=`*(a: var TVec3, b: SomeNumber) = a = a - b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
226 func `-=`*(a: var TVec4, b: SomeNumber) = a = a - b |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
227 func `*=`*(a: var TVec1, b: SomeNumber) = a = a * b |
1005
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
228 func `*=`*(a: var TVec2, b: SomeNumber) = a = a * b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
229 func `*=`*(a: var TVec3, b: SomeNumber) = a = a * b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
230 func `*=`*(a: var TVec4, b: SomeNumber) = a = a * b |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
231 func `/=`*(a: var TVec1, b: SomeNumber) = a = a / b |
1005
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
232 func `/=`*(a: var TVec2, b: SomeNumber) = a = a / b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
233 func `/=`*(a: var TVec3, b: SomeNumber) = a = a / b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
234 func `/=`*(a: var TVec4, b: SomeNumber) = a = a / b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
235 # assignment operations, vector |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
236 func `+=`*(a: var TVec1, b: TVec1) = a = a + b |
1005
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
237 func `+=`*(a: var TVec2, b: TVec2) = a = a + b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
238 func `+=`*(a: var TVec3, b: TVec3) = a = a + b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
239 func `+=`*(a: var TVec4, b: TVec4) = a = a + b |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
240 func `-=`*(a: var TVec1, b: TVec1) = a = a - b |
1005
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
241 func `-=`*(a: var TVec2, b: TVec2) = a = a - b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
242 func `-=`*(a: var TVec3, b: TVec3) = a = a - b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
243 func `-=`*(a: var TVec4, b: TVec4) = a = a - b |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
244 func `*=`*(a: var TVec1, b: TVec1) = a = a * b |
1005
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
245 func `*=`*(a: var TVec2, b: TVec2) = a = a * b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
246 func `*=`*(a: var TVec3, b: TVec3) = a = a * b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
247 func `*=`*(a: var TVec4, b: TVec4) = a = a * b |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
248 func `/=`*(a: var TVec1, b: TVec1) = a = a / b |
1005
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
249 func `/=`*(a: var TVec2, b: TVec2) = a = a / b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
250 func `/=`*(a: var TVec3, b: TVec3) = a = a / b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
251 func `/=`*(a: var TVec4, b: TVec4) = a = a / b |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
252 |
3845b9f1d27d
add: assignment operator, normal 2D vector
sam <sam@basx.dev>
parents:
1004
diff
changeset
|
253 |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
254 # special operations |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
255 func Pow*(a: TVec1, b: SomeNumber): auto = |
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
256 TVec1([pow(a[0], b)]) |
1136 | 257 func Pow*(a: TVec2, b: SomeNumber): auto = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
258 TVec2([pow(a[0], b), pow(a[1], b)]) |
1136 | 259 func Pow*(a: TVec3, b: SomeNumber): auto = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
260 TVec3([pow(a[0], b), pow(a[1], b), pow(a[2], b)]) |
1136 | 261 func Pow*(a: TVec4, b: SomeNumber): auto = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
262 TVec4([pow(a[0], b), pow(a[1], b), pow(a[2], b), pow(a[3], b)]) |
1185
565fcfde427a
did: first seemingly working version of texture/descriptor stuff
sam <sam@basx.dev>
parents:
1136
diff
changeset
|
263 func Dot*(a, b: TVec1): auto = a[0] * b[0] |
1136 | 264 func Dot*(a, b: TVec2): auto = a[0] * b[0] + a[1] * b[1] |
265 func Dot*(a, b: TVec3): auto = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] | |
266 func Dot*(a, b: TVec4): auto = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3] | |
267 func Cross*(a, b: TVec3): auto = TVec3([ | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
268 a[1] * b[2] - a[2] * b[1], |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
269 a[2] * b[0] - a[0] * b[2], |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
270 a[0] * b[1] - a[1] * b[0], |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
271 ]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
272 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
273 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
274 # macro to allow creation of new vectors by specifying vector components as attributes |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
275 # e.g. myVec.xxy will return a new Vec3 that contains the components x, x an y of the original vector |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
276 # (instead of x, y, z for a simple copy) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
277 proc vectorAttributeAccessor(accessor: string): seq[NimNode] = |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
278 const ACCESSOR_INDICES = { |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
279 'x': 0, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
280 'y': 1, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
281 'z': 2, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
282 'w': 3, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
283 'r': 0, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
284 'g': 1, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
285 'b': 2, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
286 'a': 3, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
287 }.toTable |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
288 var getterCode, setterCode: NimNode |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
289 let accessorvalue = accessor |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
290 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
291 if accessorvalue.len == 0: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
292 raise newException(Exception, "empty attribute") |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
293 elif accessorvalue.len == 1: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
294 getterCode = nnkBracketExpr.newTree(ident("vec"), newLit(ACCESSOR_INDICES[accessorvalue[0]])) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
295 setterCode = nnkStmtList.newTree( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
296 nnkAsgn.newTree( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
297 nnkBracketExpr.newTree(ident("vec"), newLit(ACCESSOR_INDICES[accessorvalue[0]])), ident("value")) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
298 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
299 if accessorvalue.len > 1: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
300 var attrs = nnkBracket.newTree() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
301 for attrname in accessorvalue: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
302 attrs.add(nnkBracketExpr.newTree(ident("vec"), newLit(ACCESSOR_INDICES[attrname]))) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
303 getterCode = nnkCall.newTree(ident("TVec" & $accessorvalue.len), attrs) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
304 setterCode = nnkStmtList.newTree() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
305 var i = 0 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
306 for attrname in accessorvalue: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
307 setterCode.add nnkAsgn.newTree( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
308 nnkBracketExpr.newTree(ident("vec"), newLit(ACCESSOR_INDICES[attrname])), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
309 nnkBracketExpr.newTree(ident("value"), newLit(i)), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
310 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
311 inc i |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
312 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
313 result.add newProc( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
314 name = nnkPostfix.newTree(ident("*"), ident(accessor)), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
315 params = [ident("auto"), nnkIdentDefs.newTree(ident("vec"), ident("TVec"), newEmptyNode())], |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
316 body = newStmtList(getterCode), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
317 procType = nnkFuncDef, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
318 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
319 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
320 result.add nnkFuncDef.newTree( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
321 nnkPostfix.newTree( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
322 newIdentNode("*"), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
323 nnkAccQuoted.newTree(newIdentNode(accessor), newIdentNode("=")) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
324 ), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
325 newEmptyNode(), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
326 nnkGenericParams.newTree(nnkIdentDefs.newTree(newIdentNode("T"), newEmptyNode(), newEmptyNode())), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
327 nnkFormalParams.newTree( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
328 newEmptyNode(), |
902 | 329 nnkIdentDefs.newTree(newIdentNode("vec"), nnkVarTy.newTree(newIdentNode("TVec")), newEmptyNode()), |
330 nnkIdentDefs.newTree(newIdentNode("value"), newIdentNode("T"), newEmptyNode()) | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
331 ), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
332 newEmptyNode(), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
333 newEmptyNode(), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
334 setterCode |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
335 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
336 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
337 macro createVectorAttribAccessorFuncs() = |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
338 const COORD_ATTRS = ["x", "y", "z", "w"] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
339 const COLOR_ATTRS = ["r", "g", "b", "a"] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
340 result = nnkStmtList.newTree() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
341 for attlist in [COORD_ATTRS, COLOR_ATTRS]: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
342 for i in attlist: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
343 result.add(vectorAttributeAccessor(i)) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
344 for j in attlist: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
345 result.add(vectorAttributeAccessor(i & j)) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
346 for k in attlist: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
347 result.add(vectorAttributeAccessor(i & j & k)) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
348 for l in attlist: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
349 result.add(vectorAttributeAccessor(i & j & k & l)) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
350 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
351 createVectorAttribAccessorFuncs() |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
352 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
353 # call e.g. Vec2[int]().randomized() to get a random matrix |
1190
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
1185
diff
changeset
|
354 template makeRandomVectorInit(mattype: typedesc) = |
1136 | 355 proc Randomized*[T: SomeInteger](m: mattype[T]): mattype[T] = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
356 for i in 0 ..< result.len: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
357 result[i] = rand(low(typeof(m[0])) .. high(typeof(m[0]))) |
1136 | 358 proc Randomized*[T: SomeFloat](m: mattype[T]): mattype[T] = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
359 for i in 0 ..< result.len: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
360 result[i] = rand(1.0) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
361 |
1190
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
1185
diff
changeset
|
362 makeRandomVectorInit(TVec1) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
1185
diff
changeset
|
363 makeRandomVectorInit(TVec2) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
1185
diff
changeset
|
364 makeRandomVectorInit(TVec3) |
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
1185
diff
changeset
|
365 makeRandomVectorInit(TVec4) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
366 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
367 converter Vec2VkExtent*(vec: TVec2[uint32]): VkExtent2D = VkExtent2D(width: vec[0], height: vec[1]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
368 converter Vec3VkExtent*(vec: TVec2[uint32]): VkExtent3D = VkExtent3D(width: vec[0], height: vec[1], depth: vec[2]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
369 |
1136 | 370 func AngleBetween*(a, b: Vec3f): float32 = |
371 arccos(a.Dot(b) / (a.Length * b.Length)) |