def insert_point(gp: GriddedPerm, cell: Cell, minimumdex: int) -> Iterator[Tuple[int, GriddedPerm]]: """Yield all possible gridded perms where a point is inserted into the given cell, where the minimum index is mindex if given. We insert right to left, to ensure that if a gp is made twice, that with the largest index is yielded first. Each gridded perm is yielded as a tuple, consisting of the idx of the newly inserted point and the gp.""" # Find the bounding box of where the point can be inserted. mindex, maxdex, minval, maxval = gp.get_bounding_box(cell) # We make sure we only insert to the right of where the last # point was inserted into the cell. mindex = max(mindex, minimumdex) for idx, val in product(range(maxdex, mindex - 1, -1), range(minval, maxval + 1)): nextgp = gp.insert_specific_point(cell, idx, val) yield idx, nextgp
def _stretch_gridded_perm(self, gp: GriddedPerm, cell: Cell) -> Iterable[GriddedPerm]: """ Return all of the possible ways that a gridded permutation can be stretched assuming that a point is placed into the given cell. """ mindex, maxdex, minval, maxval = gp.get_bounding_box(cell) if not self.own_col: maxdex = mindex elif not self.own_row: maxval = minval res = [ self._gridded_perm_translation(gp, (i, j)) for i in range(mindex, maxdex + 1) for j in range(minval, maxval + 1) ] for i in gp.points_in_cell(cell): res.append(self._gridded_perm_translation_with_point(gp, i)) return res