]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.routing.algorithm1;\r
13 \r
14 import java.awt.geom.Rectangle2D;\r
15 \r
16 \r
17 public interface Direction {\r
18         int getId();\r
19         double front(Rectangle rectangle);\r
20         double back(Rectangle rectangle);\r
21         double minSide(Rectangle rectangle);\r
22         double maxSide(Rectangle rectangle);\r
23         double front(Rectangle2D rectangle);\r
24         double back(Rectangle2D rectangle);\r
25         double minSide(Rectangle2D rectangle);\r
26         double maxSide(Rectangle2D rectangle);\r
27         Direction turnLeft();\r
28         Direction turnRight();\r
29         double getDir(double x, double y);\r
30         double getSide(double x, double y);\r
31         RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent);\r
32         \r
33         public static final Direction EAST = new East();\r
34         public static final Direction SOUTH = new South();\r
35         public static final Direction WEST = new West();\r
36         public static final Direction NORTH = new North();\r
37         public static final Direction[] directions = new Direction[] { EAST, SOUTH, WEST, NORTH };\r
38         \r
39         public static class East implements Direction {\r
40                 public int getId() { return 0; }\r
41                 public double front(Rectangle rect) { return rect.x0; }\r
42                 public double back(Rectangle rect) { return rect.x1; }\r
43                 public double minSide(Rectangle rect) { return rect.y0; }\r
44                 public double maxSide(Rectangle rect) { return rect.y1; }\r
45                 public double front(Rectangle2D rect) { return rect.getMinX(); }\r
46                 public double back(Rectangle2D rect) { return rect.getMaxX(); }\r
47                 public double minSide(Rectangle2D rect) { return rect.getMinY(); }\r
48                 public double maxSide(Rectangle2D rect) { return rect.getMaxY(); }\r
49                 public Direction turnLeft() { return NORTH; }\r
50                 public Direction turnRight() { return SOUTH; }          \r
51                 public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) {\r
52                         return new RoutePencil(front, min, back, max, penalty, this, parent);\r
53                 }               \r
54                 public double getDir(double x, double y) { return x; }  \r
55                 public double getSide(double x, double y) { return y; }\r
56         }\r
57         \r
58         public static class South implements Direction {\r
59                 public int getId() { return 1; }\r
60                 public double front(Rectangle rect) { return rect.y0; }\r
61                 public double back(Rectangle rect) { return rect.y1; }\r
62                 public double minSide(Rectangle rect) { return rect.x0; }\r
63                 public double maxSide(Rectangle rect) { return rect.x1; }\r
64                 public double front(Rectangle2D rect) { return rect.getMinY(); }\r
65                 public double back(Rectangle2D rect) { return rect.getMaxY(); }\r
66                 public double minSide(Rectangle2D rect) { return rect.getMinX(); }\r
67                 public double maxSide(Rectangle2D rect) { return rect.getMaxX(); }\r
68                 public Direction turnLeft() { return EAST; }\r
69                 public Direction turnRight() { return WEST; }           \r
70                 public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) {\r
71                         return new RoutePencil(min, front, max, back, penalty, this, parent);\r
72                 }               \r
73                 public double getDir(double x, double y) { return y; }  \r
74                 public double getSide(double x, double y) { return x; }\r
75         }\r
76         \r
77         public static class West implements Direction {\r
78                 public int getId() { return 2; }\r
79                 public double front(Rectangle rect) { return -rect.x1; }\r
80                 public double back(Rectangle rect) { return -rect.x0; }\r
81                 public double minSide(Rectangle rect) { return rect.y0; }\r
82                 public double maxSide(Rectangle rect) { return rect.y1; }\r
83                 public double front(Rectangle2D rect) { return -rect.getMaxX(); }\r
84                 public double back(Rectangle2D rect) { return -rect.getMinX(); }\r
85                 public double minSide(Rectangle2D rect) { return rect.getMinY(); }\r
86                 public double maxSide(Rectangle2D rect) { return rect.getMaxY(); }\r
87                 public Direction turnLeft() { return SOUTH; }\r
88                 public Direction turnRight() { return NORTH; }          \r
89                 public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) {\r
90                         return new RoutePencil(-back, min, -front, max, penalty, this, parent);\r
91                 }               \r
92                 public double getDir(double x, double y) { return -x; } \r
93                 public double getSide(double x, double y) { return y; }\r
94         }\r
95         \r
96         public static class North implements Direction {\r
97                 public int getId() { return 3; }\r
98                 public double front(Rectangle rect) { return -rect.y1; }\r
99                 public double back(Rectangle rect) { return -rect.y0; }\r
100                 public double minSide(Rectangle rect) { return rect.x0; }\r
101                 public double maxSide(Rectangle rect) { return rect.x1; }\r
102                 public double front(Rectangle2D rect) { return -rect.getMaxY(); }\r
103                 public double back(Rectangle2D rect) { return -rect.getMinY(); }\r
104                 public double minSide(Rectangle2D rect) { return rect.getMinX(); }\r
105                 public double maxSide(Rectangle2D rect) { return rect.getMaxX(); }\r
106                 public Direction turnLeft() { return WEST; }\r
107                 public Direction turnRight() { return EAST; }           \r
108                 public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) {\r
109                         return new RoutePencil(min, -back, max, -front, penalty, this, parent);\r
110                 }               \r
111                 public double getDir(double x, double y) { return -y; } \r
112                 public double getSide(double x, double y) { return x; }\r
113         }\r
114 }\r