glm = context.get(GraphSynchronizationHints.GRAPH_LAYER_MANAGER);
}
- public void create(WriteGraph graph, double[] start, double[] end) throws DatabaseException {
+ public void create(WriteGraph graph, double[] start, double[] end, double padding) throws DatabaseException {
DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
// 2. Add vertices
Collection<Resource> vertices = graph.syncRequest(new ObjectsWithType(diagramResource, Layer0.getInstance(graph).ConsistsOf, DistrictNetworkResource.getInstance(graph).Vertex));
- Resource startVertex = getOrCreateVertex(graph, vertices, start);
- Resource endVertex = getOrCreateVertex(graph, vertices, end);
+ Resource startVertex = getOrCreateVertex(graph, vertices, start, padding);
+ Resource endVertex = getOrCreateVertex(graph, vertices, end, padding);
graph.claim(edge, DN.HasStartVertex, startVertex);
graph.claim(edge, DN.HasEndVertex, endVertex);
glm.putElementOnVisibleLayers(diagram, graph, res);
}
- private Resource getOrCreateVertex(WriteGraph graph, Collection<Resource> vertices, double[] coords) throws DatabaseException {
+ private Resource getOrCreateVertex(WriteGraph graph, Collection<Resource> vertices, double[] coords, double padding) throws DatabaseException {
Resource vertex = null;
+ double halfPadding = padding / 2;
for (Resource vertx : vertices) {
double[] existingCoords = graph.getRelatedValue2(vertx, DiagramResource.getInstance(graph).HasLocation, Bindings.DOUBLE_ARRAY);
- Rectangle2D existing = new Rectangle2D.Double(existingCoords[0], existingCoords[1], 1, 1);
- Rectangle2D tobecreated = new Rectangle2D.Double(coords[0], coords[1], 1, 1);
+ Rectangle2D existing = new Rectangle2D.Double(existingCoords[0] - halfPadding, existingCoords[1] - halfPadding, padding, padding);
+ Rectangle2D tobecreated = new Rectangle2D.Double(coords[0] - halfPadding, coords[1] - halfPadding, padding, padding);
if (existing.intersects(tobecreated)) {
vertex = vertx;
break;