float [][] wallSidePoints = getWallSidePoints(wallSide);
float [] textureReferencePoint = wallSide == LEFT_WALL_SIDE
? wallSidePoints [0]
: wallSidePoints [wallSidePoints.length - 1];
Shape wallShape = getShape(wallSidePoints);
Area wallArea = new Area(wallShape);
float wallHeightAtStart = getWallHeightAtStart();
float wallHeightAtEnd = getWallHeightAtEnd();
float maxWallHeight = Math.max(wallHeightAtStart, wallHeightAtEnd);
// Compute wall angles and top line factors
Wall wall = (Wall)getUserData();
double wallYawAngle = Math.atan2(wall.getYEnd() - wall.getYStart(), wall.getXEnd() - wall.getXStart());
double cosWallYawAngle = Math.cos(wallYawAngle);
double sinWallYawAngle = Math.sin(wallYawAngle);
double wallXStartWithZeroYaw = cosWallYawAngle * wall.getXStart() + sinWallYawAngle * wall.getYStart();
double wallXEndWithZeroYaw = cosWallYawAngle * wall.getXEnd() + sinWallYawAngle * wall.getYEnd();
boolean roundWall = wall.getArcExtent() != null && wall.getArcExtent() != 0;
double topLineAlpha;
double topLineBeta;
if (wallHeightAtStart == wallHeightAtEnd) {
topLineAlpha = 0;
topLineBeta = wallHeightAtStart;
} else {
topLineAlpha = (wallHeightAtEnd - wallHeightAtStart) / (wallXEndWithZeroYaw - wallXStartWithZeroYaw);
topLineBeta = wallHeightAtStart - topLineAlpha * wallXStartWithZeroYaw;
}
// Search which doors or windows intersect with this wall side
List<DoorOrWindowArea> windowIntersections = new ArrayList<DoorOrWindowArea>();
for (HomePieceOfFurniture piece : getVisibleDoorsAndWindows(this.home.getFurniture())) {
if (piece.getElevation() < maxWallHeight) {
Shape pieceShape = getShape(piece.getPoints());
Area pieceArea = new Area(pieceShape);
Area intersectionArea = new Area(wallShape);
intersectionArea.intersect(pieceArea);
if (!intersectionArea.isEmpty()) {
windowIntersections.add(new DoorOrWindowArea(intersectionArea, Arrays.asList(new HomePieceOfFurniture [] {piece})));
// Remove from wall area the piece shape
wallArea.subtract(pieceArea);
}
}
}
// Refine intersections in case some doors or windows are superimposed
if (windowIntersections.size() > 1) {
// Search superimposed windows
for (int windowIndex = 0; windowIndex < windowIntersections.size(); windowIndex++) {
DoorOrWindowArea windowIntersection = windowIntersections.get(windowIndex);
List<DoorOrWindowArea> otherWindowIntersections = new ArrayList<DoorOrWindowArea>();
int otherWindowIndex = 0;
for (DoorOrWindowArea otherWindowIntersection : windowIntersections) {
if (windowIntersection.getArea().isEmpty()) {
break;
} else if (otherWindowIndex > windowIndex) { // Avoid search twice the intersection between two items
Area windowsIntersectionArea = new Area(otherWindowIntersection.getArea());
windowsIntersectionArea.intersect(windowIntersection.getArea());
if (!windowsIntersectionArea.isEmpty()) {
// Remove intersection from wall area
otherWindowIntersection.getArea().subtract(windowsIntersectionArea);
windowIntersection.getArea().subtract(windowsIntersectionArea);
// Create a new area for the intersection
List<HomePieceOfFurniture> doorsOrWindows = new ArrayList<HomePieceOfFurniture>(windowIntersection.getDoorsOrWindows());