def precalculate_polygon(self): diameter = self.diameter self.bounds_hash = {} my_polygon = Polygon() for i in range(len(self.polygon)): point1 = self.polygon.points[i - 1] point2 = self.polygon.points[i] my_polygon.extend(Edge.split(point1, point2, diameter)) self.precalculated_polygon = Polygon.copy(my_polygon.points) return my_polygon
def __init__(self, conditions_list, diameter, subdivide_n=0): self.conditions = [] self.points_to_condindex = {} self.diameter = diameter for key, value in conditions_list: p_start, p_end = key points = Edge.split(p_start, p_end, diameter) if points[-1] != p_end: points.append(Point.copy(p_end)) self.conditions.append(ConditionsItem.copy(value)) for i in range(len(points) - 1): p1_hash = hash(points[i]) p2_hash = hash(points[i + 1]) arr = tuple(sorted([p1_hash, p2_hash])) self.points_to_condindex[arr] = len(self.conditions) - 1
def test_split(self): n = 5 p1 = Point(1, 2) p2 = p1 + Point(n, n) s = Edge.split(p1, p2, 1.0) self.assertEqual(s, [p1 + (Point(1, 1) * i) for i in range(n)])