]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/sew/SplitPoint.java
Version 16, February 2014
[GpsPrune.git] / tim / prune / function / sew / SplitPoint.java
1 package tim.prune.function.sew;
2
3 import tim.prune.data.Coordinate;
4 import tim.prune.data.DataPoint;
5
6 /**
7  * Class to represent a possible split point, including
8  * the distances to the previous and next points
9  */
10 public class SplitPoint implements Comparable<SplitPoint>
11 {
12         private SplitPoint _nextPoint = null;
13         private Coordinate _longitude = null;
14         private Coordinate _latitude  = null;
15         private int        _pointIndex = 0;
16         private double     _distToPrevPoint = 0.0;
17         private double     _distToNextPoint = -1.0;
18
19
20         /**
21          * Constructor
22          * @param inPoint data point
23          * @param inIndex point index within track
24          */
25         public SplitPoint(DataPoint inPoint, int inIndex)
26         {
27                 _longitude = inPoint.getLongitude();
28                 _latitude  = inPoint.getLatitude();
29                 _pointIndex = inIndex;
30         }
31
32         /**
33          * @param inDist distance to previous track point
34          */
35         public void setDistanceToPrevPoint(double inDist) {
36                 _distToPrevPoint = inDist;
37         }
38         /** @return distance to previous track point */
39         public double getDistanceToPrevPoint() {
40                 return _distToPrevPoint;
41         }
42
43         /**
44          * @param inDist distance to next track point, or -1.0
45          */
46         public void setDistanceToNextPoint(double inDist) {
47                 _distToNextPoint = inDist;
48         }
49         /** @return distance to next track point */
50         public double getDistanceToNextPoint() {
51                 return _distToNextPoint;
52         }
53         /** @return true if this is closer to the next point than to the previous one */
54         public boolean closerToNext() {
55                 return _distToNextPoint > 0.0 && _distToNextPoint < _distToPrevPoint;
56         }
57
58         /** @return point index */
59         public int getPointIndex() {
60                 return _pointIndex;
61         }
62
63         /**
64          * @param inOther the next point
65          */
66         public void setNextPoint(SplitPoint inOther) {
67                 _nextPoint = inOther;
68         }
69
70         /** @return the next point, or null */
71         public SplitPoint getNextPoint() {
72                 return _nextPoint;
73         }
74
75         /**
76          * @param inOther other segment end
77          * @return true if the coordinates are identical
78          */
79         public boolean atSamePointAs(SplitPoint inOther)
80         {
81                 return inOther != null && _latitude.equals(inOther._latitude) && _longitude.equals(inOther._longitude);
82         }
83
84         /**
85          * Compare two objects for sorting
86          */
87         public int compareTo(SplitPoint o)
88         {
89                 if (o == null) return -1;
90                 // First, sort by latitude
91                 if (!_latitude.equals(o._latitude)) {
92                         return (_latitude.getDouble() < o._latitude.getDouble() ? -1 : 1);
93                 }
94                 // Latitudes same, so sort by longitude
95                 if (!_longitude.equals(o._longitude)) {
96                         return (_longitude.getDouble() < o._longitude.getDouble() ? -1 : 1);
97                 }
98                 // Points are identical so just sort by index
99                 return _pointIndex - o._pointIndex;
100         }
101 }