+ /**
+ * Find the nearest point to the specified x and y coordinates
+ * or -1 if no point is within the specified max distance
+ * @param inX x coordinate
+ * @param inY y coordinate
+ * @param inMaxDist maximum distance from selected coordinates
+ * @param inJustTrackPoints true if waypoints should be ignored
+ * @return index of nearest point or -1 if not found
+ */
+ public int getNearestPointIndexNew(double inX, double inY, double inMaxDist, boolean inJustTrackPoints)
+ {
+ int nearestPoint = 0;
+ double nearestDist = -1.0;
+ double currDist;
+ for (int i=0; i < getNumPoints(); i++)
+ {
+ if (!inJustTrackPoints || !_dataPoints[i].isWaypoint())
+ {
+ currDist = Math.abs(_xValuesNew[i] - inX) + Math.abs(_yValuesNew[i] - inY);
+ if (currDist < nearestDist || nearestDist < 0.0)
+ {
+ nearestPoint = i;
+ nearestDist = currDist;
+ }
+ }
+ }
+ // Check whether it's within required distance
+ if (nearestDist > inMaxDist && inMaxDist > 0.0)
+ {
+ return -1;
+ }
+ return nearestPoint;
+ }
+
+ /**
+ * Get the next track point starting from the given index
+ * @param inStartIndex index to start looking from
+ * @return next track point, or null if end of data reached
+ */
+ public DataPoint getNextTrackPoint(int inStartIndex)
+ {
+ return getNextTrackPoint(inStartIndex, _numPoints, true);
+ }
+
+ /**
+ * Get the next track point in the given range
+ * @param inStartIndex index to start looking from
+ * @param inEndIndex index to stop looking
+ * @return next track point, or null if end of data reached
+ */
+ public DataPoint getNextTrackPoint(int inStartIndex, int inEndIndex)
+ {
+ return getNextTrackPoint(inStartIndex, inEndIndex, true);
+ }
+
+ /**
+ * Get the previous track point starting from the given index
+ * @param inStartIndex index to start looking from
+ * @return next track point, or null if end of data reached
+ */
+ public DataPoint getPreviousTrackPoint(int inStartIndex)
+ {
+ return getNextTrackPoint(inStartIndex, _numPoints, false);
+ }
+
+ /**
+ * Get the next track point starting from the given index
+ * @param inStartIndex index to start looking from
+ * @param inEndIndex index to stop looking (inclusive)
+ * @param inCountUp true for next, false for previous
+ * @return next track point, or null if end of data reached
+ */
+ private DataPoint getNextTrackPoint(int inStartIndex, int inEndIndex, boolean inCountUp)
+ {
+ // Loop forever over points
+ int increment = inCountUp?1:-1;
+ for (int i=inStartIndex; i<=inEndIndex; i+=increment)
+ {
+ DataPoint point = getPoint(i);
+ // Exit if end of data reached - there wasn't a track point
+ if (point == null) {return null;}
+ if (point.isValid() && !point.isWaypoint()) {
+ // next track point found
+ return point;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Shift all the segment start flags in the given range by 1
+ * Method used by reverse range and its undo
+ * @param inStartIndex start of range, inclusive
+ * @param inEndIndex end of range, inclusive
+ */
+ public void shiftSegmentStarts(int inStartIndex, int inEndIndex)
+ {
+ boolean prevFlag = true;
+ boolean currFlag = true;
+ for (int i=inStartIndex; i<= inEndIndex; i++)
+ {
+ DataPoint point = getPoint(i);
+ if (point != null && !point.isWaypoint())
+ {
+ // remember flag
+ currFlag = point.getSegmentStart();
+ // shift flag by 1
+ point.setSegmentStart(prevFlag);
+ prevFlag = currFlag;
+ }
+ }
+ }
+