diff --git a/src/main/java/seng302/model/Yacht.java b/src/main/java/seng302/model/Yacht.java index 38104e9e..d7cd1f9e 100644 --- a/src/main/java/seng302/model/Yacht.java +++ b/src/main/java/seng302/model/Yacht.java @@ -28,6 +28,8 @@ public class Yacht { void notifyLocation(Yacht yacht, double lat, double lon, double heading, double velocity); } + private static final Double ROUNDING_DISTANCE = 15d; // TODO: 3/08/17 wmu16 - Look into this value further + //BOTH AFAIK private String boatType; private Integer sourceId; @@ -37,9 +39,10 @@ public class Yacht { private String country; private Long estimateTimeAtFinish; - private Long timeTillNext; - private Double distanceToNextMark; + private Long lastMark; private Long markRoundTime; + private Double distanceToNextMark; + private Long timeTillNext; private CompoundMark nextMark; private Double heading; private Integer legNumber = 0; @@ -51,6 +54,11 @@ public class Yacht { private GeoPoint location; private Integer boatStatus; private Double velocity; + //MARK ROUNDING INFO + private GeoPoint lastLocation; //For purposes of mark rounding calculations + private Boolean hasEnteredRoundingZone; //The distance that the boat must be from the mark to round + private Boolean hasPassedFirstLine; //The line extrapolated from the next mark to the current mark + private Boolean hasPassedSecondLine; //The line extrapolated from the last mark to the current mark //CLIENT SIDE private List locationListeners = new ArrayList<>(); @@ -71,8 +79,13 @@ public class Yacht { this.country = country; this.sailIn = false; this.location = new GeoPoint(57.670341, 11.826856); + this.lastLocation = location; this.heading = 120.0; //In degrees this.velocity = 0d; //in mms-1 + + this.hasEnteredRoundingZone = false; + this.hasPassedFirstLine = false; + this.hasPassedSecondLine = false; } /** @@ -108,9 +121,16 @@ public class Yacht { } } - Double metersCovered = velocity * secondsElapsed; - location = GeoUtility.getGeoCoordinate(location, heading, metersCovered); + //UPDATE BOAT LOCATION + location = GeoUtility.getGeoCoordinate(location, heading, velocity * secondsElapsed); + + //CHECK FOR MARK ROUNDING distanceToNextMark = calcDistanceToNextMark(); + if (distanceToNextMark < ROUNDING_DISTANCE) { + hasEnteredRoundingZone = true; + } + + // TODO: 3/08/17 wmu16 - Implement line cross check here } @@ -345,20 +365,21 @@ public class Yacht { return nextMark; } - public Double getLat() { - return location.getLat(); + public GeoPoint getLocation() { + return location; } - public void setLat(Double lat) { + /** + * Sets the current location of the boat in lat and long whilst preserving the last location + * + * @param lat Latitude + * @param lng Longitude + */ + public void setLocation(Double lat, Double lng) { + lastLocation.setLat(location.getLat()); + lastLocation.setLng(location.getLng()); location.setLat(lat); - } - - public Double getLon() { - return location.getLng(); - } - - public void setLon(Double lon) { - location.setLng(lon); + location.setLng(lng); } public Double getHeading() { @@ -378,10 +399,6 @@ public class Yacht { return boatName; } - public GeoPoint getLocation() { - return location; - } - public void updateTimeSinceLastMarkProperty(long timeSinceLastMark) { this.timeSinceLastMarkProperty.set(timeSinceLastMark); } @@ -416,14 +433,13 @@ public class Yacht { return distanceToNextMark; } - public void updateLocation (double lat, double lon, double heading, double velocity) { - location.setLat(lat); - location.setLng(lon); + public void updateLocation(double lat, double lng, double heading, double velocity) { + setLocation(lat, lng); this.heading = heading; this.velocity = velocity; updateVelocityProperty(velocity); for (YachtLocationListener yll : locationListeners) { - yll.notifyLocation(this, lat, lon, heading, velocity); + yll.notifyLocation(this, lat, lng, heading, velocity); } } diff --git a/src/main/java/seng302/utilities/GeoUtility.java b/src/main/java/seng302/utilities/GeoUtility.java index 54b0484a..0a49c776 100644 --- a/src/main/java/seng302/utilities/GeoUtility.java +++ b/src/main/java/seng302/utilities/GeoUtility.java @@ -96,8 +96,9 @@ public class GeoUtility { return new GeoPoint(Math.toDegrees(endLat), Math.toDegrees(endLng)); } - /** - * Performs the line function on two points of a line and a test point to test which side of the line that point is + + /** + * Performs the line function on two points of a line and a test point to test which side of the line that point is * on. If the return value is * return 1, then the point is on one side of the line, * return -1 then the point is on the other side of the line diff --git a/src/test/java/seng302/model/YachtTest.java b/src/test/java/seng302/model/YachtTest.java index e3144a55..7937b43c 100644 --- a/src/test/java/seng302/model/YachtTest.java +++ b/src/test/java/seng302/model/YachtTest.java @@ -31,8 +31,7 @@ public class YachtTest { "HaomingIsOk", "NZL"); - yacht.setLat(57.670333); - yacht.setLon(11.827833); + yacht.setLocation(57.670333, 11.827833); compoundMark = new CompoundMark(0, "HaomingsMark"); Mark subMark1 = new Mark("H", 57.671524, 11.844495, 0);