Merge pull request #52 from levovix0/master
fix getters and template -> func for setters in swizzle
This commit is contained in:
commit
da90d35282
File diff suppressed because it is too large
Load diff
|
@ -362,6 +362,75 @@ block:
|
||||||
b.g = 123
|
b.g = 123
|
||||||
doAssert b == dvec4(4.0, 123.0, 2.0, 1.0)
|
doAssert b == dvec4(4.0, 123.0, 2.0, 1.0)
|
||||||
|
|
||||||
|
block:
|
||||||
|
# Test swizzle with complex expressions
|
||||||
|
var a = [
|
||||||
|
vec2(1, 2),
|
||||||
|
vec2(3, 4),
|
||||||
|
vec2(5, 6),
|
||||||
|
vec2(7, 8),
|
||||||
|
]
|
||||||
|
var i = 0
|
||||||
|
proc f(): var Vec2 =
|
||||||
|
# function with side effects
|
||||||
|
result = a[i]
|
||||||
|
inc i
|
||||||
|
|
||||||
|
doAssert f().yx == vec2(2, 1)
|
||||||
|
doAssert f().gr == vec2(4, 3)
|
||||||
|
doAssert f().ts == vec2(6, 5)
|
||||||
|
doAssert f().yx == vec2(8, 7)
|
||||||
|
doAssert i == 4
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
f().yx = f()
|
||||||
|
doAssert a[0] == vec2(4, 3)
|
||||||
|
doAssert a[1] == vec2(3, 4)
|
||||||
|
doAssert i == 2
|
||||||
|
|
||||||
|
var b = [
|
||||||
|
vec3(1, 2, 3),
|
||||||
|
vec3(4, 5, 6),
|
||||||
|
vec3(7, 8, 9),
|
||||||
|
]
|
||||||
|
i = 0
|
||||||
|
proc g(): var Vec3 =
|
||||||
|
# function with side effects
|
||||||
|
result = b[i]
|
||||||
|
inc i
|
||||||
|
|
||||||
|
doAssert g().yxz == vec3(2, 1, 3)
|
||||||
|
doAssert g().bgr == vec3(6, 5, 4)
|
||||||
|
doAssert g().tps == vec3(8, 9, 7)
|
||||||
|
doAssert i == 3
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
g().yxz = g()
|
||||||
|
doAssert b[0] == vec3(5, 4, 6)
|
||||||
|
doAssert b[1] == vec3(4, 5, 6)
|
||||||
|
doAssert i == 2
|
||||||
|
|
||||||
|
var c = [
|
||||||
|
vec4(1, 2, 3, 4),
|
||||||
|
vec4(5, 6, 7, 8),
|
||||||
|
]
|
||||||
|
i = 0
|
||||||
|
proc h(): var Vec4 =
|
||||||
|
# function with side effects
|
||||||
|
result = c[i]
|
||||||
|
inc i
|
||||||
|
|
||||||
|
doAssert h().yxzw == vec4(2, 1, 3, 4)
|
||||||
|
doAssert h().tqsp == vec4(6, 8, 5, 7)
|
||||||
|
doAssert i == 2
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
h().wzyx = h()
|
||||||
|
doAssert c[0] == vec4(8, 7, 6, 5)
|
||||||
|
doAssert c[1] == vec4(5, 6, 7, 8)
|
||||||
|
doAssert i == 2
|
||||||
|
|
||||||
|
|
||||||
block:
|
block:
|
||||||
# Test basic mat constructors.
|
# Test basic mat constructors.
|
||||||
block:
|
block:
|
||||||
|
|
|
@ -15,10 +15,11 @@ for swizzle in swizzles:
|
||||||
for i1, s1 in swizzle:
|
for i1, s1 in swizzle:
|
||||||
for i2, s2 in swizzle:
|
for i2, s2 in swizzle:
|
||||||
echo &"template {s1}{s2}*[T](a: GVec234[T]): GVec2[T] ="
|
echo &"template {s1}{s2}*[T](a: GVec234[T]): GVec2[T] ="
|
||||||
echo &" gvec2(a[{i1}], a[{i2}])"
|
echo &" let a2 = a"
|
||||||
echo &"template `{s1}{s2}=`*[T](a: var GVec234[T], b: GVec2[T]) ="
|
echo &" gvec2(a2[{i1}], a2[{i2}])"
|
||||||
echo &" let x = b.x; let y = b.y"
|
echo &"func `{s1}{s2}=`*[T](a: var GVec234[T], b: GVec2[T]) ="
|
||||||
echo &" a[0{i1}] = x; a[{i2}] = y"
|
echo &" let b2 = b"
|
||||||
|
echo &" a[{i1}] = b2.x; a[{i2}] = b2.y"
|
||||||
|
|
||||||
for swizzle in swizzles:
|
for swizzle in swizzles:
|
||||||
echo "\n# 3 x ", swizzle
|
echo "\n# 3 x ", swizzle
|
||||||
|
@ -26,10 +27,11 @@ for swizzle in swizzles:
|
||||||
for i2, s2 in swizzle:
|
for i2, s2 in swizzle:
|
||||||
for i3, s3 in swizzle:
|
for i3, s3 in swizzle:
|
||||||
echo &"template {s1}{s2}{s3}*[T](a: GVec234[T]): GVec3[T] ="
|
echo &"template {s1}{s2}{s3}*[T](a: GVec234[T]): GVec3[T] ="
|
||||||
echo &" gvec3(a[{i1}], a[{i2}], a[{i3}])"
|
echo &" let a2 = a"
|
||||||
echo &"template `{s1}{s2}{s3}=`*[T](a: var GVec234[T], b: GVec3[T]) ="
|
echo &" gvec3(a2[{i1}], a2[{i2}], a2[{i3}])"
|
||||||
echo &" let x = b.x; let y = b.y; let z = b.z"
|
echo &"func `{s1}{s2}{s3}=`*[T](a: var GVec234[T], b: GVec3[T]) ="
|
||||||
echo &" a[{i1}] = x; a[{i2}] = y; a[{i3}] = z"
|
echo &" let b2 = b"
|
||||||
|
echo &" a[{i1}] = b2.x; a[{i2}] = b2.y; a[{i3}] = b2.z"
|
||||||
|
|
||||||
for swizzle in swizzles:
|
for swizzle in swizzles:
|
||||||
echo "\n# 4 x ", swizzle
|
echo "\n# 4 x ", swizzle
|
||||||
|
@ -38,7 +40,8 @@ for swizzle in swizzles:
|
||||||
for i3, s3 in swizzle:
|
for i3, s3 in swizzle:
|
||||||
for i4, s4 in swizzle:
|
for i4, s4 in swizzle:
|
||||||
echo &"template {s1}{s2}{s3}{s4}*[T](a: GVec234[T]): GVec4[T] ="
|
echo &"template {s1}{s2}{s3}{s4}*[T](a: GVec234[T]): GVec4[T] ="
|
||||||
echo &" gvec4(a [{i1}], a[{i2}], a[{i3}], a[{i4}])"
|
echo &" let a2 = a"
|
||||||
echo &"template `{s1}{s2}{s3}{s4}=`*[T](a: var GVec234[T], b: GVec4[T]) ="
|
echo &" gvec4(a2[{i1}], a2[{i2}], a2[{i3}], a2[{i4}])"
|
||||||
echo &" let x = b.x; let y = b.y; let z = b.z; let w = b.w"
|
echo &"func `{s1}{s2}{s3}{s4}=`*[T](a: var GVec234[T], b: GVec4[T]) ="
|
||||||
echo &" a[{i1}] = x; a[{i2}] = y; a[{i3}] = z; a[{i4}] = w"
|
echo &" let b2 = b"
|
||||||
|
echo &" a[{i1}] = b2.x; a[{i2}] = b2.y; a[{i3}] = b2.z; a[{i4}] = b2.w"
|
||||||
|
|
Loading…
Reference in a new issue