1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.routing.algorithm1;
14 import java.awt.geom.Rectangle2D;
17 public interface Direction {
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);
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);
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 };
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);
54 public double getDir(double x, double y) { return x; }
55 public double getSide(double x, double y) { return y; }
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);
73 public double getDir(double x, double y) { return y; }
74 public double getSide(double x, double y) { return x; }
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);
92 public double getDir(double x, double y) { return -x; }
93 public double getSide(double x, double y) { return y; }
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);
111 public double getDir(double x, double y) { return -y; }
112 public double getSide(double x, double y) { return x; }