for (MapWaySegment in : inboundNLines) {
NetworkWaySegmentWorldObject inRenderable =
((NetworkWaySegmentWorldObject)in.getPrimaryRepresentation());
VectorXZ cutVector = in.getRightNormal();
inRenderable.setEndCutVector(cutVector);
cutVectors.add(cutVector.invert());
coords.add(in.getEndNode().getPos());
widths.add(inRenderable.getWidth());
}
for (MapWaySegment out : outboundNLines) {
NetworkWaySegmentWorldObject outRenderable =
((NetworkWaySegmentWorldObject)out.getPrimaryRepresentation());
VectorXZ cutVector = out.getRightNormal();
outRenderable.setStartCutVector(cutVector);
cutVectors.add(cutVector);
coords.add(out.getStartNode().getPos());
widths.add(outRenderable.getWidth());
}
/* move roads away from the intersection until they cannot overlap anymore,
* this is certain if the distance between their ends' center points
* is greater than the sum of their half-widths */
//TODO (performance) if roads were ordered by angle here already, this would be much faster -> only neighbors checked
boolean overlapPossible;
do {
overlapPossible = false;
overlapCheck:
for (int r1=0; r1 < coords.size(); r1++) {
for (int r2=r1+1; r2 < coords.size(); r2++) {
/* ignore overlapping (or almost overlapping) way segments
* as no reasonable amount of pushing would separate these */
if (VectorXZ.distance(connectedNSegments.get(r1).getDirection(),
connectedNSegments.get(r2).getDirection()) < 0.1
|| VectorXZ.distance(connectedNSegments.get(r1).getDirection(),
connectedNSegments.get(r2).getDirection().invert()) < 0.1) {
continue;
}
double distance = Math.abs(coords.get(r1).subtract(coords.get(r2)).length());
if (distance > 200) {
//TODO: proper error handling
System.err.println("distance has exceeded 200 at node " + node
+ "\n (representation: " + nodeRepresentation + ")");
// overlapCheck will remain false, no further size increase
break overlapCheck;
}
if (distance <= widths.get(r1)*0.5 + widths.get(r2)*0.5) {
overlapPossible = true;
break overlapCheck;
}
}
}
if (overlapPossible) {
/* push outwards */
coords.clear();
for (MapWaySegment in : inboundNLines) {
NetworkWaySegmentWorldObject inRenderable =
((NetworkWaySegmentWorldObject)in.getPrimaryRepresentation());
VectorXZ inVector = in.getDirection();
VectorXZ offsetModification = inVector.mult(-ROAD_PUSHING_STEP);
VectorXZ newEndOffset = inRenderable.getEndOffset().add(offsetModification);
inRenderable.setEndOffset(newEndOffset);
coords.add(in.getEndNode().getPos().add(newEndOffset));
}
for (MapWaySegment out : outboundNLines) {
NetworkWaySegmentWorldObject outRenderable =
((NetworkWaySegmentWorldObject)out.getPrimaryRepresentation());
VectorXZ outVector = out.getDirection();
VectorXZ offsetModification = outVector.mult(ROAD_PUSHING_STEP);
VectorXZ newStartOffset = outRenderable.getStartOffset().add(offsetModification);
outRenderable.setStartOffset(newStartOffset);
coords.add(out.getStartNode().getPos().add(newStartOffset));
}