X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.debug.graphical%2Fsrc%2Forg%2Fsimantics%2Fdebug%2Fgraphical%2Flayout%2FLayoutAlgorithm.java;fp=bundles%2Forg.simantics.debug.graphical%2Fsrc%2Forg%2Fsimantics%2Fdebug%2Fgraphical%2Flayout%2FLayoutAlgorithm.java;h=1fe13a433b667cbb4c06a39af69abb7a8036ced8;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/layout/LayoutAlgorithm.java b/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/layout/LayoutAlgorithm.java new file mode 100644 index 000000000..1fe13a433 --- /dev/null +++ b/bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/layout/LayoutAlgorithm.java @@ -0,0 +1,107 @@ +package org.simantics.debug.graphical.layout; + +public class LayoutAlgorithm { + + final double OPTIMAL_DISTANCE = 150.0; + final double C = 0.1; + final double K = C / OPTIMAL_DISTANCE; + final double G = K; + final double Q = C * OPTIMAL_DISTANCE * OPTIMAL_DISTANCE; + final double TOLERANCE = 1e-3; + final int MAX_ITERATIONS = 10000; + final double MAX_MOVE2 = 40000.0; + + int size; + double[] posX; + double[] posY; + double[] forceX; + double[] forceY; + + int[][] neighbors; + + public LayoutAlgorithm(int[][] neighbors) { + this.size = neighbors.length; + this.neighbors = neighbors; + this.posX = new double[size]; + this.posY = new double[size]; + this.forceX = new double[size]; + this.forceY = new double[size]; + } + + public double[] getPosX() { + return posX; + } + + public double[] getPosY() { + return posY; + } + + private void computeForces() { + for(int i=0;i TOLERANCE) + return false; + } + return true; + } + + private void moveAll() { + for(int i=0;i MAX_MOVE2) { + double s = Math.sqrt(MAX_MOVE2 / f2); + fx *= s; + fy *= s; + } + posX[i] += fx; + posY[i] += fy; + } + computeForces(); + } + + public void optimize() { + computeForces(); + + for(int iter=0;iter