Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#2 make quat listable and iterable

open
nobody
5
2010-01-20
2010-01-20
Maxime Lemonnier
No

q = quat()

list(q) should return [0, 0, 0, 0]

for i in q :
print i

should print
0
0
0
0

I was to open this request or all cgtypes, but vec and mat seems to work now (from when?)

Discussion

  • len() and q[0] should work also

     
  • Matthias Baas
    Matthias Baas
    2010-01-21

    Vectors and matrices had this from the beginning on as in their case, the semantics is fairly unambiguous whereas in the case of the quaternion it's not as clear to me anymore. Should list(q) be [w, x, y, z] or [x, y, z, w]? And why should one be preferable over the other?
    That's why I decided people should rather be explicit and spell out the list as above (you have surely heard of Python's Zen: "explicit is better than implicit" (http://www.python.org/dev/peps/pep-0020/) :-)
    So instead of list(q) you could rather write [q.w, q.x, q.y, q.z], then at least anybody reading your program exctly knows what they are dealing with.

    (if you have a use-case where the ability to index a quaternion or iterate over it would substantially simpify your program, I might be convinced and reconsider my decision)

     
  • Well, the use case is convertion to and from scipy/numpy.

    Since the constructor already breaks that "explicit better than implicit" guideline, why not extending it to iterable interface :

    # set all four components (w,x,y,z)
    q = quat(1,0,0,0)
    q = quat([1,0,0,0])
    q = quat("1,0,0,0")

    thanks :)