]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "Fixed Path2D creation to work with overlapping RoutePoints"
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 20 Feb 2020 11:35:13 +0000 (11:35 +0000)
committerGerrit Code Review <gerrit2@simantics>
Thu, 20 Feb 2020 11:35:13 +0000 (11:35 +0000)
bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteGraph.java

index 9b707eae7e51524ec96c298042d9694e369cd4e5..fe93717662b2220c840ca38d2be848ed2c542d3b 100644 (file)
@@ -21,9 +21,10 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.TreeMap;
+import java.util.stream.Collectors;
 
 import org.simantics.diagram.connection.rendering.arrows.ILineEndStyle;
 import org.simantics.diagram.connection.rendering.arrows.PlainLineEndStyle;
@@ -1412,9 +1413,7 @@ public class RouteGraph implements Serializable {
         }
 
         // Analyze graph
-        Map<RoutePoint, RouteLine> begins = 
-//                new THashMap<RoutePoint, RouteLine>(); //The ordering of the coordinates in the path should be deterministic between scenegraphs
-                new TreeMap<RoutePoint, RouteLine>(RG_COMP);
+        Map<RoutePoint, RouteLine> begins = new HashMap<RoutePoint, RouteLine>();
         for(RouteLine line : lines) {
             add(begins, line);
         }
@@ -1428,7 +1427,9 @@ public class RouteGraph implements Serializable {
             }
 
         // Create paths
-        for(RoutePoint begin : begins.keySet().toArray(new RoutePoint[begins.size()])) {
+        // Sort the begins so that the order of segments is deterministic. This is required when comparing e.g. SVG diagrams. 
+        // In case of overlapping begins the order may vary.
+        for(RoutePoint begin : begins.keySet().stream().sorted(RG_COMP).collect(Collectors.toList())) {
             RouteLine curLine = begins.remove(begin);
             drawContinuousPath(path, begins, begin, curLine);
         }