summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/util/Vector2D.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl/maze/util/Vector2D.java')
-rw-r--r--src/ch/epfl/maze/util/Vector2D.java16
1 files changed, 1 insertions, 15 deletions
diff --git a/src/ch/epfl/maze/util/Vector2D.java b/src/ch/epfl/maze/util/Vector2D.java
index 407851c..52e1e55 100644
--- a/src/ch/epfl/maze/util/Vector2D.java
+++ b/src/ch/epfl/maze/util/Vector2D.java
@@ -3,7 +3,6 @@ package ch.epfl.maze.util;
3/** 3/**
4 * Immutable 2-dimensional vector (<i>x</i>, <i>y</i>). 4 * Immutable 2-dimensional vector (<i>x</i>, <i>y</i>).
5 */ 5 */
6
7public final class Vector2D { 6public final class Vector2D {
8 7
9 /* shift constant to compute the hash */ 8 /* shift constant to compute the hash */
@@ -20,7 +19,6 @@ public final class Vector2D {
20 * @param x Horizontal coordinate 19 * @param x Horizontal coordinate
21 * @param y Vertical coordinate 20 * @param y Vertical coordinate
22 */ 21 */
23
24 public Vector2D(int x, int y) { 22 public Vector2D(int x, int y) {
25 mX = x; 23 mX = x;
26 mY = y; 24 mY = y;
@@ -40,7 +38,6 @@ public final class Vector2D {
40 * @param y Vertical coordinate to add 38 * @param y Vertical coordinate to add
41 * @return The result of an addition with two coordinates 39 * @return The result of an addition with two coordinates
42 */ 40 */
43
44 public Vector2D add(int x, int y) { 41 public Vector2D add(int x, int y) {
45 return new Vector2D(mX + x, mY + y); 42 return new Vector2D(mX + x, mY + y);
46 } 43 }
@@ -51,7 +48,6 @@ public final class Vector2D {
51 * @param v Vector to add 48 * @param v Vector to add
52 * @return The result of the addition with the vector 49 * @return The result of the addition with the vector
53 */ 50 */
54
55 public Vector2D add(Vector2D v) { 51 public Vector2D add(Vector2D v) {
56 return add(v.mX, v.mY); 52 return add(v.mX, v.mY);
57 } 53 }
@@ -63,7 +59,6 @@ public final class Vector2D {
63 * @param y Vertical coordinate to subtract 59 * @param y Vertical coordinate to subtract
64 * @return The result of the subtraction with the vector 60 * @return The result of the subtraction with the vector
65 */ 61 */
66
67 public Vector2D sub(int x, int y) { 62 public Vector2D sub(int x, int y) {
68 return new Vector2D(mX - x, mY - y); 63 return new Vector2D(mX - x, mY - y);
69 } 64 }
@@ -74,7 +69,6 @@ public final class Vector2D {
74 * @param v Vector to subtract 69 * @param v Vector to subtract
75 * @return The result of the subtraction with the vector 70 * @return The result of the subtraction with the vector
76 */ 71 */
77
78 public Vector2D sub(Vector2D v) { 72 public Vector2D sub(Vector2D v) {
79 return sub(v.mX, v.mY); 73 return sub(v.mX, v.mY);
80 } 74 }
@@ -84,7 +78,6 @@ public final class Vector2D {
84 * 78 *
85 * @return The negated version of the vector 79 * @return The negated version of the vector
86 */ 80 */
87
88 public Vector2D negate() { 81 public Vector2D negate() {
89 return new Vector2D(-mX, -mY); 82 return new Vector2D(-mX, -mY);
90 } 83 }
@@ -95,7 +88,6 @@ public final class Vector2D {
95 * @param scalar Number to multiply the coordinates with 88 * @param scalar Number to multiply the coordinates with
96 * @return The result of the multiplication with a scalar 89 * @return The result of the multiplication with a scalar
97 */ 90 */
98
99 public Vector2D mul(int scalar) { 91 public Vector2D mul(int scalar) {
100 return new Vector2D(scalar * mX, scalar * mY); 92 return new Vector2D(scalar * mX, scalar * mY);
101 } 93 }
@@ -106,7 +98,6 @@ public final class Vector2D {
106 * @param scalar Number to divide the coordinates with 98 * @param scalar Number to divide the coordinates with
107 * @return The result of the division with a scalar 99 * @return The result of the division with a scalar
108 */ 100 */
109
110 public Vector2D div(int scalar) { 101 public Vector2D div(int scalar) {
111 return new Vector2D(scalar / mX, scalar / mY); 102 return new Vector2D(scalar / mX, scalar / mY);
112 } 103 }
@@ -116,7 +107,6 @@ public final class Vector2D {
116 * 107 *
117 * @return The normalized version of the vector 108 * @return The normalized version of the vector
118 */ 109 */
119
120 public Vector2D normalize() { 110 public Vector2D normalize() {
121 double dist = dist(); 111 double dist = dist();
122 return new Vector2D((int) (mX / dist), (int) (mY / dist)); 112 return new Vector2D((int) (mX / dist), (int) (mY / dist));
@@ -127,7 +117,6 @@ public final class Vector2D {
127 * 117 *
128 * @return The length of the vector 118 * @return The length of the vector
129 */ 119 */
130
131 public double dist() { 120 public double dist() {
132 return Math.sqrt(mX * mX + mY * mY); 121 return Math.sqrt(mX * mX + mY * mY);
133 } 122 }
@@ -138,7 +127,6 @@ public final class Vector2D {
138 * @param d Direction to add 127 * @param d Direction to add
139 * @return The result of the addition with the direction 128 * @return The result of the addition with the direction
140 */ 129 */
141
142 public Vector2D addDirectionTo(Direction d) { 130 public Vector2D addDirectionTo(Direction d) {
143 switch (d) { 131 switch (d) {
144 case UP: 132 case UP:
@@ -164,7 +152,6 @@ public final class Vector2D {
164 * 152 *
165 * @return The closest direction corresponding to the vector 153 * @return The closest direction corresponding to the vector
166 */ 154 */
167
168 public Direction toDirection() { 155 public Direction toDirection() {
169 Vector2D normal = this.normalize(); 156 Vector2D normal = this.normalize();
170 157
@@ -186,7 +173,6 @@ public final class Vector2D {
186 * 173 *
187 * @return x-coordinate of the vector 174 * @return x-coordinate of the vector
188 */ 175 */
189
190 public int getX() { 176 public int getX() {
191 return mX; 177 return mX;
192 } 178 }
@@ -196,7 +182,6 @@ public final class Vector2D {
196 * 182 *
197 * @return y-coordinate of the vector 183 * @return y-coordinate of the vector
198 */ 184 */
199
200 public int getY() { 185 public int getY() {
201 return mY; 186 return mY;
202 } 187 }
@@ -222,4 +207,5 @@ public final class Vector2D {
222 207
223 return o.hashCode() == this.hashCode(); 208 return o.hashCode() == this.hashCode();
224 } 209 }
210
225} 211}