Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def scale(self, factor):
return Vector(factor * self.x, factor * self.y, factor * self.z)
def cross(self, other):
other.mustBeVector()
return Vector(self.y * other.z - self.z * other.y,
self.z * other.x - self.x * other.z,
self.x * other.y - self.y * other.x)
def isPoint(self):
return False
def mustBeVector(self):
return self
def mustBePoint(self):
raise 'Vectors are not points!'
def reflectThrough(self, normal):
d = normal.scale(self.dot(normal))
return self - d.scale(2)
Vector.ZERO = Vector(0, 0, 0)
Vector.RIGHT = Vector(1, 0, 0)
Vector.UP = Vector(0, 1, 0)
Vector.OUT = Vector(0, 0, 1)
assert Vector.RIGHT.reflectThrough(Vector.UP) == Vector.RIGHT
assert Vector(-1, -1, 0).reflectThrough(Vector.UP) == Vector(-1, 1, 0)
class Point(object):
def __init__(self, initx, inity, initz):
self.x = initx
self.y = inity
self.z = initz
def __str__(self):
def isPoint(self):
return False
def mustBeVector(self):
return self
def mustBePoint(self):
raise 'Vectors are not points!'
def reflectThrough(self, normal):
d = normal.scale(self.dot(normal))
return self - d.scale(2)
Vector.ZERO = Vector(0, 0, 0)
Vector.RIGHT = Vector(1, 0, 0)
Vector.UP = Vector(0, 1, 0)
Vector.OUT = Vector(0, 0, 1)
assert Vector.RIGHT.reflectThrough(Vector.UP) == Vector.RIGHT
assert Vector(-1, -1, 0).reflectThrough(Vector.UP) == Vector(-1, 1, 0)
class Point(object):
def __init__(self, initx, inity, initz):
self.x = initx
self.y = inity
self.z = initz
def __str__(self):
return '(%s,%s,%s)' % (self.x, self.y, self.z)
def mustBeVector(self):
return self
def mustBePoint(self):
raise 'Vectors are not points!'
def reflectThrough(self, normal):
d = normal.scale(self.dot(normal))
return self - d.scale(2)
Vector.ZERO = Vector(0, 0, 0)
Vector.RIGHT = Vector(1, 0, 0)
Vector.UP = Vector(0, 1, 0)
Vector.OUT = Vector(0, 0, 1)
assert Vector.RIGHT.reflectThrough(Vector.UP) == Vector.RIGHT
assert Vector(-1, -1, 0).reflectThrough(Vector.UP) == Vector(-1, 1, 0)
class Point(object):
def __init__(self, initx, inity, initz):
self.x = initx
self.y = inity
self.z = initz
def __str__(self):
return '(%s,%s,%s)' % (self.x, self.y, self.z)
def __repr__(self):
def __sub__(self, other):
if other.isPoint():
return Vector(self.x - other.x, self.y - other.y, self.z - other.z)
else:
return Point(self.x - other.x, self.y - other.y, self.z - other.z)
def __add__(self, other):
if other.isPoint():
return Point(self.x + other.x, self.y + other.y, self.z + other.z)
else:
return Vector(self.x + other.x, self.y + other.y, self.z + other.z)