Skip to content

Commit bf9d19f

Browse files
author
Jonathan Feinberg
committed
Fix PVector.dot instance ethod.
Fixes jdf/Processing.py-Bugs#101
1 parent fc1c33a commit bf9d19f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

runtime/src/jycessing/core.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ def __instance_cross__(self, o):
109109
def __instance_dist__(self, o):
110110
return PVector.dist(self, o)
111111

112-
def __instance_dot__(self, o):
113-
return PVector.dot(self, o)
112+
def __instance_dot__(self, *args):
113+
if len(args) == 1:
114+
v = args[0]
115+
return self.x * v.x + self.y * v.y + self.z * v.z
116+
return self.x * args[0] + self.y * args[1] + self.z * args[2]
114117

115118
def __init__(self, x=0, y=0, z=0):
116119
__pvector__.__init__(self, x, y, z)
@@ -120,6 +123,7 @@ def __init__(self, x=0, y=0, z=0):
120123
self.div = self.__instance_div__
121124
self.cross = self.__instance_cross__
122125
self.dist = self.__instance_dist__
126+
self.dot = self.__instance_dot__
123127

124128
def get(self):
125129
return PVector(self.x, self.y, self.z)

testing/resources/test_pvector.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@
9999
# Regression test for https://github.com/jdf/Processing.py-Bugs/issues/67
100100
assert isinstance(PVector(1,2), PVector)
101101

102+
# Regression test for https://github.com/jdf/Processing.py-Bugs/issues/101
103+
v = PVector(10, 20, 0)
104+
d = v.dot(60, 80, 0)
105+
assert d == 2200.0
106+
v2 = PVector(60, 80, 0)
107+
d = v.dot(v2)
108+
assert d == 2200.0
109+
102110
print 'OK'
103111

104112
exit()

0 commit comments

Comments
 (0)