1 package org.kite9.diagram.position;
2
3 public enum Direction {
4 UP, LEFT, DOWN, RIGHT;
5
6 public Turn getDirectionChange(Direction to) {
7 int change = (to.ordinal() - this.ordinal() + 4) % 4;
8 return Turn.values()[change];
9 }
10
11 public static Direction rotateAntiClockwise(Direction d) {
12 int ord = d.ordinal();
13 ord = ord + 1;
14 ord = (ord) % 4;
15 return Direction.values()[ord];
16 }
17
18 public static Direction rotateClockwise(Direction d) {
19 int ord = d.ordinal();
20 ord = ord + 3;
21 ord = (ord) % 4;
22 return Direction.values()[ord];
23 }
24
25 public static Direction reverse(Direction d) {
26 if (d==null)
27 return null;
28 int ord = d.ordinal();
29 ord = ord + 2;
30 ord = (ord) % 4;
31 return Direction.values()[ord];
32 }
33 }