Description
Thanks for the quick turnaround on #151, it's refreshing to see a maintainer take action so quickly (no pressure on this one 😄).
I'm writing type stubs for pyglm
and came across some behaviors I'm not sure are intentional or not regarding sequences. I'm not making any prescriptions here for what pyglm
should do, but I'm noting these because they differ from how I've put the stubs together (because these behaviors are either difficult to describe with the python typing system or don't appear immediately useful in a typed context) and they seem like the kind of thing that might be artifacts of implementation.
Sequences used for initialization that contain items that are not __float__
/__int__
compatible will be 0:
import glm
glm.vec2(('abc', None)) # vec2(0, 0)
This is contrary to non-sequence initialization where this is a TypeError
:
import glm
glm.vec2('abc', None) # TypeError: invalid argument type(s) for vec()
Sequences used for initialization may be larger than the type's length, but only if the sequence has a length < 5:
import glm
glm.vec2([1, 2]) # vec2(1, 2)
glm.vec2([1, 2, 3]) # vec2(1, 2)
glm.vec2([1, 2, 3, 4]) # vec2(1, 2)
glm.vec2([1, 2, 3, 4, 5]) # TypeError: invalid argument type(s) for vec()
This rule also applies to matrix row/columns.
Following that, all matrix columns must have an equal size, even if they extend beyond what that matrix actually requires:
import glm
glm.mat2x2([
[1, 2, 3],
[10, 20, 30],
])
# [1][10]
# [2][20]
glm.mat2x2([
[1, 2, 3],
[10, 20],
]) # TypeError: invalid argument type(s) for mat2x2()
glm.mat2x2([
[1, 2, 3],
[10, 20, 30],
[100, 200, 300],
])
# [1][10]
# [2][20]
glm.mat2x2([
[1, 2,],
[10, 20,],
[100, 200, 300],
]) # TypeError: invalid argument type(s) for mat2x2()