]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/routing/ConnectionDirectionUtil.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / routing / ConnectionDirectionUtil.java
index 5c86382a897bda76561a4507bbd2a64e491efa81..5849d01dcc94b5516177585f17994028d6b38f46 100644 (file)
@@ -1,91 +1,91 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.g2d.routing;\r
-\r
-import java.awt.geom.Rectangle2D;\r
-import java.util.Arrays;\r
-\r
-import org.simantics.g2d.routing.IConnection.Connector;\r
-\r
-public class ConnectionDirectionUtil {\r
-       \r
-       public static class Dir implements Comparable<Dir> {\r
-               int id;\r
-               double dist;\r
-               \r
-               public Dir(int id, double dist) {\r
-                       this.id = id;\r
-                       this.dist = dist;\r
-               }\r
-\r
-               @Override\r
-               public int compareTo(Dir o) {\r
-                       if(dist < o.dist)\r
-                               return -1;\r
-                       if(o.dist < dist)\r
-                               return 1;\r
-                       return 0;\r
-               }       \r
-               \r
-       }\r
-       \r
-       public static Terminal createTerminal(Rectangle2D shape, double x, double y) {\r
-               Dir[] dirs = new Dir[] {\r
-                       new Dir(0, shape.getMaxX() - x),\r
-                       new Dir(1, shape.getMaxY() - y),\r
-                       new Dir(2, x - shape.getMinX()),\r
-                       new Dir(3, y - shape.getMinY()),\r
-               };\r
-               Arrays.sort(dirs);\r
-               double[] dist = new double[4];\r
-               int flags = 0;\r
-               int i=0;\r
-               do {\r
-                       flags |= 1 << dirs[i].id;\r
-                       dist[dirs[i].id] = Math.max(0.0, dirs[i].dist+1e-6);\r
-                       ++i;\r
-               } while(i < 4 && (dirs[i].dist <= 0.0 || dirs[i].dist*0.9 < dirs[0].dist));\r
-               return new Terminal(x, y, flags, dist, shape);\r
-       }\r
-       \r
-       public static int reverseDirections(int flags) {\r
-               return ((flags & Constants.EAST_FLAG) == 0 ? 0 : Constants.WEST_FLAG)\r
-                        | ((flags & Constants.SOUTH_FLAG) == 0 ? 0 : Constants.NORTH_FLAG)\r
-                        | ((flags & Constants.WEST_FLAG) == 0 ? 0 : Constants.EAST_FLAG)\r
-                        | ((flags & Constants.NORTH_FLAG) == 0 ? 0 : Constants.SOUTH_FLAG);\r
-       }\r
-       \r
-       public static void determineAllowedDirections(Connector c) {\r
-           if(c.parentObstacle == null) {\r
-               c.allowedDirections = 0xf;\r
-               return;\r
-           }\r
-           Dir[] dirs = new Dir[] {\r
-            new Dir(0, c.parentObstacle.getMaxX() - c.x),\r
-            new Dir(1, c.parentObstacle.getMaxY() - c.y),\r
-            new Dir(2, c.x - c.parentObstacle.getMinX()),\r
-            new Dir(3, c.y - c.parentObstacle.getMinY()),\r
-        };\r
-        Arrays.sort(dirs);\r
-        double[] dist = new double[4];\r
-        c.allowedDirections = 0;\r
-        int i=0;\r
-        do {\r
-            c.allowedDirections |= 1 << dirs[i].id;\r
-            dist[dirs[i].id] = Math.max(0.0, dirs[i].dist+1e-6);\r
-            ++i;\r
-        } while(i < 4 &&\r
-                       ((dirs[i].id == ((dirs[0].id + 2)&3) && (dirs[i].dist <= 0.0 || dirs[i].dist*0.9 < dirs[0].dist)) ||\r
-                       (dirs[i].dist <= 0.0 || dirs[i].dist*0.95 < dirs[0].dist))\r
-                       );\r
-       }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.g2d.routing;
+
+import java.awt.geom.Rectangle2D;
+import java.util.Arrays;
+
+import org.simantics.g2d.routing.IConnection.Connector;
+
+public class ConnectionDirectionUtil {
+       
+       public static class Dir implements Comparable<Dir> {
+               int id;
+               double dist;
+               
+               public Dir(int id, double dist) {
+                       this.id = id;
+                       this.dist = dist;
+               }
+
+               @Override
+               public int compareTo(Dir o) {
+                       if(dist < o.dist)
+                               return -1;
+                       if(o.dist < dist)
+                               return 1;
+                       return 0;
+               }       
+               
+       }
+       
+       public static Terminal createTerminal(Rectangle2D shape, double x, double y) {
+               Dir[] dirs = new Dir[] {
+                       new Dir(0, shape.getMaxX() - x),
+                       new Dir(1, shape.getMaxY() - y),
+                       new Dir(2, x - shape.getMinX()),
+                       new Dir(3, y - shape.getMinY()),
+               };
+               Arrays.sort(dirs);
+               double[] dist = new double[4];
+               int flags = 0;
+               int i=0;
+               do {
+                       flags |= 1 << dirs[i].id;
+                       dist[dirs[i].id] = Math.max(0.0, dirs[i].dist+1e-6);
+                       ++i;
+               } while(i < 4 && (dirs[i].dist <= 0.0 || dirs[i].dist*0.9 < dirs[0].dist));
+               return new Terminal(x, y, flags, dist, shape);
+       }
+       
+       public static int reverseDirections(int flags) {
+               return ((flags & Constants.EAST_FLAG) == 0 ? 0 : Constants.WEST_FLAG)
+                        | ((flags & Constants.SOUTH_FLAG) == 0 ? 0 : Constants.NORTH_FLAG)
+                        | ((flags & Constants.WEST_FLAG) == 0 ? 0 : Constants.EAST_FLAG)
+                        | ((flags & Constants.NORTH_FLAG) == 0 ? 0 : Constants.SOUTH_FLAG);
+       }
+       
+       public static void determineAllowedDirections(Connector c) {
+           if(c.parentObstacle == null) {
+               c.allowedDirections = 0xf;
+               return;
+           }
+           Dir[] dirs = new Dir[] {
+            new Dir(0, c.parentObstacle.getMaxX() - c.x),
+            new Dir(1, c.parentObstacle.getMaxY() - c.y),
+            new Dir(2, c.x - c.parentObstacle.getMinX()),
+            new Dir(3, c.y - c.parentObstacle.getMinY()),
+        };
+        Arrays.sort(dirs);
+        double[] dist = new double[4];
+        c.allowedDirections = 0;
+        int i=0;
+        do {
+            c.allowedDirections |= 1 << dirs[i].id;
+            dist[dirs[i].id] = Math.max(0.0, dirs[i].dist+1e-6);
+            ++i;
+        } while(i < 4 &&
+                       ((dirs[i].id == ((dirs[0].id + 2)&3) && (dirs[i].dist <= 0.0 || dirs[i].dist*0.9 < dirs[0].dist)) ||
+                       (dirs[i].dist <= 0.0 || dirs[i].dist*0.95 < dirs[0].dist))
+                       );
+       }
+}