Closed
Issue #1 · created by Jørgen Aarmo Lund ·


Commutative multiplication for Vector2D

By defining the operator rmul it's possible to let Vector2D have commutative multiplication (i.e. multiply scalars by vectors).

Change lines 36-47 of precode.py to

    def __mul__(self, b):
        """ Multiplication by a scalar. """
        return Vector2D(self.x * b, self.y * b)

    def __rmul__(self, b):
        return Vector2D(self.x * b, self.y * b)

2 participants