geometry.py

changeset 13
12d4ddc4bfd8
parent 12
eb74680a5e43
child 14
d383f319f35b
equal deleted inserted replaced
12:eb74680a5e43 13:12d4ddc4bfd8
65 assert is_real(scalar) 65 assert is_real(scalar)
66 return type(self)(self.x // scalar, self.y // scalar, self.z // scalar) 66 return type(self)(self.x // scalar, self.y // scalar, self.z // scalar)
67 def __matmul__(self, transformation_matrix): 67 def __matmul__(self, transformation_matrix):
68 return transform(self, transformation_matrix) 68 return transform(self, transformation_matrix)
69 def __eq__(self, other): 69 def __eq__(self, other):
70 return self.coordinates == other.coordinates 70 return all(
71 abs(a - b) < 1e-8
72 for a, b in zip(self.coordinates, other.coordinates)
73 )
74 def __ne__(self, other):
75 return not self.__eq__(other)
71 def __lt__(self, other): 76 def __lt__(self, other):
72 return self.coordinates < other.coordinates 77 return self.coordinates < other.coordinates
73 def __hash__(self): 78 def __hash__(self):
74 return hash(self.coordinates) 79 return hash(self.coordinates)
75 80
144 b.x, b.y, 1, 149 b.x, b.y, 1,
145 c.x, c.y, 1, 150 c.x, c.y, 1,
146 ]).determinant() 151 ]).determinant()
147 return Vector(x, y, z).normalized() 152 return Vector(x, y, z).normalized()
148 153
154 class NoIntersection(Exception):
155 pass
156
149 def pairs(iterable, *, count = 2): 157 def pairs(iterable, *, count = 2):
150 ''' 158 '''
151 Iterates the given iterable and returns tuples containing `count` 159 Iterates the given iterable and returns tuples containing `count`
152 sequential values in the iterable. 160 sequential values in the iterable.
153 161

mercurial