def clip(self, center, size): """ clip self in square of given size at given center. """ # TODO move in elementary path points = [ center + Point([-size, -size]), center + Point([size, -size]), center + Point([size, size]), center + Point([-size, size]), ] segments = [Segment([a, b]) for a, b in all_two_elements(points)] intersections = [] for segment in segments: intersection = segment.intersection_with_segment(self) if intersection: intersections.append(intersection) box = BoundingBox.empty_box(2) box.add_point(points[0]) box.add_point(points[2]) for chunk in self.split_at(intersections): middle = (chunk.endpoints[0] + chunk.endpoints[1]) / 2 if box.almost_contains_point(middle): return chunk
def tycat(self): """ graphical display for debugging """ # compute intersections intersections = [] for small_intersections in self.intersections.values(): intersections.extend(small_intersections) intersections = list(set(intersections)) # compute current vertical line bbox = BoundingBox.empty_box(2) for path in self.paths: bbox.update(path.get_bounding_box()) ymin, ymax = bbox.limits(1) height = ymax - ymin line_y_min = ymin - height / 20 line_y_max = ymax + height / 20 current_x = self.current_point.coordinates[0] vertical_line = Segment( [Point([current_x, line_y_min]), Point([current_x, line_y_max])]) # display figure tycat(self.paths, intersections, [self.current_point, vertical_line], *self.crossed_paths) print(list(self.key(p) for p in self.crossed_paths))
def animate(self, milling_radius): """ step by step animation for carving the path with given milling radius. """ total_length = self.length() steps_length = total_length / PATH_IMAGES # all paths strings up to now (by height) current_strings = SortedDict() bounding_box = BoundingBox.empty_box(2) # bounding box up to now current_height = 0 current_length = 0 heights_hash = CoordinatesHash() for path in self.elementary_paths: new_length = current_length + path.length() if isinstance(path, VerticalPath): current_height = path.update_height(current_height) current_height = heights_hash.hash_coordinate(current_height) else: envelope = Envelope(path, milling_radius) if current_height not in current_strings: current_strings[current_height] = [] current_strings[current_height].append(envelope.svg_content()) bounding_box.update(envelope.get_bounding_box()) if floor(current_length / steps_length) != \ floor(new_length / steps_length): tycat(*list(reversed(current_strings.values())), bounding_box=bounding_box) current_length = new_length
def get_bounding_box(self): """ min bounding box containing polygon. """ box = BoundingBox.empty_box(2) for point in self.points: box.add_point(point) return box
def get_bounding_box(self): """ return min bounding box containing self. """ box = BoundingBox.empty_box(2) for point in self.endpoints: box.add_point(point) return box
def get_bounding_box(self): """ min bounding box for whole path """ box = BoundingBox.empty_box(2) for path in self.elementary_paths: box.update(path.get_bounding_box()) return box
def get_bounding_box(self): """ smallest bounding box containing envelope """ box = BoundingBox.empty_box(2) for displaced_path in self.paths: box.update(displaced_path.path.get_bounding_box()) return box
def get_bounding_box(self): """ min bounding box containing vertices objects. """ box = BoundingBox.empty_box(2) for vertex in self.vertices: small_box = vertex.bound_object.get_bounding_box() box.update(small_box) return box
def get_bounding_box(self): """ returns min bounding box containing pocket """ box = BoundingBox.empty_box(2) for path in self.paths: pbox = path.get_bounding_box() box.update(pbox) return box
def get_bounding_box(self): """ bounding box for arc. for now, not tight """ box = BoundingBox.empty_box(2) box.add_point(self.center + Point([self.radius, self.radius])) box.add_point(self.center - Point([self.radius, self.radius])) return box
def __init__(self, file_name): self.heights_hash = CoordinatesHash(wanted_precision=5) self.facets = [] self.bounding_box = BoundingBox.empty_box(3) if __debug__: if is_module_debugged(__name__): print('loading stl file') self.parse_stl(file_name) if __debug__: if is_module_debugged(__name__): print('stl file loaded')
def __init__(self, filename, things, bounding_box): self.filename = filename self.svg_file = None if bounding_box is None: self.bounding_box = BoundingBox.empty_box(2) for thing in things: if isinstance(thing, list) or isinstance(thing, tuple): for subthing in thing: if subthing is not None: self.bounding_box.update( subthing.get_bounding_box()) else: if thing is not None: self.bounding_box.update(thing.get_bounding_box()) else: self.bounding_box = bounding_box self._calibrate()
def get_bounding_box(self): """ return min bounding box containing point. this method is defined on any displayable object. """ return BoundingBox(self.coordinates, self.coordinates)
def get_bounding_box(self): # pylint: disable=no-self-use """ bounding box. empty box. """ return BoundingBox.empty_box(2)