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