예제 #1
0
 def shortestPathXY(start, end, vh_set, grid_type, scale_factor,
                    part_radius):
     # TODO[NF]:  Docstring
     assert part_radius == DEFAULT_RADIUS
     x_y_path = []
     coordinate_path = ShortestPathHelper.shortestPathAStar(
         start=start,
         end=end,
         vh_set=vh_set,
         part_radius=part_radius,
         grid_type=grid_type,
         scale_factor=scale_factor)
     for node in coordinate_path:
         row = -node[0]
         column = node[1]
         if grid_type is GridEnum.HONEYCOMB:
             parity = 0 if HoneycombDnaPart.isEvenParity(
                 row=row, column=column) else 1
             node_pos = HoneycombDnaPart.latticeCoordToModelXY(
                 radius=part_radius, row=row, column=column)
         else:
             parity = None
             node_pos = SquareDnaPart.latticeCoordToModelXY(
                 radius=part_radius, row=row, column=column)
         x_y_path.append((node_pos[0], node_pos[1], parity))
     return x_y_path
예제 #2
0
    def showCreateHint(self,
                       coord: Tuple[int, int],
                       next_idnums: Tuple[int, int] = (0, 1),
                       show_hint: bool = True,
                       color: str = None) -> Optional[bool]:
        point_item = self.points_dict.get(coord)
        if point_item is None:
            return

        if not show_hint:
            point_item.showCreateHint(show_hint=False)

        if point_item:
            row, column = coord
            if self.grid_type is GridEnum.HONEYCOMB:
                parity = 0 if HoneycombDnaPart.isEvenParity(
                    row=row, column=column) else 1
            elif self.grid_type is GridEnum.SQUARE:
                parity = 0 if SquareDnaPart.isEvenParity(row=row,
                                                         column=column) else 1
            else:
                return
            id_num = next_idnums[1] if parity else next_idnums[0]
            point_item.showCreateHint(id_num=id_num,
                                      show_hint=show_hint,
                                      color=color)
            return parity == 1
예제 #3
0
 def _getCoordinateParity(self, row, column):
     if self.griditem.grid_type is GridType.HONEYCOMB:
         return 0 if HoneycombDnaPart.isEvenParity(row=row,
                                                   column=column) else 1
     elif self.griditem.grid_type is GridType.SQUARE:
         return 0 if SquareDnaPart.isEvenParity(row=row,
                                                column=column) else 1
     else:
         return None
예제 #4
0
 def getNeighborsForCoordinate(grid_type, row, column):
     # TODO[NF]:  Docstring
     if grid_type is GridEnum.HONEYCOMB:
         if not HoneycombDnaPart.isEvenParity(row, column):
             return ((row + 1, column), (row, column - 1), (row,
                                                            column + 1))
         else:
             return ((row - 1, column), (row, column + 1), (row,
                                                            column - 1))
     elif grid_type is GridEnum.SQUARE:
         return ((row, column + 1), (row, column - 1), (row - 1, column),
                 (row + 1, column))
     else:
         return ()
예제 #5
0
    def showCreateHint(self, coord, next_idnums=(0, 1), show_hint=True, color=None):
        point_item = self.points_dict.get(coord)
        if point_item is None:
            return

        if show_hint is False:
            point_item.showCreateHint(show_hint=False)

        if point_item:
            row, column = coord
            if self.grid_type is GridType.HONEYCOMB:
                parity = 0 if HoneycombDnaPart.isEvenParity(row=row, column=column) else 1
            elif self.grid_type is GridType.SQUARE:
                parity = 0 if SquareDnaPart.isEvenParity(row=row, column=column) else 1
            else:
                return
            id_num = next_idnums[1] if parity else next_idnums[0]
            point_item.showCreateHint(id_num=id_num, show_hint=show_hint, color=color)
            return parity == 1
예제 #6
0
    def showCreateHint(self, coord: Tuple[int, int],
                            next_idnums: Tuple[int, int] = (0, 1),
                            show_hint: bool = True,
                            color: str = None) -> Optional[bool]:
        point_item = self.points_dict.get(coord)
        if point_item is None:
            return

        if not show_hint:
            point_item.showCreateHint(show_hint=False)

        if point_item:
            row, column = coord
            if self.grid_type is GridEnum.HONEYCOMB:
                parity = 0 if HoneycombDnaPart.isEvenParity(row=row, column=column) else 1
            elif self.grid_type is GridEnum.SQUARE:
                parity = 0 if SquareDnaPart.isEvenParity(row=row, column=column) else 1
            else:
                return
            id_num = next_idnums[1] if parity else next_idnums[0]
            point_item.showCreateHint(id_num=id_num, show_hint=show_hint, color=color)
            return parity == 1
예제 #7
0
    def createHoneycombGrid(self, part_item, radius, bounds):
        """Instantiate an area of griditems arranged on a honeycomb lattice.

        Args:
            part_item (TYPE): Description
            radius (TYPE): Description
            bounds (TYPE): Description

        Returns:
            TYPE: Description
        """
        doLattice = HoneycombDnaPart.latticeCoordToPositionXY
        doPosition = HoneycombDnaPart.positionToLatticeCoordRound
        isEven = HoneycombDnaPart.isEvenParity
        x_l, x_h, y_l, y_h = bounds
        x_l = x_l + HoneycombDnaPart.PAD_GRID_XL
        x_h = x_h + HoneycombDnaPart.PAD_GRID_XH
        y_h = y_h + HoneycombDnaPart.PAD_GRID_YL
        y_l = y_l + HoneycombDnaPart.PAD_GRID_YH
        dot_size, half_dot_size = self.dots
        sf = part_item.scale_factor
        points = self.points
        row_l, col_l = doPosition(radius,
                                  x_l,
                                  -y_l,
                                  False,
                                  False,
                                  scale_factor=sf)
        row_h, col_h = doPosition(radius,
                                  x_h,
                                  -y_h,
                                  True,
                                  True,
                                  scale_factor=sf)

        redo_neighbors = (row_l, col_l, row_h, col_h) != self.previous_grid_bounds or\
            self.previous_grid_type != self.grid_type
        self.previous_grid_type = self.grid_type

        path = QPainterPath()
        is_pen_down = False
        draw_lines = self.draw_lines

        if redo_neighbors:
            point_coordinates = dict()
            neighbor_map = dict()
            self.points_dict = dict()

        for row in range(row_l, row_h):
            for column in range(col_l, col_h + 1):
                x, y = doLattice(radius, row, column, scale_factor=sf)
                if draw_lines:
                    if is_pen_down:
                        path.lineTo(x, -y)
                    else:
                        is_pen_down = True
                        path.moveTo(x, -y)
                """
                +x is Left and +y is down
                origin of ellipse is Top Left corner so we subtract half in X and subtract in y
                """
                pt = GridPoint(x - half_dot_size,
                               -y - half_dot_size,
                               dot_size,
                               self,
                               coord=(row, column))

                if self._draw_gridpoint_coordinates:
                    font = QFont(styles.THE_FONT)
                    path.addText(x - 10, -y + 5, font,
                                 "%s,%s" % (-row, column))

                pt.setPen(
                    getPenObj(styles.GRAY_STROKE,
                              styles.EMPTY_HELIX_STROKE_WIDTH))

                # if x == 0 and y == 0:
                #     pt.setBrush(getBrushObj(Qt.gray))

                points.append(pt)
                self.points_dict[(-row, column)] = pt

                if redo_neighbors:
                    point_coordinates[(-row, column)] = (x, -y)

                    # This is reversed since the Y is mirrored
                    if not HoneycombDnaPart.isEvenParity(row, column):
                        neighbor_map[(-row, column)] = [(-row - 1, column),
                                                        (-row, column + 1),
                                                        (-row, column - 1)]
                    else:
                        neighbor_map[(-row, column)] = [(-row + 1, column),
                                                        (-row, column - 1),
                                                        (-row, column + 1)]
                    self.previous_grid_bounds = (row_l, col_l, row_h, col_h)

            is_pen_down = False

        if draw_lines:
            for column in range(col_l, col_h + 1):
                for row in range(row_l, row_h):
                    x, y = doLattice(radius, row, column, scale_factor=sf)
                    if is_pen_down and isEven(row, column):
                        path.lineTo(x, -y)
                        is_pen_down = False
                    else:
                        is_pen_down = True
                        path.moveTo(x, -y)
                is_pen_down = False
            # end for j
        self._path.setPath(path)

        if redo_neighbors:
            self.part_item.setNeighborMap(neighbor_map=neighbor_map)
            self.part_item.setPointMap(point_map=point_coordinates)