Skip to content

Commit b6ad722

Browse files
author
Jonathan Feinberg
committed
Merge pull request #111 from aparrish/more_pvector_fixes
add support for multiple-arg PVector .add()/.sub()
2 parents 0a4d691 + 077270a commit b6ad722

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

runtime/src/jycessing/core.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,17 @@
9191
# as static methods and instance methods.
9292
from processing.core import PVector as __pvector__
9393
class PVector(__pvector__):
94-
def __instance_add__(self, o):
95-
PVector.add(self, o, self)
94+
def __instance_add__(self, *args):
95+
if len(args) == 1:
96+
return PVector.add(self, args[0], self)
97+
else:
98+
return PVector.add(self, PVector(*args), self)
9699

97-
def __instance_sub__(self, o):
98-
PVector.sub(self, o, self)
100+
def __instance_sub__(self, *args):
101+
if len(args) == 1:
102+
return PVector.sub(self, args[0], self)
103+
else:
104+
return PVector.sub(self, PVector(*args), self)
99105

100106
def __instance_mult__(self, o):
101107
PVector.mult(self, o, self)

testing/resources/test_pvector.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@
107107
d = v.dot(v2)
108108
assert d == 2200.0
109109

110+
# PVector.add w/multiple arguments
111+
v = PVector(40, 20, 0)
112+
v.add(25, 50, 0)
113+
assert (v.x, v.y, v.z) == (65, 70, 0)
114+
115+
# PVector.sub w/multiple arguments
116+
v = PVector(40, 20, 0)
117+
v.sub(25, 50, 0)
118+
assert (v.x, v.y, v.z) == (15, -30, 0)
119+
110120
print 'OK'
111121

112122
exit()

0 commit comments

Comments
 (0)