bug5932: added test for segment ending on a mark passing; fixed issues for tack type segment calculation

This commit is contained in:
Axel Uhl
2023-12-27 15:52:48 +01:00
parent bfc2627226
commit 9911530258
4 changed files with 96 additions and 22 deletions
@@ -66,12 +66,6 @@ public class TackTypeSegmentRetrievalProcessor extends AbstractRetrievalProcesso
break;
}
gpsFix = i.next();
try {
//no null case like line 87, because for loop checks that mark passing at leg start is not finish mark passing
nextTackType = trackedLegOfCompetitor.getTackType(gpsFix.getTimePoint());
} catch (NoWindException e) {
nextTackType = null;
}
while (nextMarkPassing != null && !gpsFix.getTimePoint().before(nextMarkPassing.getTimePoint())) {
// reached leg's end; complete the current segment if not empty and move through mark passings
// iterator until having found the leg the gpsFix is in, while moving the trackedLegOfCompetitor along
@@ -81,12 +75,17 @@ public class TackTypeSegmentRetrievalProcessor extends AbstractRetrievalProcesso
nextMarkPassing.getTimePoint(), currentTackType);
segmentEmpty = gpsFix.getTimePoint().equals(nextMarkPassing.getTimePoint()); // if the fix is exactly at leg start
startOfCurrentSegment = nextMarkPassing.getTimePoint();
currentTackType = nextTackType;
}
// if nextMarkPassing is last MarkPassing there will be no leg after, trackedLeg is null
trackedLegOfCompetitor = nextMarkPassing.getWaypoint()==finish ? null : trackedRace.getTrackedLegStartingAt(nextMarkPassing.getWaypoint()).getTrackedLeg(competitor);
nextMarkPassing = markPassingIterator.hasNext() ? markPassingIterator.next() : null;
}
try {
// no null case like line 87, because for loop checks that mark passing at leg start is not finish mark passing
nextTackType = trackedLegOfCompetitor.getTackType(gpsFix.getTimePoint());
} catch (NoWindException e) {
nextTackType = null;
}
// invariant: nextMarkPassing is either null or after gpsFix's time and representing the passing of the mark at the end
// of the leg gpsFix is in; trackedLegOfCompetitor corresponds to the leg gpsFix is in
if (!segmentEmpty && nextTackType != currentTackType) {
@@ -94,10 +93,10 @@ public class TackTypeSegmentRetrievalProcessor extends AbstractRetrievalProcesso
gpsFix.getTimePoint() /* don't include the last interval ending at the non-TackType fix */, currentTackType);
segmentEmpty = true; // because gpsFix is now exactly at the beginning of the new segment
startOfCurrentSegment = gpsFix.getTimePoint();
currentTackType = nextTackType;
} else {
segmentEmpty = false; // gpsFix is in the current segment
}
currentTackType = nextTackType;
}
} finally {
gpsFixTrack.unlockAfterRead();
@@ -85,5 +85,10 @@ public class TackTypeSegmentWithContext implements HasTackTypeSegmentContext {
getStartOfTackTypeSegment().plus(getStartOfTackTypeSegment().until(getEndOfTackTypeSegment()).divide(2)));
}
@Override
public String toString() {
return "TackTypeSegmentWithContext [gpsFixTrackContext=" + gpsFixTrackContext + ", startOfTackTypeSegment="
+ startOfTackTypeSegment + ", endOfTackTypeSegment=" + endOfTackTypeSegment + ", tackType=" + tackType
+ "]";
}
}