-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.java
More file actions
55 lines (42 loc) · 1.14 KB
/
Point.java
File metadata and controls
55 lines (42 loc) · 1.14 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
package hashcode.model;
public class Point {
int row, col;
public Point(){}
public Point(int row, int col) {
this.row = row;
this.col = col;
}
public Point(Point position) {
this.row = position.row;
this.col = position.col;
}
public static int distance(Point a, Point b) {
double diffRow = a.row - b.row;
double diffCol = a.col - b.col;
return (int) StrictMath.ceil(StrictMath.sqrt(diffRow * diffRow + diffCol * diffCol));
}
public int distanceTo(Point x) {
return distance(this, x);
}
@Override
public String toString() {
return "Point{" +
"row=" + row +
", col=" + col +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Point point = (Point) o;
if (row != point.row) return false;
return col == point.col;
}
@Override
public int hashCode() {
int result = row;
result = 31 * result + col;
return result;
}
}