From e53d72f24b722c79e333e3917e6473925eca84d8 Mon Sep 17 00:00:00 2001 From: hba56 Date: Wed, 9 Aug 2017 23:25:42 +1200 Subject: [PATCH] compound marks now can give the mark they have that needs to be rounded this is used to draw the line around the correct mark #story[1101] --- .../main/java/shared/model/CompoundMark.java | 87 +++++++++++++++++++ .../visualiser/model/ResizableRaceCanvas.java | 32 +++++-- 2 files changed, 110 insertions(+), 9 deletions(-) diff --git a/racevisionGame/src/main/java/shared/model/CompoundMark.java b/racevisionGame/src/main/java/shared/model/CompoundMark.java index 38e972dc..05256655 100644 --- a/racevisionGame/src/main/java/shared/model/CompoundMark.java +++ b/racevisionGame/src/main/java/shared/model/CompoundMark.java @@ -164,4 +164,91 @@ public class CompoundMark { public void setRoundingType(RoundingType roundingType) { this.roundingType = roundingType; } + + /** + * Used to find the mark that is to be rounded at a gate when approaching from the south + * will also give the single mark if there is only one + * @param bearing the bearing a boat will approach form + * @return the mark to round + */ + public Mark getMarkForRounding(Bearing bearing){ + Mark westMostMark; + Mark eastMostMark; + Mark northMostMark; + Mark southMostMark; + + //check to see if there are two marks + if (mark2 == null){ + return mark1; + } + + //finds the mark furthest west and east + if(this.getMark1Position().getLatitude() > this.getMark2Position().getLatitude()){ + westMostMark = this.mark1; + eastMostMark = this.mark2; + }else{ + westMostMark = this.mark2; + eastMostMark = this.mark1; + } + + //finds the mark furthest north and south + if(this.getMark1Position().getLongitude() > this.getMark2Position().getLongitude()){ + northMostMark = this.mark1; + southMostMark = this.mark2; + }else{ + northMostMark = this.mark2; + southMostMark = this.mark1; + } + + if (bearing.degrees() > 315 || bearing.degrees() <= 45){ + //north + switch (this.getRoundingType()){ + case SP: + case Port: + return westMostMark; + case PS: + case Starboard: + return eastMostMark; + default:return null; + } + }else if(bearing.degrees() > 45 && bearing.degrees() <= 135){ + //east + switch (this.getRoundingType()){ + case SP: + case Port: + return northMostMark; + case PS: + case Starboard: + return southMostMark; + default:return null; + } + }else if(bearing.degrees() > 135 && bearing.degrees() <= 225){ + //south + switch (this.getRoundingType()){ + case SP: + case Port: + return eastMostMark; + case PS: + case Starboard: + return westMostMark; + default:return null; + } + }else if(bearing.degrees() > 225 && bearing.degrees() <= 315){ + //west + switch (this.getRoundingType()){ + case SP: + case Port: + return southMostMark; + case PS: + case Starboard: + return northMostMark; + default:return null; + } + }else{ + return null; + } + + } + + } diff --git a/racevisionGame/src/main/java/visualiser/model/ResizableRaceCanvas.java b/racevisionGame/src/main/java/visualiser/model/ResizableRaceCanvas.java index 96a8d6f9..333ed54b 100644 --- a/racevisionGame/src/main/java/visualiser/model/ResizableRaceCanvas.java +++ b/racevisionGame/src/main/java/visualiser/model/ResizableRaceCanvas.java @@ -1,12 +1,13 @@ package visualiser.model; -import javafx.scene.Node; import javafx.scene.image.Image; -import javafx.scene.paint.*; +import javafx.scene.paint.Color; +import javafx.scene.paint.Paint; import javafx.scene.transform.Rotate; import network.Messages.Enums.BoatStatusEnum; import shared.dataInput.RaceDataSource; +import shared.enums.RoundingType; import shared.model.*; import java.util.List; @@ -510,7 +511,12 @@ public class ResizableRaceCanvas extends ResizableCanvas { //finds the direction of the current leg as a bearing startDirectionLinePoint = legStartPoint; - endDirectionLinePoint = legs.get(index).getEndCompoundMark().getMark1Position(); + GPSCoordinate tempEndDirectionLinePoint = legs.get(index).getEndCompoundMark().getAverageGPSCoordinate(); + + bearingOfDirectionLine = GPSCoordinate.calculateBearing(startDirectionLinePoint, tempEndDirectionLinePoint); + + //after finding the initial bearing pick the mark used for rounding + endDirectionLinePoint = legs.get(index).getEndCompoundMark().getMarkForRounding(bearingOfDirectionLine).getPosition(); bearingOfDirectionLine = GPSCoordinate.calculateBearing(startDirectionLinePoint, endDirectionLinePoint); //finds the direction of the next leg as a bearing @@ -519,13 +525,22 @@ public class ResizableRaceCanvas extends ResizableCanvas { endNextDirectionLinePoint = legs.get(index + 1).getEndCompoundMark().getMark1Position(); bearingOfNextDirectionLine = GPSCoordinate.calculateBearing(startNextDirectionLinePoint, endNextDirectionLinePoint); + double degreesToAdd; + //find which side is need to be used + if (legs.get(index).getEndCompoundMark().getRoundingType() == RoundingType.Port || + legs.get(index).getEndCompoundMark().getRoundingType() == RoundingType.SP){ + degreesToAdd = 90; + }else{ + degreesToAdd = -90; + } + //use the direction line to find a point parallel to it by the mark GPSCoordinate pointToStartCurve = GPSCoordinate.calculateNewPosition(endDirectionLinePoint, - 100, Azimuth.fromDegrees(bearingOfDirectionLine.degrees()+90)); + 100, Azimuth.fromDegrees(bearingOfDirectionLine.degrees()+degreesToAdd)); //use the direction line to find a point to curve too GPSCoordinate pointToEndCurve = GPSCoordinate.calculateNewPosition(endDirectionLinePoint, - 100, Azimuth.fromDegrees(bearingOfNextDirectionLine.degrees()+90)); + 100, Azimuth.fromDegrees(bearingOfNextDirectionLine.degrees()+degreesToAdd)); //use the curve points to find the two control points for the bezier curve GPSCoordinate controlPoint; @@ -534,14 +549,14 @@ public class ResizableRaceCanvas extends ResizableCanvas { if ((bearingOfDirectionLine.degrees() - bearingOfNextDirectionLine.degrees() +360)%360< 145){ //small turn controlPoint = GPSCoordinate.calculateNewPosition(pointToStartCurve, - 50, Azimuth.fromDegrees(bearingOfCurveLine.degrees()+45)); + 50, Azimuth.fromDegrees(bearingOfCurveLine.degrees()+(degreesToAdd/2))); controlPoint2 = controlPoint; }else{ //large turn controlPoint = GPSCoordinate.calculateNewPosition(pointToStartCurve, - 150, Azimuth.fromDegrees(bearingOfCurveLine.degrees()+90)); + 150, Azimuth.fromDegrees(bearingOfCurveLine.degrees()+degreesToAdd)); controlPoint2 = GPSCoordinate.calculateNewPosition(pointToEndCurve, - 150, Azimuth.fromDegrees(bearingOfCurveLine.degrees()+90)); + 150, Azimuth.fromDegrees(bearingOfCurveLine.degrees()+degreesToAdd)); } @@ -618,7 +633,6 @@ public class ResizableRaceCanvas extends ResizableCanvas { * @see TrackPoint */ private void drawTrack(VisualiserBoat boat) { - //Check that track points are enabled. if (this.annoPath) {