瀏覽代碼

added right spacing calculation

Kolja Strohm 6 年之前
父節點
當前提交
3ae3c213da
共有 1 個文件被更改,包括 17 次插入5 次删除
  1. 17 5
      src/bk/PlaceBlock.java

+ 17 - 5
src/bk/PlaceBlock.java

@@ -115,7 +115,7 @@ public class PlaceBlock{
             }
         });
         ifPos.add( ifSink1 );
-        ifSink1.add( new PseudoCodeNode( "shift[sink[u]] = layout.contains('RIGHT') ? min(shift[sink[u]], x[v] - x[u] - 45) : max(shift[sink[u]], x[v] + x[u] + 45);", vars, tree, new CodeLine() {
+        ifSink1.add( new PseudoCodeNode( "shift[sink[u]] = layout.contains('RIGHT') ? min(shift[sink[u]], x[v] - x[u] - spacing) : max(shift[sink[u]], x[v] + x[u] + spacing);", vars, tree, new CodeLine() {
             @Override
             public ControlFlow runForward(Memory m) {
                 String lStr = m.read( "layout", MemoryType.LOCAL );
@@ -124,8 +124,8 @@ public class PlaceBlock{
                 LayeredGraphNode u = m.read( "u", MemoryType.LOCAL );
                 double old = u.getSink( layout ).getShift( layout );
                 u.getSink( layout ).setShift( lStr.contains( "RIGHT" ) ? 
-                        Math.min( u.getSink( layout ).getShift( layout ), v.getX( layout ) - u.getX( layout ) - 45 ) : 
-                            Math.max( u.getSink( layout ).getShift( layout ), v.getX( layout ) + u.getX( layout ) + 45 ), layout);
+                        Math.min( u.getSink( layout ).getShift( layout ), v.getX( layout ) - u.getX( layout ) - calcSpacing( u.parent(), layout ) ) : 
+                            Math.max( u.getSink( layout ).getShift( layout ), v.getX( layout ) + u.getX( layout ) + calcSpacing( u.parent(), layout ) ), layout);
                 actions.push( (Memory mem) -> {
                     u.getSink( layout ).setShift( old, layout );
                 });
@@ -140,7 +140,7 @@ public class PlaceBlock{
             }
         });
         ifPos.add( ifSink2 );
-        ifSink2.add( new PseudoCodeNode( "x[v] = layout.contains('RIGHT') ? max(x[v], x[u] + 45) : max(x[v], x[u] - 45);", vars, tree, new CodeLine() {
+        ifSink2.add( new PseudoCodeNode( "x[v] = layout.contains('RIGHT') ? max(x[v], x[u] + spacing) : max(x[v], x[u] - spacing);", vars, tree, new CodeLine() {
             @Override
             public ControlFlow runForward(Memory m) {
                 String lStr = m.read( "layout", MemoryType.LOCAL );
@@ -149,7 +149,7 @@ public class PlaceBlock{
                 LayeredGraphNode u = m.read( "u", MemoryType.LOCAL );
                 double old = v.getX( layout );
                 boolean oldDef = !v.isXUndefined( layout );
-                v.setX( lStr.contains( "RIGHT" ) ? Math.max( v.getX( layout ), u.getX( layout ) + 45 ) : Math.min( v.getX( layout ), u.getX( layout ) - 45 ), true, layout );
+                v.setX( lStr.contains( "RIGHT" ) ? Math.max( v.getX( layout ), u.getX( layout ) + calcSpacing( u.parent(), layout ) ) : Math.min( v.getX( layout ), u.getX( layout ) - calcSpacing( u.parent(), layout ) ), true, layout );
                 actions.push( (Memory mem) -> {
                     v.setX( old, oldDef, layout );
                 });
@@ -165,4 +165,16 @@ public class PlaceBlock{
         return root;
     }
 
+
+    /**
+     * calculates the minimum spacing needed between two left borders of nodes.
+     * @return the spacing
+     */
+    public static double calcSpacing( LayeredGraphNode graph, LayoutType layout )
+    {
+        double max = 0;
+        for( LayeredGraphNode n : graph.getContainedNodes() )
+            max = Math.max( max, n.getWidth( layout ) );
+        return max + 5;
+    }
 }