X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FSelection.java;h=6125eacad76e7b0390daef85fa11e14bd65573fb;hb=7f5ed2be62905bd37717376dc22d09e5ea7edb4d;hp=81ab64ce7c6cc42dc7df15d788e06a90df9bb31f;hpb=f35b6d628f68e3b5ef19965ad8988d0dd1eb8efa;p=GpsPrune.git diff --git a/tim/prune/data/Selection.java b/tim/prune/data/Selection.java index 81ab64c..6125eac 100644 --- a/tim/prune/data/Selection.java +++ b/tim/prune/data/Selection.java @@ -16,12 +16,9 @@ public class Selection private int _startIndex = -1, _endIndex = -1; private int _currentPhotoIndex = -1; private int _currentAudioIndex = -1; - private IntegerRange _altitudeRange = null; - private int _climb = -1, _descent = -1; - private Altitude.Format _altitudeFormat = Altitude.Format.NO_FORMAT; + private AltitudeRange _altitudeRange = null; private long _totalSeconds = 0L, _movingSeconds = 0L; private double _angDistance = -1.0, _angMovingDistance = -1.0; - private int _numSegments = 0; /** @@ -66,8 +63,6 @@ public class Selection */ private void recalculate() { - _altitudeFormat = Altitude.Format.NO_FORMAT; - _numSegments = 0; final int numPoints = _track.getNumPoints(); // Recheck if the number of points has changed if (numPoints != _prevNumPoints) { @@ -76,18 +71,14 @@ public class Selection } if (numPoints > 0 && hasRangeSelected()) { - _altitudeRange = new IntegerRange(); - _climb = 0; - _descent = 0; + _altitudeRange = new AltitudeRange(); Altitude altitude = null; Timestamp time = null, startTime = null, endTime = null; Timestamp previousTime = null; DataPoint lastPoint = null, currPoint = null; _angDistance = 0.0; _angMovingDistance = 0.0; _totalSeconds = 0L; _movingSeconds = 0L; - int altValue = 0; - int lastAltValue = 0; - boolean foundAlt = false; + // Loop over points in selection for (int i=_startIndex; i<=_endIndex; i++) { currPoint = _track.getPoint(i); @@ -95,19 +86,7 @@ public class Selection // Ignore waypoints in altitude calculations if (!currPoint.isWaypoint() && altitude.isValid()) { - altValue = altitude.getValue(_altitudeFormat); - if (_altitudeFormat == Altitude.Format.NO_FORMAT) - _altitudeFormat = altitude.getFormat(); - _altitudeRange.addValue(altValue); - if (foundAlt) - { - if (altValue > lastAltValue) - _climb += (altValue - lastAltValue); - else - _descent += (lastAltValue - altValue); - } - lastAltValue = altValue; - foundAlt = true; + _altitudeRange.addValue(altitude); } // Store the first and last timestamp in the range time = currPoint.getTimestamp(); @@ -128,16 +107,11 @@ public class Selection { 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) { @@ -167,44 +141,16 @@ public class Selection return _endIndex; } - - /** - * @return the altitude format, ie feet or metres - */ - public Altitude.Format getAltitudeFormat() - { - return _altitudeFormat; - } - /** * @return altitude range */ - public IntegerRange getAltitudeRange() + public AltitudeRange getAltitudeRange() { if (!_valid) recalculate(); return _altitudeRange; } - /** - * @return climb - */ - public int getClimb() - { - if (!_valid) recalculate(); - return _climb; - } - - /** - * @return descent - */ - public int getDescent() - { - if (!_valid) recalculate(); - return _descent; - } - - /** * @return number of seconds spanned by selection */ @@ -224,29 +170,19 @@ public class Selection } /** - * @param inUnits distance units to use, from class Distance * @return distance of Selection in specified units */ - public double getDistance(Distance.Units inUnits) - { - return Distance.convertRadiansToDistance(_angDistance, inUnits); - } - - /** - * @param inUnits distance units to use, from class Distance - * @return moving distance of Selection in specified units - */ - public double getMovingDistance(Distance.Units inUnits) + public double getDistance() { - return Distance.convertRadiansToDistance(_angMovingDistance, inUnits); + return Distance.convertRadiansToDistance(_angDistance); } /** - * @return number of segments in selection + * @return moving distance of Selection in current units */ - public int getNumSegments() + public double getMovingDistance() { - return _numSegments; + return Distance.convertRadiansToDistance(_angMovingDistance); } /**