use of org.eclipse.zest.layouts.dataStructures.DisplayIndependentDimension in project archi by archimatetool.
the class AbstractLayoutAlgorithm method getMinimumDistance.
/**
* minDistance is the closest that any two points are together.
* These two points become the center points for the two closest nodes,
* which we wish to make them as big as possible without overlapping.
* This will be the maximum of minDistanceX and minDistanceY minus a bit, lets say 20%
*
* We make the recommended node size a square for convenience.
*
* _______
* | |
* | |
* | + |
* | |\ |
* |___|_\_|_____
* | | \ |
* | | \ |
* +-|---+ |
* | |
* |_______|
*/
private DisplayIndependentDimension getMinimumDistance(InternalNode[] entitiesToLayout) {
DisplayIndependentDimension horAndVertdistance = new DisplayIndependentDimension(Double.MAX_VALUE, Double.MAX_VALUE);
// the minimum distance between all the nodes
double minDistance = Double.MAX_VALUE;
// TODO: Very Slow!
for (int i = 0; i < entitiesToLayout.length; i++) {
InternalNode layoutEntity1 = entitiesToLayout[i];
double x1 = layoutEntity1.getInternalX();
double y1 = layoutEntity1.getInternalY();
for (int j = i + 1; j < entitiesToLayout.length; j++) {
InternalNode layoutEntity2 = entitiesToLayout[j];
double x2 = layoutEntity2.getInternalX();
double y2 = layoutEntity2.getInternalY();
double distanceX = Math.abs(x1 - x2);
double distanceY = Math.abs(y1 - y2);
double distance = Math.sqrt(Math.pow(distanceX, 2) + Math.pow(distanceY, 2));
if (distance < minDistance) {
minDistance = distance;
horAndVertdistance.width = distanceX;
horAndVertdistance.height = distanceY;
}
}
}
return horAndVertdistance;
}
use of org.eclipse.zest.layouts.dataStructures.DisplayIndependentDimension in project archi by archimatetool.
the class AbstractLayoutAlgorithm method getNodeSize.
/**
* Returns the maximum possible node size as a percentage of the width or height in current coord system.
*/
private double getNodeSize(InternalNode[] entitiesToLayout) {
double width, height;
if (entitiesToLayout.length == 1) {
width = 0.8;
height = 0.8;
} else {
DisplayIndependentDimension minimumDistance = getMinimumDistance(entitiesToLayout);
width = 0.8 * minimumDistance.width;
height = 0.8 * minimumDistance.height;
}
return Math.max(width, height);
}
Aggregations