-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapSearcher.java
executable file
·59 lines (44 loc) · 1.7 KB
/
MapSearcher.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
50
51
52
53
54
55
56
57
58
59
import java.util.ArrayList;
import java.util.List;
import java.util.LinkedList;
import visualizer.*;
public class MapSearcher extends MapExtractor{
Tree map;
public MapSearcher (Tree map_) {
map = map_;
}
public LinkedList<GEdge> getEdges(int maxy, int miny, int maxx, int minx){
List<Vertex> vertexList = findInMap(minx,miny,maxx-minx,maxy-miny);
LinkedList<GEdge> edgeList= new LinkedList<GEdge>();
for (Vertex v: vertexList ){
for (Edge e: v.edges){
if (e==null) continue;
Vertex w=map.get(e.vertexIdx);
if (v.id < w.id)
edgeList.add(new GEdge(v.y,v.x,w.y,w.x));
}
}
return edgeList;
}
List<Vertex> findInMap(int x, int y, int width, int height) {
ArrayList<Vertex> vertexList = new ArrayList<Vertex>();
return findInRect(new MapRect(x,y,width,height), vertexList);
}
List<Vertex> findInRect(MapRect rect, List<Vertex> vertexList) {
addMatchingVertices(rect, 0, map.getNumVertices(), true, vertexList);
return vertexList;
}
void addMatchingVertices(MapRect rect, int start, int end, boolean xAxis, List<Vertex> vertexList) {
int medianIdx = (start+end)/2;
Vertex medianVertex = map.get(medianIdx);
if (end - start <= 1) {
vertexList.add(medianVertex);
return;
}
VertexComparator comparator = new VertexComparator(xAxis);
if (comparator.compare(medianVertex, rect) <= 0)
addMatchingVertices(rect, medianIdx, end, !xAxis, vertexList);
if (comparator.compare(medianVertex, rect) >= 0)
addMatchingVertices(rect, start, medianIdx, !xAxis, vertexList);
}
}