summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/util/Direction.java
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-11-21 10:44:42 +0100
committerPacien TRAN-GIRARD2015-11-21 10:44:42 +0100
commit90bd766f361083f6fd9e39ff080c83fcc606832f (patch)
treedf81a931c9565a4b227068680087f58fdace1859 /src/ch/epfl/maze/util/Direction.java
parent655ac88f4e73b2df532a451aedf5a561ea1b0d2c (diff)
downloadmaze-solver-90bd766f361083f6fd9e39ff080c83fcc606832f.tar.gz
Reformat imported code
Diffstat (limited to 'src/ch/epfl/maze/util/Direction.java')
-rw-r--r--src/ch/epfl/maze/util/Direction.java445
1 files changed, 220 insertions, 225 deletions
<
diff --git a/src/ch/epfl/maze/util/Direction.java b/src/ch/epfl/maze/util/Direction.java
index a75ba7f..e8c0993 100644
--- a/src/ch/epfl/maze/util/Direction.java
+++ b/src/ch/epfl/maze/util/Direction.java
@@ -4,232 +4,227 @@ package ch.epfl.maze.util;
4 * Directions that an animal can take to move. They represent the four cardinal 4 * Directions that an animal can take to move. They represent the four cardinal
5 * points ({@code DOWN, UP, RIGHT, LEFT}) from the frame of reference of the 5 * points ({@code DOWN, UP, RIGHT, LEFT}) from the frame of reference of the
6 * labyrinth, plus a default one : {@code NONE}. 6 * labyrinth, plus a default one : {@code NONE}.
7 *
8 */ 7 */
9 8
10public enum Direction { 9public enum Direction {
11 DOWN, UP, RIGHT, LEFT, NONE; 10 DOWN, UP, RIGHT, LEFT, NONE;
12 11
13 /** 12 /**
14 * Returns the integer value of the direction 13 * Returns the integer value of the direction
15 * 14 *
16 * @return Integer value of the direction 15 * @return Integer value of the direction
17 */ 16 */
18 17
19 public int intValue() { 18 public int intValue() {
20 switch (this) { 19 switch (this) {
21 case DOWN: 20 case DOWN:
22 return 0; 21 return 0;
23 22
24 case UP: 23 case UP:
25 return 1; 24 return 1;
26 25
27 case RIGHT: 26 case RIGHT:
28 return 2; 27 return 2;
29 28
30 case LEFT: 29 case LEFT:
31 return 3; 30 return 3;
32 31
33 case NONE: 32 case NONE:
34 default: 33 default:
35 return 4; 34 return 4;
36 } 35 }
37 } 36 }
38 37
39 /** 38 /**
40 * Converts the direction into an orthonormal vector, when possible. 39 * Converts the direction into an orthonormal vector, when possible.
41 * 40 *
42 * @return Orthonormal {@code Vector2D} that represents the direction. 41 * @return Orthonormal {@code Vector2D} that represents the direction.
43 */ 42 */
44 43
45 public Vector2D toVector() { 44 public Vector2D toVector() {
46 switch (this) { 45 switch (this) {
47 case DOWN: 46 case DOWN:
48 return new Vector2D(0, 1); 47 return new Vector2D(0, 1);
49 48
50 case UP: 49 case UP:
51 return new Vector2D(0, -1); 50 return new Vector2D(0, -1);
52 51
53 case RIGHT: 52 case RIGHT:
54 return new Vector2D(1, 0); 53 return new Vector2D(1, 0);
55 54
56 case LEFT: 55 case LEFT:
57 return new Vector2D(-1, 0); 56 return new Vector2D(-1, 0);
58 57
59 case NONE: 58 case NONE:
60 default: 59 default:
61 return new Vector2D(0, 0); 60 return new Vector2D(0, 0);
62 } 61 }
63 } 62 }
64 63
65 /** 64 /**
66 * Reverses the direction. 65 * Reverses the direction.
67 * 66 *
68 * @return The opposite direction. 67 * @return The opposite direction.
69 */ 68 */
70 69
71 public Direction reverse() { 70 public Direction reverse() {
72 switch (this) { 71 switch (this) {
73 case DOWN: 72 case DOWN:
74 return UP; 73 return UP;
75 74
76 case UP: 75 case UP:
77 return DOWN; 76 return DOWN;
78 77
79 case RIGHT: 78 case RIGHT:
80 return LEFT; 79 return LEFT;
81 80
82 case LEFT: 81 case LEFT:
83 return RIGHT; 82 return RIGHT;
84 83
85 case NONE: 84 case NONE:
86 default: 85 default:
87 return NONE; 86 return NONE;
88 } 87 }
89 } 88 }
90 89
91 /** 90 /**
92 * Determines whether the argument is the opposite of another. 91 * Determines whether the argument is the opposite of another.
93 * 92 *
94 * @param d 93 * @param d The direction to compare with
95 * The direction to compare with 94 * @return <b>true</b> if the direction is the opposite the argument,
96 * @return <b>true</b> if the direction is the opposite the argument, 95 * <b>false</b> otherwise
97 * <b>false</b> otherwise 96 */
98 */ 97
99 98 public boolean isOpposite(Direction d) {
100 public boolean isOpposite(Direction d) { 99 return this == d.reverse();
101 return this == d.reverse(); 100 }
102 } 101
103 102 /**
104 /** 103 * Converts the argument relative to the frame of reference given by the
105 * Converts the argument relative to the frame of reference given by the 104 * direction that calls the method.
106 * direction that calls the method. 105 *
107 * 106 * @param dir The direction to convert
108 * @param dir 107 * @return The direction converted to the frame of reference given by the
109 * The direction to convert 108 * direction called.
110 * @return The direction converted to the frame of reference given by the 109 */
111 * direction called. 110
112 */ 111 public Direction relativeDirection(Direction dir) {
113 112 switch (this) {
114 public Direction relativeDirection(Direction dir) { 113 case DOWN:
115 switch (this) { 114 return dir.reverse();
116 case DOWN: 115
117 return dir.reverse(); 116 case UP:
118 117 return dir;
119 case UP: 118
120 return dir; 119 case RIGHT:
121 120 return dir.rotateLeft();
122 case RIGHT: 121
123 return dir.rotateLeft(); 122 case LEFT:
124 123 return dir.rotateRight();
125 case LEFT: 124
126 return dir.rotateRight(); 125 case NONE:
127 126 default:
128 case NONE: 127 return NONE;
129 default: 128 }
130 return NONE; 129 }
131 } 130
132 } 131 /**
133 132 * Converts the argument back to the frame of reference of the labyrinth
134 /** 133 *
135 * Converts the argument back to the frame of reference of the labyrinth 134 * @param dir The direction to convert back
136 * 135 * @return The direction converted back to the frame of reference of the
137 * @param dir 136 * labyrinth
138 * The direction to convert back 137 */
139 * @return The direction converted back to the frame of reference of the 138
140 * labyrinth 139 public Direction unRelativeDirection(Direction dir) {
141 */ 140 switch (this) {
142 141 case DOWN:
143 public Direction unRelativeDirection(Direction dir) { 142 return dir.reverse();
144 switch (this) { 143
145 case DOWN: 144 case UP:
146 return dir.reverse(); 145 return dir;
147 146
148 case UP: 147 case RIGHT:
149 return dir; 148 return dir.rotateRight();
150 149