Fix for placement of invis gates and checks that boats pass through these gates

-see wiki on rounding
#story[1101]
main
hba56 8 years ago
parent f90648e4ce
commit 2acc36225e

@ -262,12 +262,19 @@ public class MockBoat extends Boat {
* @return true if the boat is between two marks that make up a gate * @return true if the boat is between two marks that make up a gate
*/ */
public boolean isBetweenGate(CompoundMark gate){ public boolean isBetweenGate(CompoundMark gate){
if ((this.isPortSide(gate.getMark1()) && this.isStarboardSide(gate.getMark2())) || return (this.isPortSide(gate.getMark1()) && this.isStarboardSide(gate.getMark2())) ||
(this.isStarboardSide(gate.getMark1()) && this.isPortSide(gate.getMark2()))){ (this.isStarboardSide(gate.getMark1()) && this.isPortSide(gate.getMark2()));
return true;
}else{
return false;
} }
/**
* Used to check if this boat is between a two marks
* @param mark1 the first mark
* @param mark2 the second mark
* @return true if the boat is between two marks
*/
public boolean isBetweenGate(Mark mark1, Mark mark2){
return (this.isPortSide(mark1) && this.isStarboardSide(mark2)) ||
(this.isStarboardSide(mark1) && this.isPortSide(mark2));
} }
public Integer getRoundingStatus() { public Integer getRoundingStatus() {

@ -6,6 +6,7 @@ import network.Messages.LatestMessages;
import shared.dataInput.BoatDataSource; import shared.dataInput.BoatDataSource;
import shared.dataInput.RaceDataSource; import shared.dataInput.RaceDataSource;
import shared.dataInput.RegattaDataSource; import shared.dataInput.RegattaDataSource;
import shared.enums.RoundingType;
import shared.model.*; import shared.model.*;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
@ -473,26 +474,27 @@ public class MockRace extends Race {
//boolean for if boat has to/needs to pass through a gate //boolean for if boat has to/needs to pass through a gate
boolean gateCheck = boat.getCurrentLeg().getEndCompoundMark().getMark2() == null || boat.isBetweenGate(boat.getCurrentLeg().getEndCompoundMark()); boolean gateCheck = boat.getCurrentLeg().getEndCompoundMark().getMark2() == null || boat.isBetweenGate(boat.getCurrentLeg().getEndCompoundMark());
Mark roundingMark = boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing);
switch (boat.getRoundingStatus()) { switch (boat.getRoundingStatus()) {
case 0://hasn't started rounding case 0://hasn't started rounding
if (boat.isPortSide(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing)) && if (boat.isPortSide(roundingMark) &&
GPSCoordinate.passesLine(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing).getPosition(), GPSCoordinate.passesLine(roundingMark.getPosition(),
roundingChecks.get(0), boat.getCurrentPosition(), legBearing) && roundingChecks.get(0), boat.getCurrentPosition(), legBearing) &&
gateCheck) { gateCheck && boat.isBetweenGate(roundingMark, Mark.tempMark(roundingChecks.get(0)))) {
boat.increaseRoundingStatus(); boat.increaseRoundingStatus();
} }
break; break;
case 1://has been parallel to the mark case 1://has been parallel to the mark;
// System.out.println("round 1"); if (boat.isPortSide(roundingMark) &&
if (boat.isPortSide(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing)) && GPSCoordinate.passesLine(roundingMark.getPosition(),
GPSCoordinate.passesLine(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing).getPosition(), roundingChecks.get(1), boat.getCurrentPosition(),
roundingChecks.get(1), boat.getCurrentPosition(), Bearing.fromDegrees(legBearing.degrees() - 90))) {//negative 90 from bearing because of port rounding Bearing.fromDegrees(legBearing.degrees() - 90)) &&//negative 90 from bearing because of port rounding
boat.isBetweenGate(roundingMark, Mark.tempMark(roundingChecks.get(1)))) {
boat.increaseRoundingStatus(); boat.increaseRoundingStatus();
} }
break; break;
case 2://has traveled 180 degrees around the mark case 2://has traveled 180 degrees around the mark
// System.out.println("round 2");
//Move boat on to next leg. //Move boat on to next leg.
boat.resetRoundingStatus(); boat.resetRoundingStatus();
Leg nextLeg = this.legs.get(boat.getCurrentLeg().getLegNumber() + 1); Leg nextLeg = this.legs.get(boat.getCurrentLeg().getLegNumber() + 1);
@ -512,20 +514,23 @@ public class MockRace extends Race {
//boolean for if boat has to/needs to pass through a gate //boolean for if boat has to/needs to pass through a gate
boolean gateCheck = boat.getCurrentLeg().getEndCompoundMark().getMark2() == null || boat.isBetweenGate(boat.getCurrentLeg().getEndCompoundMark()); boolean gateCheck = boat.getCurrentLeg().getEndCompoundMark().getMark2() == null || boat.isBetweenGate(boat.getCurrentLeg().getEndCompoundMark());
Mark roundingMark = boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing);
switch (boat.getRoundingStatus()) { switch (boat.getRoundingStatus()) {
case 0://hasn't started rounding case 0://hasn't started rounding
if (boat.isStarboardSide(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing)) && if (boat.isStarboardSide(roundingMark) &&
GPSCoordinate.passesLine(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing).getPosition(), GPSCoordinate.passesLine(roundingMark.getPosition(),
roundingChecks.get(0), boat.getCurrentPosition(), legBearing) && roundingChecks.get(0), boat.getCurrentPosition(), legBearing) &&
gateCheck) { gateCheck &&
boat.isBetweenGate(roundingMark, Mark.tempMark(roundingChecks.get(0)))) {
boat.increaseRoundingStatus(); boat.increaseRoundingStatus();
} }
break; break;
case 1://has been parallel to the mark case 1://has been parallel to the mark
if (boat.isStarboardSide(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing)) && if (boat.isStarboardSide(roundingMark) &&
GPSCoordinate.passesLine(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing).getPosition(), GPSCoordinate.passesLine(roundingMark.getPosition(),
roundingChecks.get(1), boat.getCurrentPosition(), Bearing.fromDegrees(legBearing.degrees() + 90))) {//positive 90 from bearing because of starboard rounding roundingChecks.get(1), boat.getCurrentPosition(), Bearing.fromDegrees(legBearing.degrees() + 90)) && //positive 90 from bearing because of starboard rounding
boat.isBetweenGate(roundingMark, Mark.tempMark(roundingChecks.get(1)))) {
boat.increaseRoundingStatus(); boat.increaseRoundingStatus();
} }
break; break;
@ -556,8 +561,17 @@ public class MockRace extends Race {
//use the direction line to create three invisible points that act as crossover lines a boat must cross //use the direction line to create three invisible points that act as crossover lines a boat must cross
//to round a mark //to round a mark
double bearingToAdd;
if (boat.getCurrentLeg().getEndCompoundMark().getRoundingType() == RoundingType.Port ||
boat.getCurrentLeg().getEndCompoundMark().getRoundingType() == RoundingType.SP){
bearingToAdd = 90;
}else{
bearingToAdd = -90;
}
GPSCoordinate roundCheck1 = GPSCoordinate.calculateNewPosition(endDirectionLinePoint, GPSCoordinate roundCheck1 = GPSCoordinate.calculateNewPosition(endDirectionLinePoint,
epsilonNauticalMiles, Azimuth.fromDegrees(bearingOfDirectionLine.degrees() - 90));//adding 90 so the check line is parallel epsilonNauticalMiles, Azimuth.fromDegrees(bearingOfDirectionLine.degrees() + bearingToAdd));
GPSCoordinate roundCheck2; GPSCoordinate roundCheck2;
try{ try{
@ -568,15 +582,12 @@ public class MockRace extends Race {
Bearing bearingOfNextDirectionLine = GPSCoordinate.calculateBearing(startNextDirectionLinePoint, endNextDirectionLinePoint); Bearing bearingOfNextDirectionLine = GPSCoordinate.calculateBearing(startNextDirectionLinePoint, endNextDirectionLinePoint);
roundCheck2 = GPSCoordinate.calculateNewPosition(endDirectionLinePoint, roundCheck2 = GPSCoordinate.calculateNewPosition(endDirectionLinePoint,
epsilonNauticalMiles, Azimuth.fromDegrees(bearingOfNextDirectionLine.degrees() + 90)); epsilonNauticalMiles, Azimuth.fromDegrees(bearingOfNextDirectionLine.degrees() + bearingToAdd));
}catch(NullPointerException e){ }catch(NullPointerException e){
//this is caused by the last leg not being having a leg after it //this is caused by the last leg not being having a leg after it
roundCheck2 = roundCheck1; roundCheck2 = roundCheck1;
} }
List<GPSCoordinate> roundingChecks = new ArrayList<GPSCoordinate>(Arrays.asList(roundCheck1, roundCheck2)); List<GPSCoordinate> roundingChecks = new ArrayList<GPSCoordinate>(Arrays.asList(roundCheck1, roundCheck2));
switch (boat.getCurrentLeg().getEndCompoundMark().getRoundingType()) { switch (boat.getCurrentLeg().getEndCompoundMark().getRoundingType()) {

@ -158,7 +158,7 @@ public class CompoundMark {
if (mark2 != null){ if (mark2 != null){
return GPSCoordinate.calculateDistanceMeters(mark1.getPosition(), mark2.getPosition()); return GPSCoordinate.calculateDistanceMeters(mark1.getPosition(), mark2.getPosition());
}else{ }else{
return 250.0 / Constants.NMToMetersConversion; return 400;
} }
} }

@ -34,6 +34,15 @@ public class Mark {
this.position = position; this.position = position;
} }
/**
* Used to create marks that are not visible in the race
* @param position position of the mark
* @return the new mark
*/
public static Mark tempMark(GPSCoordinate position){
return new Mark(-1, "Hidden Mark", position);
}
/** /**
* Returns the name of the mark. * Returns the name of the mark.

Loading…
Cancel
Save