boolean contains1 = false;
boolean contains2 = false;
boolean intersects = false;
{
final PolygonWithHolesXZ polygon1 = area1.getPolygon();
final PolygonWithHolesXZ polygon2 = area2.getPolygon();
/* determine common nodes */
Set<VectorXZ> commonNodes = new HashSet<VectorXZ>();
for (SimplePolygonXZ p : polygon1.getPolygons()) {
commonNodes.addAll(p.getVertices());
}
Set<VectorXZ> nodes2 = new HashSet<VectorXZ>();
for (SimplePolygonXZ p : polygon2.getPolygons()) {
nodes2.addAll(p.getVertices());
}
commonNodes.retainAll(nodes2);
/* check whether the areas' outlines intersects somewhere
* else than just at the common node(s).
*/
intersectionPosCheck:
for (VectorXZ pos : polygon1.intersectionPositions(polygon2)) {
boolean trueIntersection = true;
for (VectorXZ commonNode : commonNodes) {
if (distance(pos, commonNode) < 0.01) {
trueIntersection = false;
}
}
if (trueIntersection) {
intersects = true;
break intersectionPosCheck;
}
}
/* check whether one area contains the other */
if (polygon1.contains(polygon2.getOuter())) {
contains1 = true;
} else if (polygon2.contains(polygon1.getOuter())) {
contains2 = true;
}
}