@ -3,12 +3,10 @@ package mock.model;
import network.Messages.Enums.BoatStatusEnum ;
import network.Messages.Enums.BoatStatusEnum ;
import network.Messages.Enums.RaceStatusEnum ;
import network.Messages.Enums.RaceStatusEnum ;
import network.Messages.LatestMessages ;
import network.Messages.LatestMessages ;
import org.opengis.geometry.primitive.* ;
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.model.* ;
import shared.model.* ;
import shared.model.Bearing ;
import java.time.ZonedDateTime ;
import java.time.ZonedDateTime ;
import java.time.temporal.ChronoUnit ;
import java.time.temporal.ChronoUnit ;
@ -321,6 +319,8 @@ public class MockRace extends Race {
if ( ! finish & & totalElapsedMilliseconds > = updatePeriodMilliseconds ) {
if ( ! finish & & totalElapsedMilliseconds > = updatePeriodMilliseconds ) {
checkPosition ( boat , totalElapsedMilliseconds ) ;
if ( boat . getCurrentSpeed ( ) = = 0 ) {
if ( boat . getCurrentSpeed ( ) = = 0 ) {
newOptimalVMG ( boat ) ;
newOptimalVMG ( boat ) ;
boat . setBearing ( boat . calculateBearingToNextMarker ( ) ) ;
boat . setBearing ( boat . calculateBearingToNextMarker ( ) ) ;
@ -467,22 +467,22 @@ public class MockRace extends Race {
* @param boat the boat that is rounding a mark
* @param boat the boat that is rounding a mark
* @param roundingChecks the checks to run
* @param roundingChecks the checks to run
* /
* /
private void boatRoundingCheckPort ( MockBoat boat , List < GPSCoordinate > roundingChecks ){
private void boatRoundingCheckPort ( MockBoat boat , List < GPSCoordinate > roundingChecks , Bearing legBearing ){
//boats must pass all checks in order to round a mark
//boats must pass all checks in order to round a mark
switch ( boat . getRoundingStatus ( ) ) {
switch ( boat . getRoundingStatus ( ) ) {
case 0 : //hasn't started rounding
case 0 : //hasn't started rounding
// System.out.println("round 0");
if ( boat . isPortSide ( boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getMarkForRounding ( legBearing ) ) & &
if ( boat . isPortSid e( boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getMark 1( ) ) & &
GPSCoordinate . passesLin e( boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getMark ForRounding( legBearing ) . getPosition ( ) ,
GPSCoordinate . intersects ( boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getMark1 ( ) . getPosition ( ) ,
roundingChecks . get ( 0 ) , boat . getCurrentPosition ( ) , legBearing ) ) {
roundingChecks . get ( 0 ) , boat . getCurrentPosition ( ) ) ) {
System . out . println ( "true" ) ;
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");
// System.out.println("round 1");
if ( boat . isPortSide ( boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getMark 1( ) ) & &
if ( boat . isPortSide ( boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getMark ForRounding( legBearing ) ) & &
GPSCoordinate . intersects ( boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getMark 1( ) . getPosition ( ) ,
GPSCoordinate . passesLine ( boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getMark ForRounding( legBearing ) . getPosition ( ) ,
roundingChecks . get ( 1 ) , boat . getCurrentPosition ( ) )) {
roundingChecks . get ( 1 ) , boat . getCurrentPosition ( ) , Bearing . fromDegrees ( legBearing . degrees ( ) - 90 ) )) { //negitive 90 from bearing because of port rounding
boat . increaseRoundingStatus ( ) ;
boat . increaseRoundingStatus ( ) ;
}
}
break ;
break ;
@ -533,7 +533,6 @@ public class MockRace extends Race {
* @param timeElapsed The total time , in milliseconds , that has elapsed since the race started .
* @param timeElapsed The total time , in milliseconds , that has elapsed since the race started .
* /
* /
protected void checkPosition ( MockBoat boat , long timeElapsed ) {
protected void checkPosition ( MockBoat boat , long timeElapsed ) {
//The distance, in nautical miles, within which the boat needs to get in order to consider that it has reached the marker.
//The distance, in nautical miles, within which the boat needs to get in order to consider that it has reached the marker.
double epsilonNauticalMiles = 250.0 / Constants . NMToMetersConversion ; //250 meters.
double epsilonNauticalMiles = 250.0 / Constants . NMToMetersConversion ; //250 meters.
@ -541,17 +540,15 @@ public class MockRace extends Race {
//Boat is within an acceptable distance from the mark.
//Boat is within an acceptable distance from the mark.
GPSCoordinate startDirectionLinePoint = boat . getCurrentLeg ( ) . getStartCompoundMark ( ) . getMark1Position ( ) ;
GPSCoordinate startDirectionLinePoint = boat . getCurrentLeg ( ) . getStartCompoundMark ( ) . getMark1Position ( ) ;
//todo will need to change this for gates, so that the end point is the side of the gate needed to be rounded
GPSCoordinate endDirectionLinePoint = boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getMark1Position ( ) ;
GPSCoordinate endDirectionLinePoint = boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getMark1Position ( ) ;
Bearing bearingOfDirectionLine = GPSCoordinate . calculateBearing ( startDirectionLinePoint , endDirectionLinePoint ) ;
Bearing bearingOfDirectionLine = GPSCoordinate . calculateBearing ( startDirectionLinePoint , endDirectionLinePoint ) ;
//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
GPSCoordinate roundCheck1 = GPSCoordinate . calculateNewPosition ( start DirectionLinePoint,
GPSCoordinate roundCheck1 = GPSCoordinate . calculateNewPosition ( end DirectionLinePoint,
epsilonNauticalMiles , Azimuth . fromDegrees ( bearingOfDirectionLine . degrees ( ) + 90 ) ) ; //adding 90 so the check line is parallel
epsilonNauticalMiles , Azimuth . fromDegrees ( bearingOfDirectionLine . degrees ( ) + 90 ) ) ; //adding 90 so the check line is parallel
GPSCoordinate roundCheck2 = GPSCoordinate . calculateNewPosition ( start DirectionLinePoint,
GPSCoordinate roundCheck2 = GPSCoordinate . calculateNewPosition ( end DirectionLinePoint,
epsilonNauticalMiles , Azimuth . fromDegrees ( bearingOfDirectionLine . degrees ( ) ) ) ;
epsilonNauticalMiles , Azimuth . fromDegrees ( bearingOfDirectionLine . degrees ( ) ) ) ;
List < GPSCoordinate > roundingChecks = new ArrayList < GPSCoordinate > ( Arrays . asList ( roundCheck1 , roundCheck2 ) ) ;
List < GPSCoordinate > roundingChecks = new ArrayList < GPSCoordinate > ( Arrays . asList ( roundCheck1 , roundCheck2 ) ) ;
@ -559,7 +556,7 @@ public class MockRace extends Race {
switch ( boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getRoundingType ( ) ) {
switch ( boat . getCurrentLeg ( ) . getEndCompoundMark ( ) . getRoundingType ( ) ) {
case SP : //Not yet implemented so these gates will be rounded port side
case SP : //Not yet implemented so these gates will be rounded port side
case Port :
case Port :
boatRoundingCheckPort ( boat , roundingChecks );
boatRoundingCheckPort ( boat , roundingChecks , bearingOfDirectionLine );
break ;
break ;
case PS : //not yet implemented so these gates will be rounded starboard side
case PS : //not yet implemented so these gates will be rounded starboard side
case Starboard :
case Starboard :