48 lines
1.6 KiB
Nim
48 lines
1.6 KiB
Nim
import strformat
|
|
|
|
var swizzles = @["xyzw", "rgba", "stpq"]
|
|
|
|
echo "# Generated by tools/gensswizzle"
|
|
|
|
for swizzle in swizzles[1 .. ^1]:
|
|
echo "\n# 1 x ", swizzle
|
|
for i1, s1 in swizzle:
|
|
echo &"template {s1}*[T](a: GVec234[T]): T = a[{i1}]"
|
|
echo &"template `{s1}=`*[T](a: var GVec234[T], b: T) = a[{i1}] = b"
|
|
|
|
for swizzle in swizzles:
|
|
echo "\n# 2 x ", swizzle
|
|
for i1, s1 in swizzle:
|
|
for i2, s2 in swizzle:
|
|
echo &"template {s1}{s2}*[T](a: GVec234[T]): GVec2[T] ="
|
|
echo &" let a2 = a"
|
|
echo &" gvec2(a2[{i1}], a2[{i2}])"
|
|
echo &"func `{s1}{s2}=`*[T](a: var GVec234[T], b: GVec2[T]) ="
|
|
echo &" let b2 = b"
|
|
echo &" a[{i1}] = b2.x; a[{i2}] = b2.y"
|
|
|
|
for swizzle in swizzles:
|
|
echo "\n# 3 x ", swizzle
|
|
for i1, s1 in swizzle:
|
|
for i2, s2 in swizzle:
|
|
for i3, s3 in swizzle:
|
|
echo &"template {s1}{s2}{s3}*[T](a: GVec234[T]): GVec3[T] ="
|
|
echo &" let a2 = a"
|
|
echo &" gvec3(a2[{i1}], a2[{i2}], a2[{i3}])"
|
|
echo &"func `{s1}{s2}{s3}=`*[T](a: var GVec234[T], b: GVec3[T]) ="
|
|
echo &" let b2 = b"
|
|
echo &" a[{i1}] = b2.x; a[{i2}] = b2.y; a[{i3}] = b2.z"
|
|
|
|
for swizzle in swizzles:
|
|
echo "\n# 4 x ", swizzle
|
|
for i1, s1 in swizzle:
|
|
for i2, s2 in swizzle:
|
|
for i3, s3 in swizzle:
|
|
for i4, s4 in swizzle:
|
|
echo &"template {s1}{s2}{s3}{s4}*[T](a: GVec234[T]): GVec4[T] ="
|
|
echo &" let a2 = a"
|
|
echo &" gvec4(a2[{i1}], a2[{i2}], a2[{i3}], a2[{i4}])"
|
|
echo &"func `{s1}{s2}{s3}{s4}=`*[T](a: var GVec234[T], b: GVec4[T]) ="
|
|
echo &" let b2 = b"
|
|
echo &" a[{i1}] = b2.x; a[{i2}] = b2.y; a[{i3}] = b2.z; a[{i4}] = b2.w"
|