def split_facet_edges(self, facet, line): polygon_points = facet.polygon.points neighbors = facet.neighbors points = geoutil.polygon.intersect_line(facet.polygon, line) offset = 0 for (point, idx) in points: neighbor = facet.neighbors[idx + offset] self.split_facet_edge(facet, point, idx + offset) if neighbor: (neighbor_facet, neighbor_idx) = neighbor self.split_facet_edge(neighbor_facet, point, neighbor_idx) if facet.polygon.points[ idx + offset] == neighbor_facet.polygon.points[neighbor_idx]: facet.neighbors[idx + offset] = (neighbor_facet, neighbor_idx) facet.neighbors[idx + offset + 1] = (neighbor_facet, neighbor_idx + 1) neighbor_facet.neighbors[neighbor_idx] = (facet, idx + offset) neighbor_facet.neighbors[neighbor_idx + 1] = (facet, idx + offset + 1) else: facet.neighbors[idx + offset] = (neighbor_facet, neighbor_idx + 1) facet.neighbors[idx + offset + 1] = (neighbor_facet, neighbor_idx) neighbor_facet.neighbors[neighbor_idx] = (facet, idx + offset + 1) neighbor_facet.neighbors[neighbor_idx + 1] = (facet, idx + offset) offset += 1 facet.polygon = geo.Polygon(polygon_points) facet.neighbors = neighbors
def split_facet_edge(self, facet, point, idx): points = facet.polygon.points neighbors = facet.neighbors points.insert(idx, point) facet.neighbors.insert(idx, None) facet.polygon = geo.Polygon(points) for neighbor in neighbors[idx + 1:]: if neighbor: (neighbor_facet, neighbor_idx) = neighbor (neighbor_facet2, neighbor_idx2) = neighbor_facet.neighbors[neighbor_idx] neighbor_facet.neighbors[neighbor_idx] = (neighbor_facet2, neighbor_idx2 + 1)
def split(polygon, line): points = ([], []) segment_points = [] segment_idxs = [-1, -1] point_mappings = ([], []) last_point = polygon.points[-1] last_parity = point_parity(last_point, line) point_idx = 0 for point in polygon.points: parity = point_parity(point, line) if parity == 0: idx = 0 if last_parity == -1 else 1 segment_idxs[idx] = len(points[idx]) points[0].append(point) point_mappings[0].append(point_idx) points[1].append(point) point_mappings[1].append(point_idx) segment_points.append(point) else: idx = 0 if parity == -1 else 1 points[idx].append(point) point_mappings[idx].append(point_idx) last_parity = parity point_idx += 1 polygon0 = None polygon1 = None segment = None if len(segment_points) == 2: segment = geo.Segment(segment_points[0], segment_points[1]) if len(points[0]) > 2: polygon0 = geo.Polygon(points[0]) if len(points[1]) > 2: polygon1 = geo.Polygon(points[1]) return (polygon0, polygon1, segment, segment_idxs, point_mappings)
def __init__(self, parent=None): super(Window, self).__init__(parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.canvas.paintEvent = self.on_canvas_paint_event self.ui.canvas.mouseReleaseEvent = self.on_canvas_mouse_release_event self.ui.canvas.mouseMoveEvent = self.on_canvas_mouse_move_event self.ui.scrollArea.resizeEvent = self.on_scroll_area_resize_event self.ui.actionZoomIn.triggered.connect(self.on_action_zoom_in) self.ui.actionZoomOut.triggered.connect(self.on_action_zoom_out) self.ui.actionPoints.triggered.connect(self.on_action_points) self.ui.actionPointPoint.triggered.connect(self.on_action_point_point) self.ui.actionLineLine.triggered.connect(self.on_action_line_line) self.ui.actionLinePoint.triggered.connect(self.on_action_line_point) self.ui.actionPointPointLine.triggered.connect( self.on_action_point_point_line) self.ui.actionLinePointLine.triggered.connect( self.on_action_line_point_line) self.ui.actionValleyFold.triggered.connect(self.on_action_valley_fold) self.ui.actionExecuteFold.triggered.connect( self.on_action_execute_fold) self.ui.canvas.setMouseTracking(True) self.zoom = 1 points = [ geo.Point(0, 0), geo.Point(0, 1), geo.Point(1, 1), geo.Point(1, 0) ] polygon = geo.Polygon(points) self.sheet = paper.Sheet(polygon) self.highlight = None self.selected = [] self.lines = [] self.intersections = [] self.fold = None self.update_actions()
def reflect(polygon, line): points = [geoutil.point.reflect(point, line) for point in polygon.points] return geo.Polygon(points)