1 package tim.prune.function.sew;
3 import tim.prune.data.Coordinate;
4 import tim.prune.data.DataPoint;
7 * Class to represent a possible split point, including
8 * the distances to the previous and next points
10 public class SplitPoint implements Comparable<SplitPoint>
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;
22 * @param inPoint data point
23 * @param inIndex point index within track
25 public SplitPoint(DataPoint inPoint, int inIndex)
27 _longitude = inPoint.getLongitude();
28 _latitude = inPoint.getLatitude();
29 _pointIndex = inIndex;
33 * @param inDist distance to previous track point
35 public void setDistanceToPrevPoint(double inDist) {
36 _distToPrevPoint = inDist;
38 /** @return distance to previous track point */
39 public double getDistanceToPrevPoint() {
40 return _distToPrevPoint;
44 * @param inDist distance to next track point, or -1.0
46 public void setDistanceToNextPoint(double inDist) {
47 _distToNextPoint = inDist;
49 /** @return distance to next track point */
50 public double getDistanceToNextPoint() {
51 return _distToNextPoint;
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;
58 /** @return point index */
59 public int getPointIndex() {
64 * @param inOther the next point
66 public void setNextPoint(SplitPoint inOther) {
70 /** @return the next point, or null */
71 public SplitPoint getNextPoint() {
76 * @param inOther other segment end
77 * @return true if the coordinates are identical
79 public boolean atSamePointAs(SplitPoint inOther)
81 return inOther != null && _latitude.equals(inOther._latitude) && _longitude.equals(inOther._longitude);
85 * Compare two objects for sorting
87 public int compareTo(SplitPoint o)
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);
94 // Latitudes same, so sort by longitude
95 if (!_longitude.equals(o._longitude)) {
96 return (_longitude.getDouble() < o._longitude.getDouble() ? -1 : 1);
98 // Points are identical so just sort by index
99 return _pointIndex - o._pointIndex;