Added: Division and scalar multiplication to Vector

This commit is contained in:
David Vierra 2012-12-27 14:20:48 -10:00
parent 6ed8c45e4b
commit e8364f872e

13
box.py
View File

@ -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