-
Notifications
You must be signed in to change notification settings - Fork 461
Expand file tree
/
Copy pathBoardVector.java
More file actions
41 lines (32 loc) · 842 Bytes
/
BoardVector.java
File metadata and controls
41 lines (32 loc) · 842 Bytes
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
package chess.board;
public record BoardVector(
int dx,
int dy
) {
public int getAbsDx() {
return Math.abs(dx);
}
public int getAbsDy() {
return Math.abs(dy);
}
public static BoardVector createVector(Position start, Position end) {
int dx = end.column().ordinal() - start.column().ordinal();
int dy = end.row().getValue() - start.row().getValue();
return new BoardVector(dx, dy);
}
public boolean isOneQuadrant() {
return dx > 0 && dy > 0;
}
public boolean isTwoQuadrant() {
return dx < 0 && dy > 0;
}
public boolean isThreeQuadrant() {
return dx < 0 && dy < 0;
}
public boolean isFourQuadrant() {
return dx > 0 && dy < 0;
}
public boolean isDxZero() {
return dx == 0;
}
}