double rightSide = Double.MIN_VALUE;
double bottomSide = Double.MIN_VALUE;
double leftSide = Double.MAX_VALUE;
double topSide = Double.MAX_VALUE;
for (int i = 0; i < entitiesToLayout.length; i++) {
InternalNode entity = entitiesToLayout[i];
if (entity.hasPreferredLocation()) {
continue;
}
if (includeNodeSize) {
leftSide = Math.min(entity.getInternalX() - entity.getInternalWidth() / 2, leftSide);
topSide = Math.min(entity.getInternalY() - entity.getInternalHeight() / 2, topSide);
rightSide = Math.max(entity.getInternalX() + entity.getInternalWidth() / 2, rightSide);
bottomSide = Math.max(entity.getInternalY() + entity.getInternalHeight() / 2, bottomSide);
} else {
leftSide = Math.min(entity.getInternalX(), leftSide);
topSide = Math.min(entity.getInternalY(), topSide);
rightSide = Math.max(entity.getInternalX(), rightSide);
bottomSide = Math.max(entity.getInternalY(), bottomSide);
}
}
return new DisplayIndependentRectangle(leftSide, topSide, rightSide - leftSide, bottomSide - topSide);
}