mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Bugfix: while recording UI values were doubled.
Issue: copy constructor of TrackStatisticsUpdater was not copying completely and the same reference used.
This commit is contained in:
@@ -193,4 +193,31 @@ public class TrackStatisticsUpdaterTest {
|
||||
@Test
|
||||
public void addTrackPoint_speed_from_GPS_moving_and_sensor_speed() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copy_constructor() {
|
||||
// given
|
||||
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
||||
|
||||
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000));
|
||||
TrackPoint tp2 = new TrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000));
|
||||
TrackPoint tp3 = new TrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000));
|
||||
TrackPoint tp4 = new TrackPoint(0.0005, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(4000));
|
||||
TrackPoint tp5 = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochMilli(5000));
|
||||
|
||||
subject.addTrackPoint(tp1, GPS_DISTANCE);
|
||||
subject.addTrackPoint(tp2, GPS_DISTANCE);
|
||||
subject.addTrackPoint(tp3, GPS_DISTANCE);
|
||||
subject.addTrackPoint(tp4, GPS_DISTANCE);
|
||||
|
||||
// when
|
||||
TrackStatisticsUpdater copy = new TrackStatisticsUpdater(subject);
|
||||
subject.addTrackPoint(tp5, GPS_DISTANCE);
|
||||
copy.addTrackPoint(tp5, GPS_DISTANCE);
|
||||
|
||||
|
||||
// then
|
||||
assertEquals(55.287, subject.getTrackStatistics().getTotalDistance().toM(), 0.01);
|
||||
assertEquals(55.287, copy.getTrackStatistics().getTotalDistance().toM(), 0.01);
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public class TrackStatisticsUpdater {
|
||||
private final DoubleRingBuffer speedBuffer_mps;
|
||||
|
||||
// The current segment's statistics
|
||||
private final TrackStatistics currentSegment = new TrackStatistics();
|
||||
private final TrackStatistics currentSegment;
|
||||
// Current segment's last trackPoint
|
||||
private TrackPoint lastTrackPoint;
|
||||
// Current segment's last moving trackPoint
|
||||
@@ -85,6 +85,8 @@ public class TrackStatisticsUpdater {
|
||||
*/
|
||||
public TrackStatisticsUpdater(TrackStatistics trackStatistics) {
|
||||
this.trackStatistics = trackStatistics;
|
||||
this.currentSegment = new TrackStatistics();
|
||||
|
||||
trackInitialized = true;
|
||||
|
||||
altitudeBuffer_m = new DoubleRingBuffer(ALTITUDE_SMOOTHING_FACTOR);
|
||||
@@ -92,6 +94,9 @@ public class TrackStatisticsUpdater {
|
||||
}
|
||||
|
||||
public TrackStatisticsUpdater(TrackStatisticsUpdater toCopy) {
|
||||
this.currentSegment = new TrackStatistics(toCopy.currentSegment);
|
||||
this.trackStatistics = new TrackStatistics(toCopy.trackStatistics);
|
||||
|
||||
this.trackInitialized = toCopy.trackInitialized;
|
||||
this.segmentInitialized = toCopy.segmentInitialized;
|
||||
this.altitudeBuffer_m = new DoubleRingBuffer(toCopy.altitudeBuffer_m);
|
||||
@@ -99,9 +104,6 @@ public class TrackStatisticsUpdater {
|
||||
|
||||
this.lastTrackPoint = toCopy.lastTrackPoint;
|
||||
this.lastMovingTrackPoint = toCopy.lastMovingTrackPoint;
|
||||
|
||||
this.trackStatistics = toCopy.getTrackStatistics();
|
||||
this.currentSegment.merge(toCopy.currentSegment);
|
||||
}
|
||||
|
||||
public TrackStatistics getTrackStatistics() {
|
||||
|
||||
Reference in New Issue
Block a user