public TextGrid getSubGrid(int x, int y, int width, int height) { TextGrid grid = new TextGrid(width, height); for (int i = 0; i < height; i++) { grid.setRow(i, new StringBuilder(getRow(y + i).subSequence(x, x + width))); } return grid; }
public CellSet followCell(Cell cell, Cell blocked) { if (isIntersection(cell)) return followIntersection(cell, blocked); if (isCorner(cell)) return followCorner(cell, blocked); if (isLine(cell)) return followLine(cell, blocked); if (isStub(cell)) return followStub(cell, blocked); if (isCrossOnLine(cell)) return followCrossOnLine(cell, blocked); System.err.println("Umbiguous input at position " + cell + ":"); TextGrid subGrid = getTestingSubGrid(cell); subGrid.printDebug(); throw new RuntimeException("Cannot follow cell " + cell + ": cannot determine cell type"); }
public boolean equals(TextGrid grid) { if (grid.getHeight() != this.getHeight() || grid.getWidth() != this.getWidth()) { return false; } int height = grid.getHeight(); for (int i = 0; i < height; i++) { String row1 = this.getRow(i).toString(); String row2 = grid.getRow(i).toString(); if (!row1.equals(row2)) return false; } return true; }
public void copyCellsTo(CellSet cells, TextGrid grid) { for (Cell cell : cells) { grid.set(cell, this.get(cell)); } }
public boolean matchesAny(Cell cell, GridPatternGroup criteria) { TextGrid subGrid = getTestingSubGrid(cell); return subGrid.matchesAny(criteria); }
public TextGrid(TextGrid otherGrid) { rows = new ArrayList<StringBuilder>(); for (StringBuilder row : otherGrid.getRows()) { rows.add(new StringBuilder(row)); } }
public static TextGrid makeSameSizeAs(TextGrid grid) { return new TextGrid(grid.getWidth(), grid.getHeight()); }