Skip to content

Commit fbe0a52

Browse files
author
Toni
authored
add doc for vec conversion (pygame-community#3446)
1 parent 388496f commit fbe0a52

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/reST/ref/math.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,33 @@ tuples.
6262
print(tuple(v.yx)) # (2.0, 1.0)
6363

6464

65+
A vector can be converted to other data types using the built-in constructors
66+
67+
::
68+
69+
v = pygame.Vector2(1, 2)
70+
71+
list(v) == [1.0, 2.0]
72+
tuple(v) == (1.0, 2.0)
73+
set(v) == {1.0, 2.0}
74+
75+
Conversion can be combined with swizzling or slicing to create a new order
76+
77+
::
78+
79+
v = pygame.Vector3(1, 2, 3)
80+
81+
list(v.xz) == [1.0, 3.0]
82+
list(v.zyx) == [3.0, 2.0, 1.0]
83+
list(v.yyy) == [2.0, 2.0, 2.0]
84+
tuple(v.xyyzzz) == (1.0, 2.0, 2.0, 3.0, 3.0, 3.0)
85+
tuple(v.zxyxzzyx) == (3.0, 1.0, 2.0, 1.0, 3.0, 3.0, 2.0, 1.0)
86+
set(v.yxzxzyzxyx) == {1.0, 2.0, 3.0} # sets remove duplicates
87+
88+
list(v[:]) == [1.0, 2.0, 3.0]
89+
tuple(v[::-1]) == (3.0, 2.0, 1.0)
90+
set(v[1:3]) == {2.0, 3.0}
91+
6592
.. versionaddedold:: 1.9.2pre
6693
.. versionchangedold:: 1.9.4 Removed experimental notice.
6794
.. versionchangedold:: 1.9.4 Allow scalar construction like GLSL Vector2(2) == Vector2(2.0, 2.0)

0 commit comments

Comments
 (0)