X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;ds=sidebyside;f=tim%2Fprune%2Fdata%2FTrack.java;h=f45854a0e3d47a1fd5fc0ee6924732b3294decc0;hb=92dad5df664287acb51728e9ea599f150765d34a;hp=8623c587ba5c9131d9051ad083cdcafffd24e54c;hpb=7f5ed2be62905bd37717376dc22d09e5ea7edb4d;p=GpsPrune.git diff --git a/tim/prune/data/Track.java b/tim/prune/data/Track.java index 8623c58..f45854a 100644 --- a/tim/prune/data/Track.java +++ b/tim/prune/data/Track.java @@ -87,6 +87,11 @@ public class Track _dataPoints[pointIndex] = point; pointIndex++; } + else + { + // TODO: Maybe report this somehow? + // System.out.println("point is not valid!"); + } } _numPoints = pointIndex; // Set first track point to be start of segment @@ -173,21 +178,30 @@ public class Track /** * Delete the points marked for deletion + * @param inSplitSegments true to split segments at deleted points * @return number of points deleted */ - public int deleteMarkedPoints() + public int deleteMarkedPoints(boolean inSplitSegments) { int numCopied = 0; - // Copy selected points + // Copy selected points into a new point array DataPoint[] newPointArray = new DataPoint[_numPoints]; + boolean prevPointDeleted = false; for (int i=0; i<_numPoints; i++) { DataPoint point = _dataPoints[i]; // Don't delete photo points if (point.hasMedia() || !point.getDeleteFlag()) { + if (prevPointDeleted && inSplitSegments) { + point.setSegmentStart(true); + } newPointArray[numCopied] = point; numCopied++; + prevPointDeleted = false; + } + else { + prevPointDeleted = true; } } @@ -306,7 +320,7 @@ public class Track * @param inUndo true for undo operation * @return true on success */ - public boolean addTimeOffset(int inStart, int inEnd, long inOffset, boolean inUndo) + public boolean addTimeOffsetSeconds(int inStart, int inEnd, long inOffset, boolean inUndo) { // sanity check if (inStart < 0 || inEnd < 0 || inStart >= inEnd || inEnd >= _numPoints) { @@ -316,13 +330,13 @@ public class Track // Loop over all points within range for (int i=inStart; i<=inEnd; i++) { - Timestamp timestamp = _dataPoints[i].getTimestamp(); - if (timestamp != null) + DataPoint p = _dataPoints[i]; + if (p != null && p.hasTimestamp()) { // This point has a timestamp so add the offset to it foundTimestamp = true; - timestamp.addOffset(inOffset); - _dataPoints[i].setModified(inUndo); + p.addTimeOffsetSeconds(inOffset); + p.setModified(inUndo); } } return foundTimestamp; @@ -348,13 +362,13 @@ public class Track // Loop over all points within range for (int i=inStart; i<=inEnd; i++) { - Altitude alt = _dataPoints[i].getAltitude(); - if (alt != null && alt.isValid()) + DataPoint p = _dataPoints[i]; + if (p != null && p.hasAltitude()) { // This point has an altitude so add the offset to it foundAlt = true; - alt.addOffset(inOffset, inUnit, inDecimals); - _dataPoints[i].setModified(false); + p.addAltitudeOffset(inOffset, inUnit, inDecimals); + p.setModified(false); } } // needs to be scaled again @@ -363,61 +377,6 @@ public class Track } - /** - * Collect all waypoints to the start or end of the track - * @param inAtStart true to collect at start, false for end - * @return true if successful, false if no change - */ - public boolean collectWaypoints(boolean inAtStart) - { - // Check for mixed data, numbers of waypoints & nons - int numWaypoints = 0, numNonWaypoints = 0; - boolean wayAfterNon = false, nonAfterWay = false; - DataPoint[] waypoints = new DataPoint[_numPoints]; - DataPoint[] nonWaypoints = new DataPoint[_numPoints]; - DataPoint point = null; - for (int i=0; i<_numPoints; i++) - { - point = _dataPoints[i]; - if (point.isWaypoint()) - { - waypoints[numWaypoints] = point; - numWaypoints++; - wayAfterNon |= (numNonWaypoints > 0); - } - else - { - nonWaypoints[numNonWaypoints] = point; - numNonWaypoints++; - nonAfterWay |= (numWaypoints > 0); - } - } - // Exit if the data is already in the specified order - if (numWaypoints == 0 || numNonWaypoints == 0 - || (inAtStart && !wayAfterNon && nonAfterWay) - || (!inAtStart && wayAfterNon && !nonAfterWay)) - { - return false; - } - - // Copy the arrays back into _dataPoints in the specified order - if (inAtStart) - { - System.arraycopy(waypoints, 0, _dataPoints, 0, numWaypoints); - System.arraycopy(nonWaypoints, 0, _dataPoints, numWaypoints, numNonWaypoints); - } - else - { - System.arraycopy(nonWaypoints, 0, _dataPoints, 0, numNonWaypoints); - System.arraycopy(waypoints, 0, _dataPoints, numNonWaypoints, numWaypoints); - } - // needs to be scaled again - _scaled = false; - UpdateMessageBroker.informSubscribers(); - return true; - } - - /** * Interleave all waypoints by each nearest track point * @return true if successful, false if no change @@ -602,8 +561,8 @@ public class Track meanAltitude = new Altitude((int) (totalAltitude / numAltitudes), altUnit); } - DataPoint insertedPoint = new DataPoint(new Latitude(meanLatitude, Coordinate.FORMAT_NONE), - new Longitude(meanLongitude, Coordinate.FORMAT_NONE), meanAltitude); + DataPoint insertedPoint = new DataPoint(new Latitude(meanLatitude, Coordinate.FORMAT_DECIMAL_FORCE_POINT), + new Longitude(meanLongitude, Coordinate.FORMAT_DECIMAL_FORCE_POINT), meanAltitude); // Make into singleton insertedPoint.setSegmentStart(true); DataPoint nextPoint = getNextTrackPoint(inEndIndex+1); @@ -951,7 +910,7 @@ public class Track */ private static final double getMinXDist(double inX) { - // TODO: Can use some kind of floor here? + // TODO: Should be abs(mod(inX-0.5,1)-0.5) - means two adds, one mod, one abs instead of two adds, 3 abss and two compares return Math.min(Math.min(Math.abs(inX), Math.abs(inX-1.0)), Math.abs(inX+1.0)); }