-/*******************************************************************************\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
+/*******************************************************************************
+ * 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.algorithm1;
+
+import java.awt.geom.Rectangle2D;
+
+
+public interface Direction {
+ int getId();
+ double front(Rectangle rectangle);
+ double back(Rectangle rectangle);
+ double minSide(Rectangle rectangle);
+ double maxSide(Rectangle rectangle);
+ double front(Rectangle2D rectangle);
+ double back(Rectangle2D rectangle);
+ double minSide(Rectangle2D rectangle);
+ double maxSide(Rectangle2D rectangle);
+ Direction turnLeft();
+ Direction turnRight();
+ double getDir(double x, double y);
+ double getSide(double x, double y);
+ RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent);
+
+ public static final Direction EAST = new East();
+ public static final Direction SOUTH = new South();
+ public static final Direction WEST = new West();
+ public static final Direction NORTH = new North();
+ public static final Direction[] directions = new Direction[] { EAST, SOUTH, WEST, NORTH };
+
+ public static class East implements Direction {
+ public int getId() { return 0; }
+ public double front(Rectangle rect) { return rect.x0; }
+ public double back(Rectangle rect) { return rect.x1; }
+ public double minSide(Rectangle rect) { return rect.y0; }
+ public double maxSide(Rectangle rect) { return rect.y1; }
+ public double front(Rectangle2D rect) { return rect.getMinX(); }
+ public double back(Rectangle2D rect) { return rect.getMaxX(); }
+ public double minSide(Rectangle2D rect) { return rect.getMinY(); }
+ public double maxSide(Rectangle2D rect) { return rect.getMaxY(); }
+ public Direction turnLeft() { return NORTH; }
+ public Direction turnRight() { return SOUTH; }
+ public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) {
+ return new RoutePencil(front, min, back, max, penalty, this, parent);
+ }
+ public double getDir(double x, double y) { return x; }
+ public double getSide(double x, double y) { return y; }
+ }
+
+ public static class South implements Direction {
+ public int getId() { return 1; }
+ public double front(Rectangle rect) { return rect.y0; }
+ public double back(Rectangle rect) { return rect.y1; }
+ public double minSide(Rectangle rect) { return rect.x0; }
+ public double maxSide(Rectangle rect) { return rect.x1; }
+ public double front(Rectangle2D rect) { return rect.getMinY(); }
+ public double back(Rectangle2D rect) { return rect.getMaxY(); }
+ public double minSide(Rectangle2D rect) { return rect.getMinX(); }
+ public double maxSide(Rectangle2D rect) { return rect.getMaxX(); }
+ public Direction turnLeft() { return EAST; }
+ public Direction turnRight() { return WEST; }
+ public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) {
+ return new RoutePencil(min, front, max, back, penalty, this, parent);
+ }
+ public double getDir(double x, double y) { return y; }
+ public double getSide(double x, double y) { return x; }
+ }
+
+ public static class West implements Direction {
+ public int getId() { return 2; }
+ public double front(Rectangle rect) { return -rect.x1; }
+ public double back(Rectangle rect) { return -rect.x0; }
+ public double minSide(Rectangle rect) { return rect.y0; }
+ public double maxSide(Rectangle rect) { return rect.y1; }
+ public double front(Rectangle2D rect) { return -rect.getMaxX(); }
+ public double back(Rectangle2D rect) { return -rect.getMinX(); }
+ public double minSide(Rectangle2D rect) { return rect.getMinY(); }
+ public double maxSide(Rectangle2D rect) { return rect.getMaxY(); }
+ public Direction turnLeft() { return SOUTH; }
+ public Direction turnRight() { return NORTH; }
+ public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) {
+ return new RoutePencil(-back, min, -front, max, penalty, this, parent);
+ }
+ public double getDir(double x, double y) { return -x; }
+ public double getSide(double x, double y) { return y; }
+ }
+
+ public static class North implements Direction {
+ public int getId() { return 3; }
+ public double front(Rectangle rect) { return -rect.y1; }
+ public double back(Rectangle rect) { return -rect.y0; }
+ public double minSide(Rectangle rect) { return rect.x0; }
+ public double maxSide(Rectangle rect) { return rect.x1; }
+ public double front(Rectangle2D rect) { return -rect.getMaxY(); }
+ public double back(Rectangle2D rect) { return -rect.getMinY(); }
+ public double minSide(Rectangle2D rect) { return rect.getMinX(); }
+ public double maxSide(Rectangle2D rect) { return rect.getMaxX(); }
+ public Direction turnLeft() { return WEST; }
+ public Direction turnRight() { return EAST; }
+ public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) {
+ return new RoutePencil(min, -back, max, -front, penalty, this, parent);
+ }
+ public double getDir(double x, double y) { return -y; }
+ public double getSide(double x, double y) { return x; }
+ }
+}