for (MapAreaSegment area1Segment : area1Segments) {
for (MapAreaSegment area2Segment : area2Segments) {
if (area1Segment.sharesBothNodes(area2Segment)) {
MapOverlapAA newOverlap =
new MapOverlapAA(area1, area2, MapOverlapType.SHARE_SEGMENT);
area1.addOverlap(newOverlap);
area2.addOverlap(newOverlap);
return;
}
}
}
/* calculate whether one area contains the other
* or whether their outlines intersect (or neither) */
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;
}
}
/* add an overlap if detected */
if (contains1 || contains2 || intersects) {
/* add the overlap */
MapOverlapAA newOverlap = null;
if (contains1) {
newOverlap = new MapOverlapAA(area2, area1, MapOverlapType.CONTAIN);
} else if (contains2) {
newOverlap = new MapOverlapAA(area1, area2, MapOverlapType.CONTAIN);
} else {
newOverlap = new MapOverlapAA(area1, area2, MapOverlapType.INTERSECT);
}
area1.addOverlap(newOverlap);
area2.addOverlap(newOverlap);