2021-11-20 17:55:10 +00:00
|
|
|
import strformat
|
|
|
|
|
2022-08-08 18:03:41 +00:00
|
|
|
var
|
|
|
|
swizzles = @["xyzw", "rgba", "stpq"]
|
|
|
|
code = ""
|
2021-11-20 17:55:10 +00:00
|
|
|
|
2022-08-08 18:03:41 +00:00
|
|
|
code.add "# Generated by tools/gensswizzle - don't edit manually.\n"
|
2021-11-20 17:55:10 +00:00
|
|
|
|
|
|
|
for swizzle in swizzles[1 .. ^1]:
|
2022-08-08 18:03:41 +00:00
|
|
|
code.add "\n# 1 x " & swizzle & "\n"
|
2021-11-20 17:55:10 +00:00
|
|
|
for i1, s1 in swizzle:
|
2022-08-08 18:03:41 +00:00
|
|
|
code.add &"proc {s1}*[T](a: GVec234[T]): T = a[{i1}]\n"
|
|
|
|
for i1, s1 in swizzle:
|
|
|
|
code.add &"proc `{s1}=`*[T](a: var GVec234[T], b: T) = a[{i1}] = b\n"
|
2021-11-20 17:55:10 +00:00
|
|
|
|
|
|
|
for swizzle in swizzles:
|
2022-08-08 18:03:41 +00:00
|
|
|
code.add "\n# 2 x " & swizzle & "\n"
|
|
|
|
for i1, s1 in swizzle:
|
|
|
|
for i2, s2 in swizzle:
|
|
|
|
code.add &"proc {s1}{s2}*[T](a: GVec234[T]): GVec2[T] = gvec2(a[{i1}], a[{i2}])\n"
|
2021-11-20 17:55:10 +00:00
|
|
|
for i1, s1 in swizzle:
|
|
|
|
for i2, s2 in swizzle:
|
2022-08-08 18:03:41 +00:00
|
|
|
code.add &"proc `{s1}{s2}=`*[T](a: var GVec234[T], b: GVec2[T]) = (let b = b; a[{i1}] = b.x; a[{i2}] = b.y)\n"
|
2021-11-20 17:55:10 +00:00
|
|
|
|
|
|
|
for swizzle in swizzles:
|
2022-08-08 18:03:41 +00:00
|
|
|
code.add "\n# 3 x " & swizzle & "\n"
|
|
|
|
for i1, s1 in swizzle:
|
|
|
|
for i2, s2 in swizzle:
|
|
|
|
for i3, s3 in swizzle:
|
|
|
|
code.add &"proc {s1}{s2}{s3}*[T](a: GVec234[T]): GVec3[T] = gvec3(a[{i1}], a[{i2}], a[{i3}])\n"
|
2021-11-20 17:55:10 +00:00
|
|
|
for i1, s1 in swizzle:
|
|
|
|
for i2, s2 in swizzle:
|
|
|
|
for i3, s3 in swizzle:
|
2022-08-08 18:03:41 +00:00
|
|
|
code.add &"proc `{s1}{s2}{s3}=`*[T](a: var GVec234[T], b: GVec3[T]) = (let b = b; a[{i1}] = b.x; a[{i2}] = b.y; a[{i3}] = b.z)\n"
|
2021-11-20 17:55:10 +00:00
|
|
|
|
|
|
|
for swizzle in swizzles:
|
2022-08-08 18:03:41 +00:00
|
|
|
code.add "\n# 4 x " & swizzle & "\n"
|
2021-11-20 17:55:10 +00:00
|
|
|
for i1, s1 in swizzle:
|
|
|
|
for i2, s2 in swizzle:
|
|
|
|
for i3, s3 in swizzle:
|
|
|
|
for i4, s4 in swizzle:
|
2022-08-08 18:03:41 +00:00
|
|
|
code.add &"proc {s1}{s2}{s3}{s4}*[T](a: GVec234[T]): GVec4[T] = gvec4(a[{i1}], a[{i2}], a[{i3}], a[{i4}])\n"
|
|
|
|
for i1, s1 in swizzle:
|
|
|
|
for i2, s2 in swizzle:
|
|
|
|
for i3, s3 in swizzle:
|
|
|
|
for i4, s4 in swizzle:
|
|
|
|
code.add &"proc `{s1}{s2}{s3}{s4}=`*[T](a: var GVec234[T], b: GVec4[T]) = (let b = b; a[{i1}] = b.x; a[{i2}] = b.y; a[{i3}] = b.z; a[{i4}] = b.w)\n"
|
|
|
|
|
|
|
|
writeFile("src/vmath/swizzle.nim", code)
|