add some vector conversions

This commit is contained in:
Ryan Oldenburg 2021-10-11 20:45:05 -05:00
parent 47891e35d2
commit 81041ac712
2 changed files with 50 additions and 0 deletions

View file

@ -485,6 +485,42 @@ genConstructor(uvec, UVec, uint32)
genConstructor(vec, Vec, float32)
genConstructor(dvec, DVec, float64)
proc vec2*(ivec2: Ivec2): Vec2 {.inline.} =
vec2(ivec2.x.float32, ivec2.y.float32)
proc vec2*(uvec2: Uvec2): Vec2 {.inline.} =
vec2(uvec2.x.float32, uvec2.y.float32)
proc ivec2*(uvec2: Uvec2): Ivec2 {.inline.} =
ivec2(uvec2.x.int32, uvec2.y.int32)
proc uvec2*(ivec2: Ivec2): Uvec2 {.inline.} =
uvec2(ivec2.x.uint32, ivec2.y.uint32)
proc vec3*(ivec3: Ivec3): Vec3 {.inline.} =
vec3(ivec3.x.float32, ivec3.y.float32, ivec3.z.float32)
proc vec3*(uvec3: Uvec3): Vec3 {.inline.} =
vec3(uvec3.x.float32, uvec3.y.float32, uvec3.z.float32)
proc ivec3*(uvec3: Uvec3): Ivec3 {.inline.} =
ivec3(uvec3.x.int32, uvec3.y.int32, uvec3.z.int32)
proc uvec3*(ivec3: Ivec3): Uvec3 {.inline.} =
uvec3(ivec3.x.uint32, ivec3.y.uint32, ivec3.z.uint32)
proc vec4*(ivec4: Ivec4): Vec4 {.inline.} =
vec4(ivec4.x.float32, ivec4.y.float32, ivec4.z.float32, ivec4.w.float32)
proc vec4*(uvec4: Uvec4): Vec4 {.inline.} =
vec4(uvec4.x.float32, uvec4.y.float32, uvec4.z.float32, uvec4.w.float32)
proc ivec4*(uvec4: Uvec4): Ivec4 {.inline.} =
ivec4(uvec4.x.int32, uvec4.y.int32, uvec4.z.int32, uvec4.w.int32)
proc uvec4*(ivec4: Ivec4): Uvec4 {.inline.} =
uvec4(ivec4.x.uint32, ivec4.y.uint32, ivec4.z.uint32, ivec4.w.uint32)
{.experimental: "dotOperators".}
proc num(letter: char, fields: NimNode): int =
## Given a swizzle character gives back the location number.

View file

@ -885,3 +885,17 @@ block:
doAssert bvec4(true, true, true, false) != bvec4(true, true, true, true)
doAssert ivec4(3, 3, 3, 3) != ivec4(3, 3, 3, 4)
doAssert uvec4(3, 3, 3, 3) != uvec4(3, 3, 3, 4)
block:
doAssert vec2(ivec2(1, 1)) == vec2(1, 1)
doAssert vec2(uvec2(5, 5)) == vec2(5, 5)
doAssert ivec2(uvec2(23, 23)) == ivec2(23, 23)
doAssert uvec2(ivec2(12, 12)) == uvec2(12, 12)
doAssert vec3(ivec3(1, 2, 3)) == vec3(1, 2, 3)
doAssert vec3(uvec3(4, 5, 6)) == vec3(4, 5, 6)
doAssert ivec3(uvec3(7, 8, 9)) == ivec3(7, 8, 9)
doAssert uvec3(ivec3(10, 11, 12)) == uvec3(10, 11, 12)
doAssert vec4(ivec4(13, 14, 15, 16)) == vec4(13, 14, 15, 16)
doAssert vec4(uvec4(17, 18, 19, 20)) == vec4(17, 18, 19, 20)
doAssert ivec4(uvec4(21, 22, 23, 24)) == ivec4(21, 22, 23, 24)
doAssert uvec4(ivec4(25, 26, 27, 28)) == uvec4(25, 26, 27, 28)