-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVertexComparator.java
49 lines (43 loc) · 1.07 KB
/
VertexComparator.java
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
import java.util.Comparator;
class MapRect {
int x;
int y;
int width;
int height;
public MapRect(int x_, int y_, int width_, int height_) {
x = x_;
y = y_;
width = width_;
height = height_;
}
}
class VertexComparator implements Comparator<Vertex> {
boolean sortOnX;
public VertexComparator(boolean sortOnX_) {
sortOnX = sortOnX_;
}
public int compare(Vertex a, Vertex b) {
if (sortOnX)
return a.x - b.x;
else
return a.y - b.y;
}
public int compare(Vertex vertex, MapRect rect) {
if (sortOnX) {
if (vertex.x > rect.x) {
if (vertex.x <= rect.x+rect.width)
return 0;
return 1;
}
return -1;
}
else {
if (vertex.y > rect.y) {
if (vertex.y <= rect.y+rect.height)
return 0;
return 1;
}
return -1;
}
}
}