-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVector2.java
More file actions
66 lines (52 loc) · 1.46 KB
/
Vector2.java
File metadata and controls
66 lines (52 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
*
* Last Edited 24/05/2017 : Antony.J
*
*/
public class Vector2 {
public final int x;
public final int y;
public static final Vector2 zero = new Vector2(0, 0);
public static final int LEFT = 0;
public static final int UP = 1;
public static final int RIGHT = 2;
public static final int DOWN = 3;
private BlockType blockType;
public static final Vector2[] directions = {new Vector2(-1, 0), new Vector2(0, 1), new Vector2(1, 0), new Vector2(0, -1)};
public Vector2(int x, int y) {
this.x = x;
this.y = y;
}
public BlockType getBlockType() {
return this.blockType;
}
public void setBlockType(BlockType type) {
this.blockType = type;
}
public static Vector2 add(Vector2 v1, Vector2 v2) {
return new Vector2(v1.x + v2.x, v1.y + v2.y);
}
public static Vector2 subtract(Vector2 v1, Vector2 v2) {
return new Vector2(v1.x - v2.x, v1.y - v2.y);
}
public static Vector2 scale(Vector2 v, int scale) {
return new Vector2(v.x * scale, v.y * scale);
}
public static int manDistance(Vector2 v1, Vector2 v2) {
return Math.abs(v1.x - v2.x) + Math.abs(v1.y - v2.y);
}
@Override
public boolean equals(Object o) {
if(o == null || !(o instanceof Vector2)) return false;
Vector2 v = (Vector2)o;
return x == v.x && y == v.y;
}
@Override
public int hashCode() {
return 7 * x + 13 * y;
}
@Override
public String toString() {
return "(" + x + ", " + y + ")";
}
}