it = iterator();
while(it.hasNext()){
TextGrid.Cell cell = (TextGrid.Cell) it.next();
if(boundaryGrid.isBlank(cell.x, cell.y)) continue;
CellSet boundarySet = boundaryGrid.fillContinuousArea(cell.x, cell.y, ' ');
//boundarySet.translate( this.getMinX() - 1, this.getMinY() - 1);
result.add(boundarySet);
}
return result;
}
/**
*
* Breaks that:
*
* +-----+
* | |
* + ---+-------------------
* | |
* +-----+
*
*
* into the following 3:
*
*
* +-----+
* | |
* + +
* | |
* +-----+
*
* ---
* -------------------
*
*
* @param grid
* @return a list of boundaries that are either open or closed but not mixed
* and they are equivalent to the this
*/
public ArrayList breakTrulyMixedBoundaries(TextGrid grid){
ArrayList result = new ArrayList();
CellSet visitedEnds = new CellSet();
TextGrid workGrid = TextGrid.makeSameSizeAs(grid);
grid.copyCellsTo(this, workGrid);
if (DEBUG){
System.out.println("Breaking truly mixed boundaries below:");
workGrid.printDebug();
}
Iterator it = iterator();
while(it.hasNext()){
TextGrid.Cell start = (TextGrid.Cell) it.next();
if(workGrid.isLinesEnd(start) && !visitedEnds.contains(start)){
if (DEBUG)
System.out.println("Starting new subshape:");
CellSet set = new CellSet();
set.add(start);
if(DEBUG) System.out.println("Added boundary "+start);
TextGrid.Cell previous = start;
TextGrid.Cell cell = null;
CellSet nextCells = workGrid.followCell(previous);
if(nextCells.size() == 0)
throw new IllegalArgumentException("This shape is either open but multipart or has only one cell, and cannot be processed by this method");
cell = (TextGrid.Cell) nextCells.getFirst();
set.add(cell);
if(DEBUG) System.out.println("Added boundary "+cell);
boolean finished = false;
if(workGrid.isLinesEnd(cell)){
visitedEnds.add(cell);
finished = true;
}
while(!finished){
nextCells = workGrid.followCell(cell, previous);
if(nextCells.size() == 1) {
set.add(cell);
if(DEBUG) System.out.println("Added boundary " + cell);
previous = cell;
cell = (TextGrid.Cell) nextCells.getFirst();
//if(!cell.equals(start) && grid.isPointCell(cell))
// s.addToPoints(makePointForCell(cell, workGrid, cellWidth, cellHeight, allRound));
if(workGrid.isLinesEnd(cell)){
visitedEnds.add(cell);
finished = true;
}
} else if(nextCells.size() > 1) {
finished = true;
}
}
result.add(set);
}
}
//substract all boundary sets from this CellSet
CellSet whatsLeft = new CellSet(this);
for(CellSet set : result) {
whatsLeft.subtractSet(set);
if(DEBUG) set.printAsGrid();
}
result.add(whatsLeft);
if(DEBUG) whatsLeft.printAsGrid();
return result;
}
public TextGrid makeIntoGrid(){
TextGrid grid = new TextGrid(getMaxX()+2, getMaxY()+2);
grid.fillCellsWith(this, '*');
return grid;
}
public CellSet makeScaledOneThirdEquivalent(){
TextGrid gridBig = this.makeIntoGrid();
gridBig.fillCellsWith(this, '*');
if (VERBOSE_DEBUG){
System.out.println("---> making ScaledOneThirdEquivalent of:");
gridBig.printDebug();
}
TextGrid gridSmall = new TextGrid((getMaxX() + 2) / 3, (getMaxY() + 2) / 3);
for(int y = 0; y < gridBig.getHeight(); y++){
for(int x = 0; x < gridBig.getWidth(); x++){
TextGrid.Cell cell = gridBig.new Cell(x, y);
if(!gridBig.isBlank(cell)) gridSmall.set(x/3, y/3, '*');
}
}
if (VERBOSE_DEBUG){
System.out.println("---> made into grid:");
gridSmall.printDebug();
}
return gridSmall.getAllNonBlank();
}
}