geometry.py

changeset 38
66c9591b733d
parent 31
02e7e1d73ebb
child 62
f0a6bf48b05e
equal deleted inserted replaced
37:e46fa477007b 38:66c9591b733d
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.is_close(other, threshold = 1e-10) 70 return self.is_close(other, threshold = 1.0e-10)
71 def __ne__(self, other): 71 def __ne__(self, other):
72 return not self.__eq__(other) 72 return not self.__eq__(other)
73 def __lt__(self, other): 73 def __lt__(self, other):
74 return self.coordinates < other.coordinates 74 return self.coordinates < other.coordinates
75 def __hash__(self): 75 def __hash__(self):
76 return hash(self.coordinates) 76 return hash(self.coordinates)
77 def is_close(self, other, *, threshold): 77 def is_close(self, other, *, threshold = 1.0e-05):
78 return all( 78 return self.distance_to(other) < threshold
79 abs(a - b) < threshold 79 #return all(
80 for a, b in zip(self.coordinates, other.coordinates) 80 # abs(a - b) < threshold
81 ) 81 # for a, b in zip(self.coordinates, other.coordinates)
82 82 #)
83 class VertexOp:
84 def __init__(self, callable):
85 self.callable = callable
86 def __rmul__(self, coordinate):
87 return self.callable(coordinate)
88 83
89 class LineSegment: 84 class LineSegment:
90 def __init__(self, v1, v2): 85 def __init__(self, v1, v2):
91 self.v1, self.v2 = v1, v2 86 self.v1, self.v2 = v1, v2
92 def __repr__(self): 87 def __repr__(self):

mercurial