solving a NPE related to missing mark positions which had a severe effect on ranking based on windward leg distances

This commit is contained in:
Axel Uhl committed 2015-07-19 11:28:35 +02:00
1 parent 5ecef79310
commit 7f9da36277
2 files changed
+28 -20

No files matched your search

@@ -593,7 +593,9 @@ public abstract class AbstractRankingMetric implements RankingMetric {
* For each leg the total windward distance sailed is limited to the leg's windward distance at its
* {@link TrackedLeg#getReferenceTimePoint() reference time point}. This ensures that significantly "overstaying" the lay lines
* doesn't let a competitor rank better than one who already passed the mark but traveled little windward distance in
* the next leg.
* the next leg.<p>
*
* If mark positions along the way are not known, the windward distance of those legs will be counted as 0.
*
* @param timePoint needed to determine <code>competitor</code>'s position at that time point; note that the
* time point for wind approximation is taken to be a reference time point selected based on the mark passings
@@ -620,7 +622,7 @@ public abstract class AbstractRankingMetric implements RankingMetric {
if (estimatedPosition != null) {
final Distance windwardDistanceFromLegStart = trackedLeg.getWindwardDistanceFromLegStart(estimatedPosition, cache);
final Distance legWindwardDistance = trackedLeg.getWindwardDistance(cache);
if (legWindwardDistance.compareTo(windwardDistanceFromLegStart) < 0) {
if (legWindwardDistance != null && legWindwardDistance.compareTo(windwardDistanceFromLegStart) < 0) {
d = d.add(legWindwardDistance);
} else {
// if the competitor is currently at the mark rounding, the windward distance within the leg may
@@ -632,7 +634,10 @@ public abstract class AbstractRankingMetric implements RankingMetric {
}
break;
} else {
d = d.add(trackedLeg.getWindwardDistance(cache));
final Distance legWindwardDistance = trackedLeg.getWindwardDistance(cache);
if (legWindwardDistance != null) {
d = d.add(legWindwardDistance);
}
}
}
}
@@ -454,27 +454,30 @@ public class TrackedLegImpl implements TrackedLeg {
Distance getWindwardDistance(final Position pos1, final Position pos2, TimePoint at, WindPositionMode windPositionMode, WindLegTypeAndLegBearingCache cache) {
Distance result;
try {
final LegType legType = cache.getLegType(this, at);
if (legType != LegType.REACHING) { // upwind or downwind
final Position effectivePosition = getEffectiveWindPosition(
() -> pos1.translateGreatCircle(pos1.getBearingGreatCircle(pos2), pos1.getDistance(pos2).scale(0.5)),
at, windPositionMode);
Wind wind = getTrackedRace().getWind(effectivePosition, at);
if (wind == null) {
result = pos2.alongTrackDistance(pos1, cache.getLegBearing(this, at));
if (pos1 == null || pos2 == null) {
result = null;
} else {
try {
final LegType legType = cache.getLegType(this, at);
if (legType != LegType.REACHING) { // upwind or downwind
final Position effectivePosition = getEffectiveWindPosition(() -> pos1.translateGreatCircle(
pos1.getBearingGreatCircle(pos2), pos1.getDistance(pos2).scale(0.5)), at, windPositionMode);
Wind wind = getTrackedRace().getWind(effectivePosition, at);
if (wind == null) {
result = pos2.alongTrackDistance(pos1, cache.getLegBearing(this, at));
} else {
Position projectionToLineThroughPos2 = pos1.projectToLineThrough(pos2, wind.getBearing());
result = pos2.alongTrackDistance(projectionToLineThroughPos2,
legType == LegType.UPWIND ? wind.getFrom() : wind.getBearing());
}
} else {
Position projectionToLineThroughPos2 = pos1.projectToLineThrough(pos2, wind.getBearing());
result = pos2.alongTrackDistance(projectionToLineThroughPos2,
legType == LegType.UPWIND ? wind.getFrom() : wind.getBearing());
// reaching leg, return distance projected onto leg's bearing
result = pos2.alongTrackDistance(pos1, cache.getLegBearing(this, at));
}
} else {
// reaching leg, return distance projected onto leg's bearing
} catch (NoWindException e) {
// no wind information; use along-track distance as fallback
result = pos2.alongTrackDistance(pos1, cache.getLegBearing(this, at));
}
} catch (NoWindException e) {
// no wind information; use along-track distance as fallback
result = pos2.alongTrackDistance(pos1, cache.getLegBearing(this, at));
}
return result;
}