public void replacePointMarkersOnLine() { int width = getWidth(); int height = getHeight(); for (int yi = 0; yi < height; yi++) { for (int xi = 0; xi < width; xi++) { char c = get(xi, yi); Cell cell = new Cell(xi, yi); if (StringUtils.isOneOf(c, pointMarkers) && isStarOnLine(cell)) { boolean isOnHorizontalLine = false; if (StringUtils.isOneOf(get(cell.getEast()), horizontalLines)) isOnHorizontalLine = true; if (StringUtils.isOneOf(get(cell.getWest()), horizontalLines)) isOnHorizontalLine = true; boolean isOnVerticalLine = false; if (StringUtils.isOneOf(get(cell.getNorth()), verticalLines)) isOnVerticalLine = true; if (StringUtils.isOneOf(get(cell.getSouth()), verticalLines)) isOnVerticalLine = true; if (isOnHorizontalLine && isOnVerticalLine) { set(xi, yi, '+'); if (DEBUG) System.out.println("replaced marker on line '" + c + "' with +"); } else if (isOnHorizontalLine) { set(xi, yi, '-'); if (DEBUG) System.out.println("replaced marker on line '" + c + "' with -"); } else if (isOnVerticalLine) { set(xi, yi, '|'); if (DEBUG) System.out.println("replaced marker on line '" + c + "' with |"); } } } } }
public void removeColorCodes() { for (CellColorPair o : findColorCodes()) { Cell cell = o.cell; set(cell, ' '); cell = cell.getEast(); set(cell, ' '); cell = cell.getEast(); set(cell, ' '); cell = cell.getEast(); set(cell, ' '); } }
public void replaceBullets() { int width = getWidth(); int height = getHeight(); for (int yi = 0; yi < height; yi++) { for (int xi = 0; xi < width; xi++) { Cell cell = new Cell(xi, yi); if (isBullet(cell)) { set(cell, ' '); set(cell.getEast(), '\u2022'); } } } }
private CellSet seedFillOld(Cell seed, char newChar) { CellSet cellsFilled = new CellSet(); char oldChar = get(seed); if (oldChar == newChar) return cellsFilled; if (isOutOfBounds(seed)) return cellsFilled; Stack<Cell> stack = new Stack<Cell>(); stack.push(seed); while (!stack.isEmpty()) { Cell cell = stack.pop(); set(cell, newChar); cellsFilled.add(cell); Cell nCell = cell.getNorth(); Cell sCell = cell.getSouth(); Cell eCell = cell.getEast(); Cell wCell = cell.getWest(); if (get(nCell) == oldChar) stack.push(nCell); if (get(sCell) == oldChar) stack.push(sCell); if (get(eCell) == oldChar) stack.push(eCell); if (get(wCell) == oldChar) stack.push(wCell); } return cellsFilled; }
public void removeArrowheads() { int width = getWidth(); int height = getHeight(); for (int yi = 0; yi < height; yi++) { for (int xi = 0; xi < width; xi++) { Cell cell = new Cell(xi, yi); if (isArrowhead(cell)) set(cell, ' '); } } }
/** * Replaces letters or numbers that are on horizontal or vertical lines, with the appropriate * character that will make the line continuous (| for vertical and - for horizontal lines) */ public void replaceTypeOnLine() { int width = getWidth(); int height = getHeight(); for (int yi = 0; yi < height; yi++) { for (int xi = 0; xi < width; xi++) { char c = get(xi, yi); if (Character.isLetterOrDigit(c)) { boolean isOnHorizontalLine = isOnHorizontalLine(xi, yi); boolean isOnVerticalLine = isOnVerticalLine(xi, yi); if (isOnHorizontalLine && isOnVerticalLine) { set(xi, yi, '+'); if (DEBUG) System.out.println("replaced type on line '" + c + "' with +"); } else if (isOnHorizontalLine) { set(xi, yi, '-'); if (DEBUG) System.out.println("replaced type on line '" + c + "' with -"); } else if (isOnVerticalLine) { set(xi, yi, '|'); if (DEBUG) System.out.println("replaced type on line '" + c + "' with |"); } } } } }
public void removeBoundaries() { ArrayList<Cell> toBeRemoved = new ArrayList<Cell>(); int width = getWidth(); int height = getHeight(); for (int yi = 0; yi < height; yi++) { for (int xi = 0; xi < width; xi++) { Cell cell = new Cell(xi, yi); if (isBoundary(cell)) toBeRemoved.add(cell); } } // remove in two stages, because decision of // isBoundary depends on contants of surrounding // cells for (Object aToBeRemoved : toBeRemoved) { Cell cell = (Cell) aToBeRemoved; set(cell, ' '); } }
/** * Locates and returns the '*' boundaries that we would encounter if we did a flood-fill at <code> * seed</code>. */ public CellSet findBoundariesExpandingFrom(Cell seed) { CellSet boundaries = new CellSet(); char oldChar = get(seed); if (isOutOfBounds(seed)) return boundaries; char newChar = 1; // TODO: kludge Stack<Cell> stack = new Stack<Cell>(); stack.push(seed); while (!stack.isEmpty()) { Cell cell = stack.pop(); set(cell, newChar); Cell nCell = cell.getNorth(); Cell sCell = cell.getSouth(); Cell eCell = cell.getEast(); Cell wCell = cell.getWest(); if (get(nCell) == oldChar) stack.push(nCell); else if (get(nCell) == '*') boundaries.add(nCell); if (get(sCell) == oldChar) stack.push(sCell); else if (get(sCell) == '*') boundaries.add(sCell); if (get(eCell) == oldChar) stack.push(eCell); else if (get(eCell) == '*') boundaries.add(eCell); if (get(wCell) == oldChar) stack.push(wCell); else if (get(wCell) == '*') boundaries.add(wCell); } return boundaries; }
/** Fills all the cells in <code>cells</code> with <code>c</code> */ public void fillCellsWith(Iterable<Cell> cells, char c) { for (Cell cell : cells) { set(cell.x, cell.y, c); } }
public void copyCellsTo(CellSet cells, TextGrid grid) { for (Cell cell : cells) { grid.set(cell, this.get(cell)); } }
public void set(Cell cell, char c) { set(cell.x, cell.y, c); }