]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/data/Selection.java
Version 18.1, September 2015
[GpsPrune.git] / tim / prune / data / Selection.java
index f5c41ffd91f6015d8d4762e546fe8385c5dadc8e..7b63d70838e660c9af142aa1b341f5c2bd40ccce 100644 (file)
@@ -17,9 +17,8 @@ public class Selection
        private int _currentPhotoIndex = -1;
        private int _currentAudioIndex = -1;
        private AltitudeRange _altitudeRange = null;
-       private long _totalSeconds = 0L, _movingSeconds = 0L;
-       private double _angDistance = -1.0, _angMovingDistance = -1.0;
-       private int _numSegments = 0;
+       private long _movingMilliseconds = 0L;
+       private double _angMovingDistance = -1.0;
 
 
        /**
@@ -64,10 +63,10 @@ public class Selection
         */
        private void recalculate()
        {
-               _numSegments = 0;
                final int numPoints = _track.getNumPoints();
                // Recheck if the number of points has changed
-               if (numPoints != _prevNumPoints) {
+               if (numPoints != _prevNumPoints)
+               {
                        _prevNumPoints = numPoints;
                        check();
                }
@@ -75,11 +74,10 @@ public class Selection
                {
                        _altitudeRange = new AltitudeRange();
                        Altitude altitude = null;
-                       Timestamp time = null, startTime = null, endTime = null;
-                       Timestamp previousTime = null;
+                       Timestamp time = null, previousTime = null;
                        DataPoint lastPoint = null, currPoint = null;
-                       _angDistance = 0.0; _angMovingDistance = 0.0;
-                       _totalSeconds = 0L; _movingSeconds = 0L;
+                       _angMovingDistance = 0.0;
+                       _movingMilliseconds = 0L;
                        // Loop over points in selection
                        for (int i=_startIndex; i<=_endIndex; i++)
                        {
@@ -88,17 +86,20 @@ public class Selection
                                // Ignore waypoints in altitude calculations
                                if (!currPoint.isWaypoint() && altitude.isValid())
                                {
-                                       _altitudeRange.addValue(altitude);
+                                       if (currPoint.getSegmentStart()) {
+                                               _altitudeRange.ignoreValue(altitude);
+                                       }
+                                       else {
+                                               _altitudeRange.addValue(altitude);
+                                       }
                                }
-                               // Store the first and last timestamp in the range
+                               // Compare timestamps within the segments
                                time = currPoint.getTimestamp();
                                if (time.isValid())
                                {
-                                       if (startTime == null || startTime.isAfter(time)) startTime = time;
-                                       if (endTime == null || time.isAfter(endTime)) endTime = time;
                                        // add moving time
                                        if (!currPoint.getSegmentStart() && previousTime != null && time.isAfter(previousTime)) {
-                                               _movingSeconds += time.getSecondsSince(previousTime);
+                                               _movingMilliseconds += time.getMillisecondsSince(previousTime);
                                        }
                                        previousTime = time;
                                }
@@ -108,22 +109,13 @@ public class Selection
                                        if (lastPoint != null)
                                        {
                                                double radians = DataPoint.calculateRadiansBetween(lastPoint, currPoint);
-                                               _angDistance += radians;
-                                               if (currPoint.getSegmentStart()) {
-                                                       _numSegments++;
-                                               }
-                                               else {
+                                               if (!currPoint.getSegmentStart()) {
                                                        _angMovingDistance += radians;
                                                }
                                        }
                                        lastPoint = currPoint;
-                                       // If it's a track point then there must be at least one segment
-                                       if (_numSegments == 0) {_numSegments = 1;}
                                }
                        }
-                       if (endTime != null) {
-                               _totalSeconds = endTime.getSecondsSince(startTime);
-                       }
                }
                _valid = true;
        }
@@ -158,30 +150,13 @@ public class Selection
        }
 
 
-       /**
-        * @return number of seconds spanned by selection
-        */
-       public long getNumSeconds()
-       {
-               if (!_valid) recalculate();
-               return _totalSeconds;
-       }
-
        /**
         * @return number of seconds spanned by segments within selection
         */
        public long getMovingSeconds()
        {
                if (!_valid) recalculate();
-               return _movingSeconds;
-       }
-
-       /**
-        * @return distance of Selection in specified units
-        */
-       public double getDistance()
-       {
-               return Distance.convertRadiansToDistance(_angDistance);
+               return _movingMilliseconds / 1000L;
        }
 
        /**
@@ -192,14 +167,6 @@ public class Selection
                return Distance.convertRadiansToDistance(_angMovingDistance);
        }
 
-       /**
-        * @return number of segments in selection
-        */
-       public int getNumSegments()
-       {
-               return _numSegments;
-       }
-
        /**
         * Clear selected point, range, photo and audio
         */