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
*/
public boolean isBetweenGate(CompoundMark gate){
if ((this.isPortSide(gate.getMark1()) && this.isStarboardSide(gate.getMark2())) ||
(this.isStarboardSide(gate.getMark1()) && this.isPortSide(gate.getMark2()))){
return true;
}else{
return false;
}
return (this.isPortSide(gate.getMark1()) && this.isStarboardSide(gate.getMark2())) ||
(this.isStarboardSide(gate.getMark1()) && this.isPortSide(gate.getMark2()));
}
/**
* 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() {

@ -6,6 +6,7 @@ import network.Messages.LatestMessages;
import shared.dataInput.BoatDataSource;
import shared.dataInput.RaceDataSource;
import shared.dataInput.RegattaDataSource;
import shared.enums.RoundingType;
import shared.model.*;
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 gateCheck = boat.getCurrentLeg().getEndCompoundMark().getMark2() == null || boat.isBetweenGate(boat.getCurrentLeg().getEndCompoundMark());
Mark roundingMark = boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing);
switch (boat.getRoundingStatus()) {
case 0://hasn't started rounding
if (boat.isPortSide(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing)) &&
GPSCoordinate.passesLine(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing).getPosition(),
if (boat.isPortSide(roundingMark) &&
GPSCoordinate.passesLine(roundingMark.getPosition(),
roundingChecks.get(0), boat.getCurrentPosition(), legBearing) &&
gateCheck) {
gateCheck && boat.isBetweenGate(roundingMark, Mark.tempMark(roundingChecks.get(0)))) {
boat.increaseRoundingStatus();
}
break;
case 1://has been parallel to the mark
// System.out.println("round 1");
if (boat.isPortSide(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing)) &&
GPSCoordinate.passesLine(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing).getPosition(),
roundingChecks.get(1), boat.getCurrentPosition(), Bearing.fromDegrees(legBearing.degrees() - 90))) {//negative 90 from bearing because of port rounding
case 1://has been parallel to the mark;
if (boat.isPortSide(roundingMark) &&
GPSCoordinate.passesLine(roundingMark.getPosition(),
roundingChecks.get(1), boat.getCurrentPosition(),
Bearing.fromDegrees(legBearing.degrees() - 90)) &&//negative 90 from bearing because of port rounding
boat.isBetweenGate(roundingMark, Mark.tempMark(roundingChecks.get(1)))) {
boat.increaseRoundingStatus();
}
break;
case 2://has traveled 180 degrees around the mark
// System.out.println("round 2");
//Move boat on to next leg.
boat.resetRoundingStatus();
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 gateCheck = boat.getCurrentLeg().getEndCompoundMark().getMark2() == null || boat.isBetweenGate(boat.getCurrentLeg().getEndCompoundMark());
Mark roundingMark = boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing);
switch (boat.getRoundingStatus()) {
case 0://hasn't started rounding
if (boat.isStarboardSide(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing)) &&
GPSCoordinate.passesLine(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing).getPosition(),
if (boat.isStarboardSide(roundingMark) &&
GPSCoordinate.passesLine(roundingMark.getPosition(),
roundingChecks.get(0), boat.getCurrentPosition(), legBearing) &&
gateCheck) {
gateCheck &&
boat.isBetweenGate(roundingMark, Mark.tempMark(roundingChecks.get(0)))) {
boat.increaseRoundingStatus();
}
break;
case 1://has been parallel to the mark
if (boat.isStarboardSide(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing)) &&
GPSCoordinate.passesLine(boat.getCurrentLeg().getEndCompoundMark().getMarkForRounding(legBearing).getPosition(),
roundingChecks.get(1), boat.getCurrentPosition(), Bearing.fromDegrees(legBearing.degrees() + 90))) {//positive 90 from bearing because of starboard rounding
if (boat.isStarboardSide(roundingMark) &&
GPSCoordinate.passesLine(roundingMark.getPosition(),
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();
}
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
//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,
epsilonNauticalMiles, Azimuth.fromDegrees(bearingOfDirectionLine.degrees() - 90));//adding 90 so the check line is parallel
epsilonNauticalMiles, Azimuth.fromDegrees(bearingOfDirectionLine.degrees() + bearingToAdd));
GPSCoordinate roundCheck2;
try{
@ -568,15 +582,12 @@ public class MockRace extends Race {
Bearing bearingOfNextDirectionLine = GPSCoordinate.calculateBearing(startNextDirectionLinePoint, endNextDirectionLinePoint);
roundCheck2 = GPSCoordinate.calculateNewPosition(endDirectionLinePoint,
epsilonNauticalMiles, Azimuth.fromDegrees(bearingOfNextDirectionLine.degrees() + 90));
epsilonNauticalMiles, Azimuth.fromDegrees(bearingOfNextDirectionLine.degrees() + bearingToAdd));
}catch(NullPointerException e){
//this is caused by the last leg not being having a leg after it
roundCheck2 = roundCheck1;
}
List<GPSCoordinate> roundingChecks = new ArrayList<GPSCoordinate>(Arrays.asList(roundCheck1, roundCheck2));
switch (boat.getCurrentLeg().getEndCompoundMark().getRoundingType()) {

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

@ -34,6 +34,15 @@ public class Mark {
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.

Loading…
Cancel
Save