for (Edge edge : graph.getEdges())
{
RectangularShape source = vertexMap.get(graph.getSource(edge));
RectangularShape destination = vertexMap.get(graph.getDest(edge));
PolyLine line = new PolyLine(new Line2D.Double(source.getCenterX(),
source.getCenterY(), destination.getCenterX(), destination
.getCenterY()));
edgeMap.put(edge, new Pair<RectangularShape, PolyLine>(null, line));
polyLines.add(line);
}
// avoid collisions with the vertices
for (PolyLine line : polyLines)
{
for (RectangleWithRef<Vertex,?> vertex : nodeMapping.values())
{
int equalityDistance = 5;
if (line.intersects(vertex)
&& !(line.startsWith(vertex.getCenter(), equalityDistance) || (line
.endsWith(vertex.getCenter(), equalityDistance))))
{
// determine which diagonale part is intersected and add another
// point to the polyline
Line2D.Double diagonalePart = vertex.getUpperLeftDiagonaleLine();
Pair<Line2D, Point2D> intersection = line
.getIntersection(diagonalePart);
if (intersection != null)
{
line.splitLine(intersection.getFirst(), GeometryBoostUtils
.translate(vertex.getUpperLeftCorner(),
GeometryBoostUtils.getVector(vertex.getCenter(),
intersection.getSecond())));
}
diagonalePart = vertex.getUpperRightDiagonaleLine();
intersection = line.getIntersection(diagonalePart);
if (intersection != null)
{
line.splitLine(intersection.getFirst(), GeometryBoostUtils
.translate(vertex.getUpperRightCorner(),
GeometryBoostUtils.getVector(vertex.getCenter(),
intersection.getSecond())));
}
diagonalePart = vertex.getLowerRightDiagonaleLine();
intersection = line.getIntersection(diagonalePart);
if (intersection != null)
{
line.splitLine(intersection.getFirst(), GeometryBoostUtils
.translate(vertex.getLowerRightCorner(),
GeometryBoostUtils.getVector(vertex.getCenter(),
intersection.getSecond())));
}
diagonalePart = vertex.getLowerLeftDiagonaleLine();
intersection = line.getIntersection(diagonalePart);
if (intersection != null)
{
line.splitLine(intersection.getFirst(), GeometryBoostUtils
.translate(vertex.getLowerLeftCorner(),
GeometryBoostUtils.getVector(vertex.getCenter(),
intersection.getSecond())));
}