]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Don't create degenerated transient RouteLines to RouteGraph 80/4480/1
authorJussi Koskela <jussi.koskela@semantum.fi>
Wed, 11 Mar 2020 13:35:51 +0000 (15:35 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 28 Sep 2020 06:33:18 +0000 (06:33 +0000)
This change addresses the trivial cases. If multiple bends are required
we still get degenerated lines if the terminal is at the corner of the
bounds.

gitlab #495

Change-Id: Iac5d139ba805955c38d4b4e4906eda4795871a66
(cherry picked from commit 1aedad590d55facc132e458a578064300bac833c)

bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteGraph.java
bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteLine.java
bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteTerminal.java

index fe93717662b2220c840ca38d2be848ed2c542d3b..6357e537ac5c5d356b89803c25ad2ea3166c8706 100644 (file)
@@ -277,6 +277,12 @@ public class RouteGraph implements Serializable {
         transientLines.clear();
     }
     
+    protected void removeRouteTerminalsFromRouteLines() {
+        for(RouteLine line : lines) {
+            line.removeRouteTerminals();
+        }
+    }
+
     /**
      * Rotates given terminal clockwise by given amount
      * (also negative numbers are allowed). 
@@ -311,6 +317,7 @@ public class RouteGraph implements Serializable {
     public void update() {
         needsUpdate = false;
         removeTransientRouteLines();
+        removeRouteTerminalsFromRouteLines();
 
         //print();
         
index 50d6c85d496548f75b316b8f2011ec39d5536886..225c4abfe890ecb5250e724777fb5f2dc4659c97 100644 (file)
@@ -195,6 +195,10 @@ public class RouteLine implements RouteNode, Serializable {
        return lines;
     }
 
+    public void removeRouteTerminals() {
+        points.removeIf(p -> p instanceof RouteTerminal);
+    }
+
     public RouteTerminal getTerminal() {
         return terminal;
     }
index dd660d4aaa659df5bce98302794586549e423c04..3d6bd182f664b9146c5686155ac8d4f541e6f8cf 100644 (file)
@@ -164,18 +164,31 @@ public class RouteTerminal extends RoutePoint implements RouteNode, Serializable
             boolean routeLineDoesNotIntersectTerminal;
             double linePosition = line.position;
             if(line.isHorizontal) { 
+                if (linePosition == y) {
+                    // direct route to terminal
+                    line.addPoint(this);
+                    return;
+                }
                 lineDir = linePosition < y ? 3 : 1;
                 routeLineDoesNotIntersectTerminal = linePosition <= minY || linePosition >= maxY 
                         || boundingBoxesIntersect /* we ignore intersection in this case */;
             }
             else {
+                if (linePosition == x) {
+                    // direct route to terminal
+                    line.addPoint(this);
+                    return;
+                }
                 lineDir = linePosition < x ? 2 : 0;
                 routeLineDoesNotIntersectTerminal = linePosition <= minX || linePosition >= maxX
                         || boundingBoxesIntersect /* we ignore intersection in this case */;
             }
                     
             // We can route the connection directly to the right direction
-            if(routeLineDoesNotIntersectTerminal && 
+            if((routeLineDoesNotIntersectTerminal ||
+                    (line.isHorizontal && (x == minX || x == maxX)) || // already on the top/bottom edge
+                    (!line.isHorizontal && (y == minY || y == maxY)) // already on the left/right edge
+                    ) && 
                     Directions.isAllowed(allowedDirections, lineDir)) {           
                 RouteLine line0 = createLine0(lineDir);
                 new RouteLink(line0, line);