def gift_wrap(self, points): np = len(points) if np <= 2: # too few points to wrap if np == 2: self.lines += [tuple(points)] return points hull_pt = min(points, key=lambda x: x[0]) # leftmost point toR = [] # the points we're wrapping on endpoint = None # the final point while endpoint is None or endpoint != toR[0]: toR.append(hull_pt) endpoint = points[0] for j in points[1:]: if endpoint == hull_pt or self.on_left((hull_pt, endpoint), j): endpoint = j hull_pt = endpoint n = Noise("butts") self.squiggles += [n.noisy_line(c1, c2) for c1, c2 in self.polypoints(toR)] self.polygons.append(toR) return toR