Finished MarkRoundingSequence class. Added MarkRoundingData class.
RaceState has a MarkRoundingSequenceMember. The temporary rounding line drawing in canvas uses MarkRoundingSequence. MockRace now uses MarkRoundingSequence. #story[1185]
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
package shared.model;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Contains data related to mark rounding for a specific leg.
|
||||
*/
|
||||
public class MarkRoundingData {
|
||||
|
||||
/**
|
||||
* The leg this relates to.
|
||||
*/
|
||||
private Leg leg;
|
||||
|
||||
/**
|
||||
* The mark that should be rounded.
|
||||
*/
|
||||
private Mark markToRound;
|
||||
|
||||
/**
|
||||
* The bearing of the leg.
|
||||
*/
|
||||
private Bearing legBearing;
|
||||
|
||||
/**
|
||||
* The bearing of the next leg.
|
||||
*/
|
||||
private Bearing nextLegBearing;
|
||||
|
||||
/**
|
||||
* The location of the first rounding check point.
|
||||
*/
|
||||
private GPSCoordinate roundCheck1;
|
||||
|
||||
/**
|
||||
* The location of the second rounding check point.
|
||||
*/
|
||||
private GPSCoordinate roundCheck2;
|
||||
|
||||
/**
|
||||
* A halfway point between mark to round and roundCheck1.
|
||||
*/
|
||||
private GPSCoordinate roundCheck1Halfway;
|
||||
|
||||
/**
|
||||
* A halfway point between mark to round and roundCheck2.
|
||||
*/
|
||||
private GPSCoordinate roundCheck2Halfway;
|
||||
|
||||
|
||||
public MarkRoundingData() {
|
||||
}
|
||||
|
||||
|
||||
public Leg getLeg() {
|
||||
return leg;
|
||||
}
|
||||
|
||||
public void setLeg(Leg leg) {
|
||||
this.leg = leg;
|
||||
}
|
||||
|
||||
public Mark getMarkToRound() {
|
||||
return markToRound;
|
||||
}
|
||||
|
||||
public void setMarkToRound(Mark markToRound) {
|
||||
this.markToRound = markToRound;
|
||||
}
|
||||
|
||||
public Bearing getLegBearing() {
|
||||
return legBearing;
|
||||
}
|
||||
|
||||
public void setLegBearing(Bearing legBearing) {
|
||||
this.legBearing = legBearing;
|
||||
}
|
||||
|
||||
public Bearing getNextLegBearing() {
|
||||
return nextLegBearing;
|
||||
}
|
||||
|
||||
public void setNextLegBearing(Bearing nextLegBearing) {
|
||||
this.nextLegBearing = nextLegBearing;
|
||||
}
|
||||
|
||||
public GPSCoordinate getRoundCheck1() {
|
||||
return roundCheck1;
|
||||
}
|
||||
|
||||
public void setRoundCheck1(GPSCoordinate roundCheck1) {
|
||||
this.roundCheck1 = roundCheck1;
|
||||
}
|
||||
|
||||
public GPSCoordinate getRoundCheck2() {
|
||||
return roundCheck2;
|
||||
}
|
||||
|
||||
public void setRoundCheck2(GPSCoordinate roundCheck2) {
|
||||
this.roundCheck2 = roundCheck2;
|
||||
}
|
||||
|
||||
public GPSCoordinate getRoundCheck1Halfway() {
|
||||
return roundCheck1Halfway;
|
||||
}
|
||||
|
||||
public void setRoundCheck1Halfway(GPSCoordinate roundCheck1Halfway) {
|
||||
this.roundCheck1Halfway = roundCheck1Halfway;
|
||||
}
|
||||
|
||||
public GPSCoordinate getRoundCheck2Halfway() {
|
||||
return roundCheck2Halfway;
|
||||
}
|
||||
|
||||
public void setRoundCheck2Halfway(GPSCoordinate roundCheck2Halfway) {
|
||||
this.roundCheck2Halfway = roundCheck2Halfway;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
package shared.model;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import static shared.enums.RoundingType.*;
|
||||
|
||||
/**
|
||||
* This class contains a sequence of points that describe the mark rounding order for a course.
|
||||
@@ -19,9 +16,9 @@ public class MarkRoundingSequence {
|
||||
private List<Leg> legs;
|
||||
|
||||
/**
|
||||
* For each leg, a sequence of rounding points.
|
||||
* For each leg, mark rounding information.
|
||||
*/
|
||||
private Map<Leg, List<GPSCoordinate>> roundingPoints;
|
||||
private Map<Leg, MarkRoundingData> roundingPoints;
|
||||
|
||||
|
||||
|
||||
@@ -31,6 +28,16 @@ public class MarkRoundingSequence {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the rounding points for a given leg.
|
||||
* @param leg Leg to check.
|
||||
* @return Rounding points for leg.
|
||||
*/
|
||||
public MarkRoundingData getRoundingData(Leg leg) {
|
||||
return roundingPoints.get(leg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates the rounding points for all legs in the race.
|
||||
*/
|
||||
@@ -39,7 +46,11 @@ public class MarkRoundingSequence {
|
||||
|
||||
for (int i = 0; i < this.legs.size(); i++) {
|
||||
Leg currentLeg = this.legs.get(i);
|
||||
Optional<Leg> nextLeg = Optional.ofNullable(this.legs.get(i + 1));
|
||||
|
||||
Optional<Leg> nextLeg = Optional.empty();
|
||||
if (i < legs.size() - 1) {
|
||||
nextLeg = Optional.of(this.legs.get(i + 1));
|
||||
}
|
||||
|
||||
generateRoundingPoint(currentLeg, nextLeg);
|
||||
}
|
||||
@@ -50,14 +61,85 @@ public class MarkRoundingSequence {
|
||||
/**
|
||||
* Generates the rounding points for a specific leg.
|
||||
* @param currentLeg The leg to generate rounding points for.
|
||||
* @param nextLeg The following leg, used to help generate rounding points.
|
||||
* @param nextLeg The following leg, used to help generate rounding points. Final leg of race doesn't have a following leg.
|
||||
*/
|
||||
private void generateRoundingPoint(Leg currentLeg, Optional<Leg> nextLeg) {
|
||||
|
||||
Bearing bearingToAddFirstPoint = calculateBearingToAdd(currentLeg);
|
||||
|
||||
GPSCoordinate startCoord = currentLeg.getStartCompoundMark().getAverageGPSCoordinate();
|
||||
GPSCoordinate endCoord = currentLeg.getEndCompoundMark().getAverageGPSCoordinate();
|
||||
Bearing legBearing = GPSCoordinate.calculateBearing(startCoord, endCoord);
|
||||
Bearing nextBearing = legBearing;
|
||||
|
||||
Mark markToRound = currentLeg.getEndCompoundMark().getMarkForRounding(legBearing);
|
||||
|
||||
GPSCoordinate roundCheck1;
|
||||
if (currentLeg.getEndCompoundMark().getMark2() == null) {
|
||||
//End is a single mark.
|
||||
roundCheck1 = calculateRoundingCheckPoint(
|
||||
currentLeg,
|
||||
markToRound,
|
||||
legBearing,
|
||||
bearingToAddFirstPoint);
|
||||
} else {
|
||||
//End is a gate.
|
||||
if (markToRound == currentLeg.getEndCompoundMark().getMark1()) {
|
||||
roundCheck1 = currentLeg.getEndCompoundMark().getMark2().getPosition();
|
||||
} else {
|
||||
roundCheck1 = currentLeg.getEndCompoundMark().getMark1().getPosition();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO the halfway points currently haven't been done properly.
|
||||
|
||||
GPSCoordinate roundCheck1Halfway = calculateRoundingCheckPoint(
|
||||
currentLeg,
|
||||
markToRound,
|
||||
legBearing,
|
||||
bearingToAddFirstPoint);
|
||||
|
||||
|
||||
GPSCoordinate roundCheck2 = roundCheck1;
|
||||
GPSCoordinate roundCheck2Halfway = roundCheck1Halfway;
|
||||
if (nextLeg.isPresent()) {
|
||||
|
||||
Bearing bearingToAddSecondPoint = bearingToAddFirstPoint;//calculateBearingToAdd(nextLeg.get());
|
||||
|
||||
GPSCoordinate startCoord2 = nextLeg.get().getStartCompoundMark().getAverageGPSCoordinate();
|
||||
GPSCoordinate endCoord2 = nextLeg.get().getEndCompoundMark().getAverageGPSCoordinate();
|
||||
nextBearing = GPSCoordinate.calculateBearing(startCoord2, endCoord2);
|
||||
|
||||
roundCheck2 = calculateRoundingCheckPoint(
|
||||
currentLeg,
|
||||
markToRound,
|
||||
nextBearing,
|
||||
bearingToAddSecondPoint);
|
||||
|
||||
roundCheck2Halfway = calculateRoundingCheckPoint(
|
||||
currentLeg,
|
||||
markToRound,
|
||||
nextBearing,
|
||||
bearingToAddSecondPoint);
|
||||
}
|
||||
|
||||
|
||||
MarkRoundingData roundingData = new MarkRoundingData();
|
||||
roundingData.setLeg(currentLeg);
|
||||
|
||||
roundingData.setLegBearing(legBearing);
|
||||
roundingData.setNextLegBearing(nextBearing);
|
||||
|
||||
roundingData.setMarkToRound(markToRound);
|
||||
|
||||
roundingData.setRoundCheck1(roundCheck1);
|
||||
roundingData.setRoundCheck1Halfway(roundCheck1Halfway);
|
||||
|
||||
roundingData.setRoundCheck2(roundCheck2);
|
||||
roundingData.setRoundCheck2Halfway(roundCheck2Halfway);
|
||||
|
||||
|
||||
this.roundingPoints.put(currentLeg, roundingData);
|
||||
|
||||
|
||||
//Rounding points:
|
||||
@@ -75,4 +157,54 @@ public class MarkRoundingSequence {
|
||||
//the second rounding point is the same as the first, except LEGBEARING is the bearing between end of current leg, and start of next leg.
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the location of the rounding check point, which together with the mark to round, forms a line that the boat must cross to round the mark.
|
||||
* @param leg Leg of race to check.
|
||||
* @param markToRound Mark at end of leg to round.
|
||||
* @param legBearing The bearing of the nearest leg. For the first rounding point this is the leg's bearing, for the second rounding point it is the next leg's bearing.
|
||||
* @param bearingToAdd The bearing to add to the leg bearing to get a perpendicular bearing.
|
||||
* @return The location of the rounding point, which together with the mark to round forms a line the boat must cross.
|
||||
*/
|
||||
private GPSCoordinate calculateRoundingCheckPoint(Leg leg, Mark markToRound, Bearing legBearing, Bearing bearingToAdd) {
|
||||
|
||||
|
||||
double roundingDistanceMeters = leg.getEndCompoundMark().getRoundingDistance();
|
||||
|
||||
|
||||
//We project from rounding mark to get the second point which forms the line the boat must cross.
|
||||
/*
|
||||
c2
|
||||
|
|
||||
|
|
||||
r------c1
|
||||
b
|
||||
*/
|
||||
GPSCoordinate roundCheck = GPSCoordinate.calculateNewPosition(
|
||||
markToRound.getPosition(),
|
||||
roundingDistanceMeters,
|
||||
Azimuth.fromDegrees(legBearing.degrees() + bearingToAdd.degrees()) );
|
||||
|
||||
return roundCheck;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the bearing that must be added to a leg's bearing to calculate a perpendicular bearing, used for finding rounding points.
|
||||
* @param leg Leg to check.
|
||||
* @return Bearing to add. Will be either +90 or -90.
|
||||
*/
|
||||
private Bearing calculateBearingToAdd(Leg leg) {
|
||||
|
||||
if (leg.getEndCompoundMark().getRoundingType() == Port ||
|
||||
leg.getEndCompoundMark().getRoundingType() == SP) {
|
||||
return Bearing.fromDegrees(90);
|
||||
} else {
|
||||
return Bearing.fromDegrees(-90);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -46,6 +46,12 @@ public abstract class RaceState {
|
||||
private ObservableList<Leg> legs;
|
||||
|
||||
|
||||
/**
|
||||
* The sequence of rounding points for each leg/mark.
|
||||
*/
|
||||
private MarkRoundingSequence markRoundingSequence;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The clock which tracks the race's start time, current time, and elapsed duration.
|
||||
@@ -102,10 +108,15 @@ public abstract class RaceState {
|
||||
*/
|
||||
protected void useLegsList(List<Leg> legs) {
|
||||
this.legs.setAll(legs);
|
||||
|
||||
//We create this before adding the extra finish leg, as it doesn't contain compound marks.
|
||||
this.markRoundingSequence = new MarkRoundingSequence(getLegs());
|
||||
|
||||
//We add a "dummy" leg at the end of the race.
|
||||
if (getLegs().size() > 0) {
|
||||
getLegs().add(new Leg("Finish", getLegs().size()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -367,6 +378,11 @@ public abstract class RaceState {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the rounding sequences for each leg.
|
||||
* @return Rounding sequence for each leg.
|
||||
*/
|
||||
public MarkRoundingSequence getMarkRoundingSequence() {
|
||||
return markRoundingSequence;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user