def set_path(self, path): """ Sets the path for this wire to |path|. Path must start and end at the start and end connectors of this wire, respectively. Each of the segments in |path| must be horizontal or vertical. This method also stores the corresponding path coverage. """ for i in xrange(len(path) - 1): x1, y1 = path[i] x2, y2 = path[i + 1] assert x1 == x2 or y1 == y2 assert path[0] == self.start_connector.center assert path[-1] == self.end_connector.center self.path = path self.path_coverage = path_coverage(path)
def find_wire_path_simple(board_coverage, start_point, end_point): """ Returns a list of tuples indicating a path from |start_point| to |end_point| on a board, doing an exhaustive search for paths including up to 2 bends. Tries to avoid points in |board_coverage|. """ x1, y1 = start_point x2, y2 = end_point if x1 == x2 or y1 == y2: return [start_point, end_point] else: paths = [[(x1, y1), (x1, y2), (x2, y2)], [(x1, y1), (x2, y1), (x2, y2)]] x_sign = 1 if x1 <= x2 else -1 for x in xrange(x1 + x_sign * BOARD_GRID_SEPARATION, x2, x_sign * BOARD_GRID_SEPARATION): paths.append([(x1, y1), (x, y1), (x, y2), (x2, y2)]) y_sign = 1 if y1 <= y2 else -1 for y in xrange(y1 + y_sign * BOARD_GRID_SEPARATION, y2, y_sign * BOARD_GRID_SEPARATION): paths.append([(x1, y1), (x1, y), (x2, y), (x2, y2)]) return min(paths, key=lambda path: len(board_coverage & path_coverage( path)))
def find_wire_path_simple(board_coverage, start_point, end_point): """ Returns a list of tuples indicating a path from |start_point| to |end_point| on a board, doing an exhaustive search for paths including up to 2 bends. Tries to avoid points in |board_coverage|. """ x1, y1 = start_point x2, y2 = end_point if x1 == x2 or y1 == y2: return [start_point, end_point] else: paths = [[(x1, y1), (x1, y2), (x2, y2)], [(x1, y1), (x2, y1), (x2, y2)]] x_sign = 1 if x1 <= x2 else -1 for x in xrange(x1 + x_sign * BOARD_GRID_SEPARATION, x2, x_sign * BOARD_GRID_SEPARATION): paths.append([(x1, y1), (x, y1), (x, y2), (x2, y2)]) y_sign = 1 if y1 <= y2 else -1 for y in xrange(y1 + y_sign * BOARD_GRID_SEPARATION, y2, y_sign * BOARD_GRID_SEPARATION): paths.append([(x1, y1), (x1, y), (x2, y), (x2, y2)]) return min(paths, key=lambda path: len(board_coverage & path_coverage(path)))