1 package org.simantics.debug.graphical.layout;
3 public class LayoutAlgorithm {
5 final double OPTIMAL_DISTANCE = 150.0;
7 final double K = C / OPTIMAL_DISTANCE;
9 final double Q = C * OPTIMAL_DISTANCE * OPTIMAL_DISTANCE;
10 final double TOLERANCE = 1e-3;
11 final int MAX_ITERATIONS = 10000;
12 final double MAX_MOVE2 = 40000.0;
22 public LayoutAlgorithm(int[][] neighbors) {
23 this.size = neighbors.length;
24 this.neighbors = neighbors;
25 this.posX = new double[size];
26 this.posY = new double[size];
27 this.forceX = new double[size];
28 this.forceY = new double[size];
31 public double[] getPosX() {
35 public double[] getPosY() {
39 private void computeForces() {
40 for(int i=0;i<size;++i) {
46 for(int j=0;j<size;++j)
48 double dx = posX[j] - x;
49 double dy = posY[j] - y;
50 double l2 = dx*dx + dy*dy;
51 /*double l = Math.sqrt(l2);
57 for(int j : neighbors[i]) {
58 double dx = posX[j] - x;
59 double dy = posY[j] - y;
60 double l2 = dx*dx + dy*dy;
61 double l = Math.sqrt(l2);
71 private boolean converged() {
72 for(int i=0;i<size;++i) {
73 double fx = forceX[i];
74 double fy = forceY[i];
75 double f2 = fx*fx + fy*fy;
82 private void moveAll() {
83 for(int i=0;i<size;++i) {
84 double fx = forceX[i];
85 double fy = forceY[i];
86 double f2 = fx*fx + fy*fy;
88 double s = Math.sqrt(MAX_MOVE2 / f2);
98 public void optimize() {
101 for(int iter=0;iter<MAX_ITERATIONS;++iter) {