compas
compas copied to clipboard
Vector operators
Describe the bug
for Vector peration *
, like:
>>> u = Vector(1.000, 1.000, 0.000)
>>> u * 2
Vector(2.000, 2.000, 0.000)
if we do:
Vector * float
: It is fine.
float * Vector
: TypeError: unsupported operand type(s) for *: 'float' and 'Vector'.
Expected behavior I think this could be fixed with minimal effort just for a better user experience. :)
Can it really be solved easily? I have the feeling it's not possible to define the binding of the star operator to take right hand operand as precedence...
yes, we could implement the "r" versions of the magic methods, but i don't know if there would be any unwanted side-effects...
def __rmul__(self, factor):
...
Ah true 👍
yes, it's not a big issue. mathmatically the floating number is preferred in the front. like a = k b
, a, b are vectors.
@tomvanmele you're right that rmul would address the issue, and @ZacZhangzhuo is right in that operators in Vectors should be complete -- but float * Vector
is quite counter intuitive?
i agree, that is why never implemented the "r" versions. i think it is easy enough for the user to be explicit about their intent by writing the compas object first...
@tomvanmele I know I'm being frantic, but seems like this issue can be closed? The broader concept of vec ops isn't discussed.
@tomvanmele you're right that rmul would address the issue, and @ZacZhangzhuo is right in that operators in Vectors should be complete -- but
float * Vector
is quite counter intuitive?
It is actually quite common and intuitive, especially when you compute a "WEIGHTED * long-expression"....