From db3f4a5b2bfc5c179e8dcf1ba145bc38cba7fdc9 Mon Sep 17 00:00:00 2001 From: hba56 Date: Tue, 23 May 2017 14:56:07 +1200 Subject: [PATCH] fix to keep boats in the bounds #story[#874, 873] --- mock/src/main/java/seng302/Model/Angle.java | 3 +++ mock/src/main/java/seng302/Model/Race.java | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/mock/src/main/java/seng302/Model/Angle.java b/mock/src/main/java/seng302/Model/Angle.java index 8fa767dd..0fa6db0c 100644 --- a/mock/src/main/java/seng302/Model/Angle.java +++ b/mock/src/main/java/seng302/Model/Angle.java @@ -54,6 +54,9 @@ public class Angle implements Comparable { return this.degrees; } + public void setDegrees(double degrees) { + this.degrees = degrees; + } /** * Returns the value of this Angle object, in radians. diff --git a/mock/src/main/java/seng302/Model/Race.java b/mock/src/main/java/seng302/Model/Race.java index c894b21f..98ce3d7c 100644 --- a/mock/src/main/java/seng302/Model/Race.java +++ b/mock/src/main/java/seng302/Model/Race.java @@ -589,9 +589,22 @@ public class Race implements Runnable { VMG newVMG = this.calculateVMG(boat, bearingBounds); + + + //If the new vmg improves velocity, use it. if (improvesVelocity(boat, newVMG)) { boat.setVMG(newVMG); + }else if (!GPSCoordinate.isInsideBoundary(boat.getCurrentPosition(), boundary)){ + //checks to see if the new vmg sends the boat out of bounds and if so mirrors its direction in the wind + Azimuth azimuth = Azimuth.fromBearing(boat.getBearing()); + GPSCoordinate test = GPSCoordinate.calculateNewPosition(boat.getCurrentPosition(), + (100.0 / Constants.NMToMetersConversion), azimuth); + double currDegrees = newVMG.getBearing().degrees(); + double windDirectionDegrees = this.windDirection.degrees(); + double tempHeading = (currDegrees - windDirectionDegrees +90)%360; + newVMG.getBearing().setDegrees(tempHeading); + boat.setVMG(newVMG); }