this.faces = new HashMap<>( facesMap.size() );
for (Map.Entry<Set<Pipe>, Integer> faceAndId : facesMap.entrySet()) {
/* Per ogni faccia ... */
Pipe firstPipe = faceAndId.getKey().iterator().next();
Junction lastJunction = levelMap.getEdgeSource( firstPipe );
Pipe lastPipe = null;
GeneralPath faceShape = new GeneralPath();
faceShape.moveTo( lastJunction.getPosition().x, lastJunction.getPosition().y );
while ( ! firstPipe.equals( lastPipe ) ) {
/* Aggiunge la linea*/
Pipe nextPipe = null;
final Set<Pipe> connectedSegments = new HashSet<>( levelMap.edgesOf( lastJunction ) );
if ( lastPipe == null ) {
/* È il primo loop */
lastPipe = firstPipe;
}
/* Scarta il segmento già percorso */
connectedSegments.remove( lastPipe );
for (Pipe perimeterSegment : faceAndId.getKey()) {
/* Tra tutti i segmenti del perimetro seleziona solo quello che confina con il vertice corrente */
if ( connectedSegments.contains( perimeterSegment ) ) {
nextPipe = perimeterSegment;
break;
}
}
if ( nextPipe == null ) {
if( THROW_EXCEPTION_ON_FACES_ERROR ) {
throw new IllegalArgumentException("Invalid faces set");
} else {
lastPipe = firstPipe;
faceShape.closePath();
}
} else {
lastPipe = nextPipe;
final Junction edgeSource = levelMap.getEdgeSource( nextPipe );
lastJunction = edgeSource.equals( lastJunction ) ? levelMap
.getEdgeTarget( nextPipe ) : edgeSource;
final Point junctionPosition = lastJunction.getPosition();
faceShape.lineTo( junctionPosition.x, junctionPosition.y );
}