Skip to content

Commit 504932f

Browse files
sspickleclaude
andcommitted
support keyword args in vec/vector constructor (vec(x=1, y=2, z=3))
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5f9b375 commit 504932f

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

vpython/cyvector.pyx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ cdef class vector(object):
2626
def random():
2727
return vector(-1 + 2*random(), -1 + 2*random(), -1 + 2*random())
2828

29-
def __init__(self, *args):
29+
def __init__(self, *args, x=None, y=None, z=None):
3030
if len(args) == 3:
3131
self._x = args[0] # make sure it's a float; could be numpy.float64?
3232
self._y = args[1]
3333
self._z = args[2]
34+
elif len(args) == 0 and x is not None and y is not None and z is not None:
35+
self._x = float(x)
36+
self._y = float(y)
37+
self._z = float(z)
3438
elif len(args) == 1 and isinstance(args[0], vector): # make a copy of a vector
3539
other = args[0]
3640
self._x = other._x

0 commit comments

Comments
 (0)