{ /* calculate centerline */
centerlineXZ = new ArrayList<VectorXZ>();
final VectorXZ start = getStartWithOffset();
final VectorXZ end = getEndWithOffset();
centerlineXZ.add(start);
connectors.add(new EleConnector(start,
segment.getStartNode(), getGroundState(segment.getStartNode())));
// add intersections along the centerline
for (MapOverlap<?,?> overlap : segment.getOverlaps()) {
if (overlap.getOther(segment).getPrimaryRepresentation() == null)
continue;
if (overlap instanceof MapIntersectionWW) {
MapIntersectionWW intersection = (MapIntersectionWW) overlap;
if (GeometryUtil.isBetween(intersection.pos, start, end)) {
centerlineXZ.add(intersection.pos);
connectors.add(new EleConnector(intersection.pos,
null, getGroundState()));
}
} else if (overlap instanceof MapOverlapWA
&& overlap.type == MapOverlapType.INTERSECT) {
if (!(overlap.getOther(segment).getPrimaryRepresentation()
instanceof AbstractAreaWorldObject)) continue;
MapOverlapWA overlapWA = (MapOverlapWA) overlap;
for (int i = 0; i < overlapWA.getIntersectionPositions().size(); i++) {
VectorXZ pos = overlapWA.getIntersectionPositions().get(i);
if (GeometryUtil.isBetween(pos, start, end)) {
centerlineXZ.add(pos);
connectors.add(new EleConnector(pos,
null, getGroundState()));
}
}
}
}
// finish the centerline
centerlineXZ.add(end);
connectors.add(new EleConnector(end,
segment.getEndNode(), getGroundState(segment.getEndNode())));
if (centerlineXZ.size() > 3) {
// sort by distance from start
Collections.sort(centerlineXZ, new Comparator<VectorXZ>() {
@Override
public int compare(VectorXZ v1, VectorXZ v2) {
return Double.compare(
distanceSquared(v1, start),
distanceSquared(v2, start));
}
});
}
}
{ /* calculate left and right outlines */
leftOutlineXZ = new ArrayList<VectorXZ>(centerlineXZ.size());
rightOutlineXZ = new ArrayList<VectorXZ>(centerlineXZ.size());
assert centerlineXZ.size() >= 2;
double halfWidth = getWidth() * 0.5f;
VectorXZ centerStart = centerlineXZ.get(0);
leftOutlineXZ.add(centerStart.add(startCutVector.mult(-halfWidth)));
rightOutlineXZ.add(centerStart.add(startCutVector.mult(halfWidth)));
connectors.add(new EleConnector(leftOutlineXZ.get(0),
segment.getStartNode(), getGroundState(segment.getStartNode())));
connectors.add(new EleConnector(rightOutlineXZ.get(0),
segment.getStartNode(), getGroundState(segment.getStartNode())));
for (int i = 1; i < centerlineXZ.size() - 1; i++) {
leftOutlineXZ.add(centerlineXZ.get(i).add(segment.getRightNormal().mult(-halfWidth)));
rightOutlineXZ.add(centerlineXZ.get(i).add(segment.getRightNormal().mult(halfWidth)));
connectors.add(new EleConnector(leftOutlineXZ.get(i),
null, getGroundState()));
connectors.add(new EleConnector(rightOutlineXZ.get(i),
null, getGroundState()));
}
VectorXZ centerEnd = centerlineXZ.get(centerlineXZ.size() - 1);
leftOutlineXZ.add(centerEnd.add(endCutVector.mult(-halfWidth)));
rightOutlineXZ.add(centerEnd.add(endCutVector.mult(halfWidth)));
connectors.add(new EleConnector(leftOutlineXZ.get(leftOutlineXZ.size() - 1),
segment.getEndNode(), getGroundState(segment.getEndNode())));
connectors.add(new EleConnector(rightOutlineXZ.get(rightOutlineXZ.size() - 1),
segment.getEndNode(), getGroundState(segment.getEndNode())));