From e8364f872eb5f4076b38cf17a8e843d59d400e58 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Thu, 27 Dec 2012 14:20:48 -1000 Subject: [PATCH] Added: Division and scalar multiplication to Vector --- box.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/box.py b/box.py index caf6f0e..1406766 100644 --- a/box.py +++ b/box.py @@ -9,11 +9,24 @@ class Vector(_Vector): def __add__(self, other): return Vector(self[0] + other[0], self[1] + other[1], self[2] + other[2]) + def __sub__(self, other): return Vector(self[0] - other[0], self[1] - other[1], self[2] - other[2]) + def __mul__(self, other): + if isinstance(other, (int, float)): + return Vector(self[0] * other, self[1] * other, self[2] * other) + return Vector(self[0] * other[0], self[1] * other[1], self[2] * other[2]) + def __truediv__(self, other): + if isinstance(other, (int, float)): + return Vector(self[0] / other, self[1] / other, self[2] / other) + + return Vector(self[0] / other[0], self[1] / other[1], self[2] / other[2]) + + __div__ = __truediv__ + class BoundingBox (object): type = int