Explorar o código

连线布局计算优化

zhaoyk %!s(int64=2) %!d(string=hai) anos
pai
achega
a841e4b9d1

+ 14 - 12
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/line/PathBuilder.java

@@ -110,9 +110,19 @@ public class PathBuilder {
                     stopPos += edge;
                 }
             }
+            //获取垂直参考方向
+            int crossDirection = 0;
+            for (int i = 0; i < directions.length; i++) {
+                if (isVerticalDirection(directions[i]) != vDirection) { //TODO ?? 为什么垂直参考方向过滤掉fromDirection反而计算出错
+                    crossDirection = directions[i];
+                    break;
+                }
+            }
+            boolean crossReverse = crossDirection == D_LEFT || crossDirection == D_UP;
 
+            //获取当前方向上的阻挡线和通道
             List<int[]> nonBlockRoads = getNonBlockRoads(blockLines, rectArea, vDirection);
-            if(reverse) {
+            if(crossReverse) {
                 Collections.reverse(nonBlockRoads);
             }
             int[] nbr = findNonBlockRoad(nonBlockRoads, trackPos);
@@ -125,15 +135,7 @@ public class PathBuilder {
                 }
             }
 
-            //获取垂直参考方向
-            int crossDirection = 0;
-            for (int i = 0; i < directions.length; i++) {
-                if (isVerticalDirection(directions[i]) != vDirection) {
-                    crossDirection = directions[i];
-                    break;
-                }
-            }
-            boolean crossReverse = crossDirection == D_LEFT || crossDirection == D_UP;
+            //获取垂直参考方向上的阻挡线和通道
             List<BlockLine> crossBlockLines = buildBlockLines(currentBlocks, crossDirection);
             List<int[]> crossNonBlockRoads = getNonBlockRoads(crossBlockLines, rectArea, !vDirection);
             if(reverse) {
@@ -551,9 +553,9 @@ public class PathBuilder {
                         //临时避免和节点边线重合
                         int target0 = targetScope[0] + random.nextInt(targetScope[1] - targetScope[0]);
                         if (vEndNbr) {
-                            currentPoint.x = target0;
+                            moveTo(target0, false);
                         } else {
-                            currentPoint.y = target0;
+                            moveTo(target0, true);
                         }
                     }