“Since vectors represent groupings of values, we cannot simply use traditional addition/multiplication/etc. Instead, we’ll need to do some “vector” math, which is made easy by the methods inside the PVector class.”
But arithmetic operators appear to work fine:
# methods
a = PVector(1, 1)
b = PVector(1, 1)
a.add(b)
print(a) # (2, 2)
print(a.div(2)) # (1, 1)
# arithmetic operators
a = PVector(1, 1)
b = PVector(1, 1)
a += b
print(a) # (2, 2)
print(a/2) # (1, 1)
What are the advantages (if any) of using the methods? Is this some Python vs Java Mode thing?
I’m not as familiar with the Python implementation of Processing, but if this is the right spot in the source code, then the Python operator definition calls either the static or the instance method.
For advantages vs. disadvantages, if you search for debates about whether languages should allow operator overloading or not, you’ll find a variety of responses. I’m not sure exactly what the documentation is referencing… Maybe to how, for example, the * operator could refer ambiugously to
component-wise multiplication betweeen two vectors
multiplication between a vector and a scalar
the cross product
the dot product?
The ambiguity between the first two is not as great in languages where the variable data type is clearer (i.e., PVector#mult(PVector, float) vs. PVector#mult(PVector, PVector)).