]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/routing/algorithm1/Direction.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / routing / algorithm1 / Direction.java
diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/routing/algorithm1/Direction.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/routing/algorithm1/Direction.java
new file mode 100644 (file)
index 0000000..31e391a
--- /dev/null
@@ -0,0 +1,114 @@
+/*******************************************************************************\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.algorithm1;\r
+\r
+import java.awt.geom.Rectangle2D;\r
+\r
+\r
+public interface Direction {\r
+       int getId();\r
+       double front(Rectangle rectangle);\r
+       double back(Rectangle rectangle);\r
+       double minSide(Rectangle rectangle);\r
+       double maxSide(Rectangle rectangle);\r
+       double front(Rectangle2D rectangle);\r
+       double back(Rectangle2D rectangle);\r
+       double minSide(Rectangle2D rectangle);\r
+       double maxSide(Rectangle2D rectangle);\r
+       Direction turnLeft();\r
+       Direction turnRight();\r
+       double getDir(double x, double y);\r
+       double getSide(double x, double y);\r
+       RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent);\r
+       \r
+       public static final Direction EAST = new East();\r
+       public static final Direction SOUTH = new South();\r
+       public static final Direction WEST = new West();\r
+       public static final Direction NORTH = new North();\r
+       public static final Direction[] directions = new Direction[] { EAST, SOUTH, WEST, NORTH };\r
+       \r
+       public static class East implements Direction {\r
+               public int getId() { return 0; }\r
+               public double front(Rectangle rect) { return rect.x0; }\r
+               public double back(Rectangle rect) { return rect.x1; }\r
+               public double minSide(Rectangle rect) { return rect.y0; }\r
+               public double maxSide(Rectangle rect) { return rect.y1; }\r
+               public double front(Rectangle2D rect) { return rect.getMinX(); }\r
+               public double back(Rectangle2D rect) { return rect.getMaxX(); }\r
+               public double minSide(Rectangle2D rect) { return rect.getMinY(); }\r
+               public double maxSide(Rectangle2D rect) { return rect.getMaxY(); }\r
+               public Direction turnLeft() { return NORTH; }\r
+               public Direction turnRight() { return SOUTH; }          \r
+               public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) {\r
+                       return new RoutePencil(front, min, back, max, penalty, this, parent);\r
+               }               \r
+               public double getDir(double x, double y) { return x; }  \r
+               public double getSide(double x, double y) { return y; }\r
+       }\r
+       \r
+       public static class South implements Direction {\r
+               public int getId() { return 1; }\r
+               public double front(Rectangle rect) { return rect.y0; }\r
+               public double back(Rectangle rect) { return rect.y1; }\r
+               public double minSide(Rectangle rect) { return rect.x0; }\r
+               public double maxSide(Rectangle rect) { return rect.x1; }\r
+               public double front(Rectangle2D rect) { return rect.getMinY(); }\r
+               public double back(Rectangle2D rect) { return rect.getMaxY(); }\r
+               public double minSide(Rectangle2D rect) { return rect.getMinX(); }\r
+               public double maxSide(Rectangle2D rect) { return rect.getMaxX(); }\r
+               public Direction turnLeft() { return EAST; }\r
+               public Direction turnRight() { return WEST; }           \r
+               public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) {\r
+                       return new RoutePencil(min, front, max, back, penalty, this, parent);\r
+               }               \r
+               public double getDir(double x, double y) { return y; }  \r
+               public double getSide(double x, double y) { return x; }\r
+       }\r
+       \r
+       public static class West implements Direction {\r
+               public int getId() { return 2; }\r
+               public double front(Rectangle rect) { return -rect.x1; }\r
+               public double back(Rectangle rect) { return -rect.x0; }\r
+               public double minSide(Rectangle rect) { return rect.y0; }\r
+               public double maxSide(Rectangle rect) { return rect.y1; }\r
+               public double front(Rectangle2D rect) { return -rect.getMaxX(); }\r
+               public double back(Rectangle2D rect) { return -rect.getMinX(); }\r
+               public double minSide(Rectangle2D rect) { return rect.getMinY(); }\r
+               public double maxSide(Rectangle2D rect) { return rect.getMaxY(); }\r
+               public Direction turnLeft() { return SOUTH; }\r
+               public Direction turnRight() { return NORTH; }          \r
+               public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) {\r
+                       return new RoutePencil(-back, min, -front, max, penalty, this, parent);\r
+               }               \r
+               public double getDir(double x, double y) { return -x; } \r
+               public double getSide(double x, double y) { return y; }\r
+       }\r
+       \r
+       public static class North implements Direction {\r
+               public int getId() { return 3; }\r
+               public double front(Rectangle rect) { return -rect.y1; }\r
+               public double back(Rectangle rect) { return -rect.y0; }\r
+               public double minSide(Rectangle rect) { return rect.x0; }\r
+               public double maxSide(Rectangle rect) { return rect.x1; }\r
+               public double front(Rectangle2D rect) { return -rect.getMaxY(); }\r
+               public double back(Rectangle2D rect) { return -rect.getMinY(); }\r
+               public double minSide(Rectangle2D rect) { return rect.getMinX(); }\r
+               public double maxSide(Rectangle2D rect) { return rect.getMaxX(); }\r
+               public Direction turnLeft() { return WEST; }\r
+               public Direction turnRight() { return EAST; }           \r
+               public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) {\r
+                       return new RoutePencil(min, -back, max, -front, penalty, this, parent);\r
+               }               \r
+               public double getDir(double x, double y) { return -y; } \r
+               public double getSide(double x, double y) { return x; }\r
+       }\r
+}\r