use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.
the class CompactionTest method testRightGroupCompaction.
/**
* The connection indicates a grouping, not an edge.
*
* +--+
* | | +--+
* +--+ | |
* | +--+
* |
* +--+
* | |
* +--+
*/
@Test
public void testRightGroupCompaction() {
CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
CTestNode left = new CTestNode(new ElkRectangle(0, 5, 20, 20));
graph.cNodes.add(left);
CTestNode upperRight = new CTestNode(new ElkRectangle(40, 0, 20, 20));
graph.cNodes.add(upperRight);
CTestNode lowerRight = new CTestNode(new ElkRectangle(10, 25, 20, 20));
graph.cNodes.add(lowerRight);
CGroup group = new CGroup(left, lowerRight);
graph.cGroups.add(group);
compacter(graph).changeDirection(Direction.RIGHT).compact().finish();
assertEquals(15, left.hitbox.x, EPSILON);
assertEquals(40, upperRight.hitbox.x, EPSILON);
assertEquals(25, lowerRight.hitbox.x, EPSILON);
}
use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.
the class CompactionTest method testHorizontalSpacingDuringVerticalCompaction.
/**
* "Two" is "center node". Node "one" is supposed to be blocked by "two", while "three" can move freely.
*/
@Test
public void testHorizontalSpacingDuringVerticalCompaction() {
CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
CTestNodeSpacing one = new CTestNodeSpacing(new ElkRectangle(16, 150, 20, 20), 5d, 0d);
graph.cNodes.add(one);
CTestNodeSpacing two = new CTestNodeSpacing(new ElkRectangle(40, 0, 20, 20), 10d, 0d);
graph.cNodes.add(two);
CTestNodeSpacing three = new CTestNodeSpacing(new ElkRectangle(76, 150, 20, 20), 15d, 0d);
graph.cNodes.add(three);
compacter(graph).changeDirection(Direction.UP).compact().finish();
assertEquals(20, one.hitbox.y, EPSILON);
assertEquals(0, two.hitbox.y, EPSILON);
assertEquals(0, three.hitbox.y, EPSILON);
}
use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.
the class ComponentsToCGraphTransformer method transform.
/* -----------------------------------------------------------
* Graph Transformation
* ----------------------------------------------------------- */
@Override
public CGraph transform(final IConnectedComponents<N, E> ccs) {
cGraph = new CGraph(EnumSet.allOf(Direction.class));
for (IComponent<N, E> comp : ccs.getComponents()) {
CGroup group = new CGroup();
cGraph.cGroups.add(group);
// convert the hull of the graph's elements without external edges
for (ElkRectangle rect : comp.getHull()) {
CRectNode rectNode = new CRectNode(rect);
setLock(rectNode, comp.getExternalExtensionSides());
if (!oldPosition.containsKey(comp)) {
oldPosition.put(comp, new KVector(rect.x, rect.y));
offsets.put(comp, rectNode);
}
cGraph.cNodes.add(rectNode);
group.addCNode(rectNode);
}
// they can be added to the CGraph on demand later on
for (IExternalExtension<E> ee : comp.getExternalExtensions()) {
CRectNode rectNode = new CRectNode(ee.getRepresentor());
externalExtensions.put(ee, Pair.of(group, rectNode));
setLock(rectNode, comp.getExternalExtensionSides());
// placeholder
if (ee.getPlaceholder() != null) {
CRectNode rectPlaceholder = new CRectNode(ee.getPlaceholder(), 1d);
setLock(rectPlaceholder, comp.getExternalExtensionSides());
CGroup dummyGroup = new CGroup();
dummyGroup.addCNode(rectPlaceholder);
externalPlaceholder.put(ee.getDirection(), Pair.of(group, rectPlaceholder));
}
}
}
return cGraph;
}
use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.
the class ComponentsCompactor method transformLEdge.
/**
* Converts an external edge to an external extension. While doing so, the the original edge
* contributes three things as explained in the code.
*/
private IExternalExtension<LEdge> transformLEdge(final LEdge externalEdge, final Hullpoints hullPoints, final OuterSegments outerSegments) {
InternalExternalExtension externalExtension = new InternalExternalExtension(externalEdge);
// #1 convert the edge's path into a set of segments
Segments segments = edgeToSegments(externalEdge, externalExtension);
// #2 all 'inner' segments contribute to the hull (consider the edge's thickness)
double thickness = Math.max(externalEdge.getProperty(LayeredOptions.EDGE_THICKNESS).doubleValue(), 1);
for (Pair<KVector, KVector> segment : segments.innerSegments) {
ElkRectangle rect = segmentToRectangle(segment.getFirst(), segment.getSecond(), thickness);
hullPoints.add(rect);
}
// #3 the 'outer' segment, being the segment that actually connects to the external port,
// contributes to the 'union external segment' that we create
// for one direction of the component
PortSide side = externalExtension.externalPortSide;
ElkRectangle outerSegmentRect = segmentToRectangle(segments.outerSegment.getFirst(), segments.outerSegment.getSecond(), thickness);
if (side == PortSide.WEST || side == PortSide.EAST) {
outerSegments.min[side.ordinal()] = Math.min(outerSegments.min[side.ordinal()], outerSegmentRect.y);
outerSegments.max[side.ordinal()] = Math.max(outerSegments.max[side.ordinal()], outerSegmentRect.y + outerSegmentRect.height);
} else {
outerSegments.min[side.ordinal()] = Math.min(outerSegments.min[side.ordinal()], outerSegmentRect.x);
outerSegments.max[side.ordinal()] = Math.max(outerSegments.max[side.ordinal()], outerSegmentRect.x + outerSegmentRect.width);
}
// extent
double extent = Double.NEGATIVE_INFINITY;
LMargin margins = externalExtension.externalPort.getNode().getMargin();
switch(side) {
case WEST:
extent = margins.right;
break;
case EAST:
extent = margins.left;
break;
case NORTH:
extent = margins.bottom;
break;
case SOUTH:
extent = margins.top;
break;
}
outerSegments.extent[side.ordinal()] = Math.max(outerSegments.extent[side.ordinal()], extent);
return externalExtension;
}
use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.
the class EndLabelPreprocessor method updateNodeMargins.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Node Margins
/**
* Updates the node's margins to account for its end labels.
*/
private void updateNodeMargins(final LNode node, final LabelCell[] labelCells) {
LMargin nodeMargin = node.getMargin();
KVector nodeSize = node.getSize();
// Calculate the rectangle that describes the node's current margin
ElkRectangle nodeMarginRectangle = new ElkRectangle(-nodeMargin.left, -nodeMargin.top, nodeMargin.left + nodeSize.x + nodeMargin.right, nodeMargin.top + nodeSize.y + nodeMargin.bottom);
// Union the rectangle with each rectangle that describes a label cell
for (LabelCell labelCell : labelCells) {
if (labelCell != null) {
nodeMarginRectangle.union(labelCell.getCellRectangle());
}
}
// Reapply the new rectangle to the margin
nodeMargin.left = -nodeMarginRectangle.x;
nodeMargin.top = -nodeMarginRectangle.y;
nodeMargin.right = nodeMarginRectangle.width - nodeMargin.left - nodeSize.x;
nodeMargin.bottom = nodeMarginRectangle.height - nodeMargin.top - nodeSize.y;
}
Aggregations