use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.
the class UtilsTest method distanceTest.
/**
* Distance test using different directions.
*/
@Test
public void distanceTest() {
List<Pair<KVector, Boolean>> vectors = Lists.newArrayList();
// true if the nodes should collide
vectors.add(Pair.of(new KVector(-20, 20), true));
vectors.add(Pair.of(new KVector(-80, 0), false));
vectors.add(Pair.of(new KVector(-20, 9), false));
vectors.add(Pair.of(new KVector(0, 50), false));
vectors.add(Pair.of(new KVector(-9.99, 50), false));
vectors.add(Pair.of(new KVector(60, 60), false));
vectors.add(Pair.of(new KVector(-30, 50), true));
vectors.add(Pair.of(new KVector(-20, 130), true));
vectors.add(Pair.of(new KVector(-20, -21), false));
// Arrays.stream(new File(ElkUtil.debugFolderPath("test")).listFiles()).forEach(File::delete);
Node n1 = new Node(r1.getCenter(), r1);
for (Pair<KVector, Boolean> v : vectors) {
Node n2 = new Node(rectangles.get(12).getCenter(), new ElkRectangle(rectangles.get(12)));
double distance = n1.distance(n2, v.getFirst());
// if they should collide, move them, otherwise check whether the returned distance is infinite
if (v.getSecond()) {
// move + check shortest distance
n2.translate(v.getFirst().scaleToLength(distance));
assertTrue(CompareFuzzy.eq(ElkMath.shortestDistance(n1.rect, n2.rect), 0.0));
} else {
assertTrue(Double.isInfinite(distance));
}
}
}
use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.
the class Issue502Test method testLargeEnoughNode.
private void testLargeEnoughNode(final ElkNode node) {
ElkRectangle requiredSize = new ElkRectangle();
for (ElkNode child : node.getChildren()) {
ElkRectangle childRect = new ElkRectangle(child.getX(), child.getY(), child.getWidth(), child.getHeight());
requiredSize.union(childRect);
}
for (ElkEdge edge : node.getContainedEdges()) {
for (ElkEdgeSection section : edge.getSections()) {
for (ElkBendPoint bendPoint : section.getBendPoints()) {
requiredSize.width = Math.max(requiredSize.width, bendPoint.getX());
requiredSize.height = Math.max(requiredSize.height, bendPoint.getY());
}
}
}
assertTrue("Node not large enough for content. Size required: (" + requiredSize.width + ", " + requiredSize.height + "). " + "Actual size: (" + node.getWidth() + ", " + node.getHeight() + ")", node.getWidth() >= requiredSize.width && node.getHeight() >= requiredSize.height);
}
Aggregations