-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeoPolyline.java
65 lines (51 loc) · 1.48 KB
/
GeoPolyline.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
60
61
62
63
64
65
import java.util.LinkedList;
import java.util.ListIterator;
/**
*GeoPolyline class represents a path. It is a set of ordered
*Geopoints(coordinates) represented internally as a LinkedList<Geopoint>.
*/
public class GeoPolyline {
//used to represent a GeoPolyline. We can get the next and previous points
//to effecively compute the distance and traverse the path
private LinkedList<GeoPoint> geoPath;
public GeoPolyline(){
geoPath= new LinkedList<GeoPoint>();
}
public boolean addPoint(GeoPoint point){
//, we assume shortest paths, eliminate duplicates
if(geoPath.contains(point))
return false;
geoPath.add(point);// add point to end of linklist
return true;
}
public boolean addPoint(double x, double y){
return addPoint(new GeoPoint(x,y));
}
/**
*Will use this method to check whether two GeoPolylines intersect
*/
public boolean contains(GeoPoint point){
return geoPath.contains(point);
}
public int indexOf(GeoPoint point){
return geoPath.indexOf(point);
}
/*
*We will use this method to tranverse from a point in a path to another
*allow us to navigate in either direction
**/
public ListIterator<GeoPoint> pathNavigator(int firstIndex){
return geoPath.listIterator(firstIndex);
}
/**Get the starting point of a path**/
public GeoPoint getStart(){
return geoPath.getFirst();
}
/*Get the destination of a particular path**/
public GeoPoint getEnd(){
return geoPath.getLast();
}
public int getPointsCount(){
return geoPath.size();
}
}