PVector in a separate module #12

Closed
jarav opened this Issue Nov 1, 2010 · 3 comments

Projects

None yet

2 participants

@jarav
jarav commented Nov 1, 2010

Suppose I have this:

main program

mysketch.py

import mylib

def setup():
size(200, 200)
noLoop()
v1 = PVector(50, 60)
v2 = PVector(120, 185)
mylib.f(v1, v2)

And in the module mylib.py:

mylib.py

import processing.core.PVector as PVector

def f(v1, v2):
v = PVector(2,3)
diff = PVector.sub(v1, v2)
print v # gives [ 2.0, 3.0, 0.0 ]
print diff # gives 'None'

PVector.sub gives 'None'

@jdf
Owner
jdf commented Nov 1, 2010

Don't import PVector; it should already be in the namespace you want. If you import PVector from processing.core, you're overwriting the weird Frankenclass I had to create to support PVectors same-named static and instance methods.

@jarav
jarav commented Nov 1, 2010

If I don't import Pvector like I had done, I get this error from the mylib module :
NameError: global name 'PVector' is not defined

@jdf
Owner
jdf commented Feb 12, 2011

This program works for me:

def f(v1, v2):
  v = PVector(2,3)
  diff = PVector.sub(v1, v2)
  print v
  print diff

f(PVector(12,13), PVector(100,88))

How about you?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment