Fixing some of the SharedModel/seng302 import conflicts
-Am really not liking the SharedModel structure, think reverting back to original structure is worth discussing story[778]
This commit is contained in:
@@ -5,9 +5,9 @@ import javafx.animation.AnimationTimer;
|
|||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import org.geotools.referencing.GeodeticCalculator;
|
import org.geotools.referencing.GeodeticCalculator;
|
||||||
import seng302.DataInput.RaceDataSource;
|
|
||||||
|
|
||||||
import SharedModel.*;
|
|
||||||
|
import seng302.DataInput.RaceDataSource;
|
||||||
import seng302.Networking.MockOutput;
|
import seng302.Networking.MockOutput;
|
||||||
import seng302.Networking.Utils.BoatStatusMessage;
|
import seng302.Networking.Utils.BoatStatusMessage;
|
||||||
import seng302.Networking.Utils.Enums.BoatStatus;
|
import seng302.Networking.Utils.Enums.BoatStatus;
|
||||||
@@ -24,9 +24,9 @@ import java.util.Random;
|
|||||||
* Created by fwy13 on 3/03/17.
|
* Created by fwy13 on 3/03/17.
|
||||||
*/
|
*/
|
||||||
public class Race implements Runnable {
|
public class Race implements Runnable {
|
||||||
//protected BoatInRace[] startingBoats;
|
//protected SharedModel.BoatInRace[] startingBoats;
|
||||||
protected ObservableList<BoatInRace> startingBoats;
|
protected ObservableList<SharedModel.BoatInRace> startingBoats;
|
||||||
protected List<Leg> legs;
|
protected List<SharedModel.Leg> legs;
|
||||||
protected int boatsFinished = 0;
|
protected int boatsFinished = 0;
|
||||||
protected long totalTimeElapsed;
|
protected long totalTimeElapsed;
|
||||||
protected int scaleFactor;
|
protected int scaleFactor;
|
||||||
@@ -44,11 +44,11 @@ public class Race implements Runnable {
|
|||||||
* @param legs Number of marks in order that the boats pass in order to complete the race.
|
* @param legs Number of marks in order that the boats pass in order to complete the race.
|
||||||
* @param scaleFactor for race
|
* @param scaleFactor for race
|
||||||
*/
|
*/
|
||||||
public Race(List<BoatInRace> boats, List<Leg> legs, int scaleFactor, MockOutput mockOutput) {
|
public Race(List<SharedModel.BoatInRace> boats, List<SharedModel.Leg> legs, int scaleFactor, MockOutput mockOutput) {
|
||||||
|
|
||||||
this.startingBoats = FXCollections.observableArrayList(boats);
|
this.startingBoats = FXCollections.observableArrayList(boats);
|
||||||
this.legs = legs;
|
this.legs = legs;
|
||||||
this.legs.add(new Leg("Finish", this.legs.size()));
|
this.legs.add(new SharedModel.Leg("Finish", this.legs.size()));
|
||||||
this.scaleFactor = scaleFactor;
|
this.scaleFactor = scaleFactor;
|
||||||
this.mockOutput = mockOutput;
|
this.mockOutput = mockOutput;
|
||||||
|
|
||||||
@@ -68,14 +68,14 @@ public class Race implements Runnable {
|
|||||||
this.raceId = raceId;
|
this.raceId = raceId;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Calculates the boats next GPS position based on its distance travelled and heading
|
* Calculates the boats next SharedModel.GPS position based on its distance travelled and heading
|
||||||
*
|
*
|
||||||
* @param oldCoordinates GPS coordinates of the boat's starting position
|
* @param oldCoordinates SharedModel.GPS coordinates of the boat's starting position
|
||||||
* @param distanceTravelled distance in nautical miles
|
* @param distanceTravelled distance in nautical miles
|
||||||
* @param azimuth boat's current direction. Value between -180 and 180
|
* @param azimuth boat's current direction. Value between -180 and 180
|
||||||
* @return The boat's new coordinate
|
* @return The boat's new coordinate
|
||||||
*/
|
*/
|
||||||
public static GPSCoordinate calculatePosition(GPSCoordinate oldCoordinates, double distanceTravelled, double azimuth) {
|
public static SharedModel.GPSCoordinate calculatePosition(SharedModel.GPSCoordinate oldCoordinates, double distanceTravelled, double azimuth) {
|
||||||
|
|
||||||
//Find new coordinate using current heading and distance
|
//Find new coordinate using current heading and distance
|
||||||
|
|
||||||
@@ -84,11 +84,11 @@ public class Race implements Runnable {
|
|||||||
Point2D startPoint = new Point2D.Double(oldCoordinates.getLongitude(), oldCoordinates.getLatitude());
|
Point2D startPoint = new Point2D.Double(oldCoordinates.getLongitude(), oldCoordinates.getLatitude());
|
||||||
geodeticCalculator.setStartingGeographicPoint(startPoint);
|
geodeticCalculator.setStartingGeographicPoint(startPoint);
|
||||||
//load direction and distance tranvelled into calculator
|
//load direction and distance tranvelled into calculator
|
||||||
geodeticCalculator.setDirection(azimuth, distanceTravelled * Constants.NMToMetersConversion);
|
geodeticCalculator.setDirection(azimuth, distanceTravelled * SharedModel.Constants.NMToMetersConversion);
|
||||||
//get new point
|
//get new point
|
||||||
Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint();
|
Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint();
|
||||||
|
|
||||||
return new GPSCoordinate(endPoint.getY(), endPoint.getX());
|
return new SharedModel.GPSCoordinate(endPoint.getY(), endPoint.getX());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,7 +142,7 @@ public class Race implements Runnable {
|
|||||||
|
|
||||||
System.setProperty("javafx.animation.fullspeed", "true");
|
System.setProperty("javafx.animation.fullspeed", "true");
|
||||||
|
|
||||||
for (BoatInRace boat : startingBoats) {
|
for (SharedModel.BoatInRace boat : startingBoats) {
|
||||||
boat.setStarted(true);
|
boat.setStarted(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ public class Race implements Runnable {
|
|||||||
ArrayList<BoatStatusMessage> boatStatusMessages = new ArrayList<BoatStatusMessage>();
|
ArrayList<BoatStatusMessage> boatStatusMessages = new ArrayList<BoatStatusMessage>();
|
||||||
|
|
||||||
//For each boat, we update it's position, and generate a BoatLocationMessage.
|
//For each boat, we update it's position, and generate a BoatLocationMessage.
|
||||||
for (BoatInRace boat : startingBoats) {
|
for (SharedModel.BoatInRace boat : startingBoats) {
|
||||||
if (boat != null && !boat.isFinished()) {
|
if (boat != null && !boat.isFinished()) {
|
||||||
//Update position.
|
//Update position.
|
||||||
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
||||||
@@ -184,7 +184,7 @@ public class Race implements Runnable {
|
|||||||
*/
|
*/
|
||||||
protected void updatePositions() {
|
protected void updatePositions() {
|
||||||
FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
|
FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
|
||||||
for (BoatInRace boat : startingBoats) {
|
for (SharedModel.BoatInRace boat : startingBoats) {
|
||||||
if (boat != null) {
|
if (boat != null) {
|
||||||
boat.setPosition(Integer.toString(startingBoats.indexOf(boat) + 1));
|
boat.setPosition(Integer.toString(startingBoats.indexOf(boat) + 1));
|
||||||
//System.out.println(boat.toString() + " " + boat.getPosition());//TEMP debug print
|
//System.out.println(boat.toString() + " " + boat.getPosition());//TEMP debug print
|
||||||
@@ -196,16 +196,16 @@ public class Race implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initialiseBoats() {
|
public void initialiseBoats() {
|
||||||
Leg officialStart = legs.get(0);
|
SharedModel.Leg officialStart = legs.get(0);
|
||||||
String name = officialStart.getName();
|
String name = officialStart.getName();
|
||||||
Marker endMarker = officialStart.getEndMarker();
|
SharedModel.Marker endMarker = officialStart.getEndMarker();
|
||||||
|
|
||||||
ArrayList<Marker> startMarkers = getSpreadStartingPositions();
|
ArrayList<SharedModel.Marker> startMarkers = getSpreadStartingPositions();
|
||||||
for (int i = 0; i < startingBoats.size(); i++) {
|
for (int i = 0; i < startingBoats.size(); i++) {
|
||||||
BoatInRace boat = startingBoats.get(i);
|
SharedModel.BoatInRace boat = startingBoats.get(i);
|
||||||
if (boat != null) {
|
if (boat != null) {
|
||||||
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
|
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
|
||||||
Leg startLeg = new Leg(name, 0);
|
SharedModel.Leg startLeg = new SharedModel.Leg(name, 0);
|
||||||
boat.setCurrentPosition(startMarkers.get(i).getAverageGPSCoordinate());
|
boat.setCurrentPosition(startMarkers.get(i).getAverageGPSCoordinate());
|
||||||
startLeg.setStartMarker(startMarkers.get(i));
|
startLeg.setStartMarker(startMarkers.get(i));
|
||||||
startLeg.setEndMarker(endMarker);
|
startLeg.setEndMarker(endMarker);
|
||||||
@@ -221,10 +221,10 @@ public class Race implements Runnable {
|
|||||||
*
|
*
|
||||||
* @return list of starting positions
|
* @return list of starting positions
|
||||||
*/
|
*/
|
||||||
public ArrayList<Marker> getSpreadStartingPositions() {
|
public ArrayList<SharedModel.Marker> getSpreadStartingPositions() {
|
||||||
|
|
||||||
int nBoats = startingBoats.size();
|
int nBoats = startingBoats.size();
|
||||||
Marker marker = legs.get(0).getStartMarker();
|
SharedModel.Marker marker = legs.get(0).getStartMarker();
|
||||||
|
|
||||||
GeodeticCalculator initialCalc = new GeodeticCalculator();
|
GeodeticCalculator initialCalc = new GeodeticCalculator();
|
||||||
initialCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
initialCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
||||||
@@ -236,12 +236,12 @@ public class Race implements Runnable {
|
|||||||
|
|
||||||
GeodeticCalculator positionCalc = new GeodeticCalculator();
|
GeodeticCalculator positionCalc = new GeodeticCalculator();
|
||||||
positionCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
positionCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
||||||
ArrayList<Marker> positions = new ArrayList<>();
|
ArrayList<SharedModel.Marker> positions = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < nBoats; i++) {
|
for (int i = 0; i < nBoats; i++) {
|
||||||
positionCalc.setDirection(azimuth, distanceBetweenBoats);
|
positionCalc.setDirection(azimuth, distanceBetweenBoats);
|
||||||
Point2D position = positionCalc.getDestinationGeographicPoint();
|
Point2D position = positionCalc.getDestinationGeographicPoint();
|
||||||
positions.add(new Marker(new GPSCoordinate(position.getY(), position.getX())));
|
positions.add(new SharedModel.Marker(new SharedModel.GPSCoordinate(position.getY(), position.getX())));
|
||||||
|
|
||||||
positionCalc = new GeodeticCalculator();
|
positionCalc = new GeodeticCalculator();
|
||||||
positionCalc.setStartingGeographicPoint(position);
|
positionCalc.setStartingGeographicPoint(position);
|
||||||
@@ -271,7 +271,7 @@ public class Race implements Runnable {
|
|||||||
* @param boat to be updated
|
* @param boat to be updated
|
||||||
* @param millisecondsElapsed since last update
|
* @param millisecondsElapsed since last update
|
||||||
*/
|
*/
|
||||||
protected void updatePosition(BoatInRace boat, int millisecondsElapsed) {
|
protected void updatePosition(SharedModel.BoatInRace boat, int millisecondsElapsed) {
|
||||||
|
|
||||||
//distanceTravelled = velocity (nm p hr) * time taken to update loop
|
//distanceTravelled = velocity (nm p hr) * time taken to update loop
|
||||||
double distanceTravelled = (boat.getScaledVelocity() * millisecondsElapsed) / 3600000;
|
double distanceTravelled = (boat.getScaledVelocity() * millisecondsElapsed) / 3600000;
|
||||||
@@ -289,7 +289,7 @@ public class Race implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
protected void checkPosition(SharedModel.BoatInRace boat, long timeElapsed) {
|
||||||
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()) {
|
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()) {
|
||||||
//boat has passed onto new leg
|
//boat has passed onto new leg
|
||||||
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
||||||
@@ -300,14 +300,14 @@ public class Race implements Runnable {
|
|||||||
} else if (doNotFinish()) {
|
} else if (doNotFinish()) {
|
||||||
boatsFinished++;
|
boatsFinished++;
|
||||||
boat.setFinished(true);
|
boat.setFinished(true);
|
||||||
boat.setCurrentLeg(new Leg("DNF", -1));
|
boat.setCurrentLeg(new SharedModel.Leg("DNF", -1));
|
||||||
boat.setVelocity(0);
|
boat.setVelocity(0);
|
||||||
boat.setScaledVelocity(0);
|
boat.setScaledVelocity(0);
|
||||||
} else {
|
} else {
|
||||||
//Calculate how much the boat overshot the marker by
|
//Calculate how much the boat overshot the marker by
|
||||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
||||||
//Move boat on to next leg
|
//Move boat on to next leg
|
||||||
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
SharedModel.Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
||||||
|
|
||||||
boat.setCurrentLeg(nextLeg);
|
boat.setCurrentLeg(nextLeg);
|
||||||
//Add overshoot distance into the distance travelled for the next leg
|
//Add overshoot distance into the distance travelled for the next leg
|
||||||
@@ -321,11 +321,11 @@ public class Race implements Runnable {
|
|||||||
/**
|
/**
|
||||||
* Returns the boats that have started the race.
|
* Returns the boats that have started the race.
|
||||||
*
|
*
|
||||||
* @return ObservableList of BoatInRace class that participated in the race.
|
* @return ObservableList of SharedModel.BoatInRace class that participated in the race.
|
||||||
* @see ObservableList
|
* @see ObservableList
|
||||||
* @see BoatInRace
|
* @see SharedModel.BoatInRace
|
||||||
*/
|
*/
|
||||||
public ObservableList<BoatInRace> getStartingBoats() {
|
public ObservableList<SharedModel.BoatInRace> getStartingBoats() {
|
||||||
return startingBoats;
|
return startingBoats;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,24 +13,24 @@ public class BoatInRaceTest {
|
|||||||
|
|
||||||
|
|
||||||
private GPSCoordinate ORIGIN_COORDS = new GPSCoordinate(0, 0);
|
private GPSCoordinate ORIGIN_COORDS = new GPSCoordinate(0, 0);
|
||||||
private BoatInRace TEST_BOAT = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt", 1);
|
private SharedModel.BoatInRace TEST_BOAT = new SharedModel.BoatInRace("Test", 1, Color.ALICEBLUE, "tt", 1);
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void calculateDueNorthAzimuthReturns0() {
|
public void calculateDueNorthAzimuthReturns0() {
|
||||||
|
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(50, 0));
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8);
|
assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void calculateDueSouthAzimuthReturns180() {
|
public void calculateDueSouthAzimuthReturns180() {
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
|
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(-50, 0));
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8);
|
assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8);
|
||||||
}
|
}
|
||||||
@@ -39,9 +39,9 @@ public class BoatInRaceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void calculateDueEastAzimuthReturns90() {
|
public void calculateDueEastAzimuthReturns90() {
|
||||||
|
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(0, 50));
|
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(0, 50));
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8);
|
assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8);
|
||||||
}
|
}
|
||||||
@@ -49,9 +49,9 @@ public class BoatInRaceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void calculateDueWestAzimuthReturnsNegative90() {
|
public void calculateDueWestAzimuthReturnsNegative90() {
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(0, -50));
|
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(0, -50));
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8);
|
assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8);
|
||||||
|
|
||||||
@@ -60,9 +60,9 @@ public class BoatInRaceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void calculateDueNorthHeadingReturns0() {
|
public void calculateDueNorthHeadingReturns0() {
|
||||||
|
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(50, 0));
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateHeading(), 0, 1e-8);
|
assertEquals(TEST_BOAT.calculateHeading(), 0, 1e-8);
|
||||||
}
|
}
|
||||||
@@ -70,37 +70,37 @@ public class BoatInRaceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void calculateDueEastHeadingReturns90() {
|
public void calculateDueEastHeadingReturns90() {
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(0, 50));
|
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(0, 50));
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateHeading(), 90, 1e-8);
|
assertEquals(TEST_BOAT.calculateHeading(), 90, 1e-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void calculateDueSouthHeadingReturns180() {
|
public void calculateDueSouthHeadingReturns180() {
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
|
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(-50, 0));
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateHeading(), 180, 1e-8);
|
assertEquals(TEST_BOAT.calculateHeading(), 180, 1e-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void calculateDueWestHeadingReturns270() {
|
public void calculateDueWestHeadingReturns270() {
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(0, -50));
|
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(0, -50));
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateHeading(), 270, 1e-8);
|
assertEquals(TEST_BOAT.calculateHeading(), 270, 1e-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createNewBoatCratesInstanceOfSuperClass() {
|
public void createNewBoatCreatesInstanceOfSuperClass() {
|
||||||
|
|
||||||
BoatInRace testBoat = new BoatInRace("Boat", 20, Color.ALICEBLUE, "tt", 1);
|
SharedModel.BoatInRace testBoat = new SharedModel.BoatInRace("Boat", 20, Color.ALICEBLUE, "tt", 1);
|
||||||
testBoat.setName("Name can change");
|
testBoat.setName("Name can change");
|
||||||
assertTrue(testBoat instanceof Boat);
|
assertTrue(testBoat instanceof SharedModel.Boat);
|
||||||
assertTrue(testBoat.getCurrentLeg() == null);
|
assertTrue(testBoat.getCurrentLeg() == null);
|
||||||
assertTrue(testBoat.getCurrentPosition() == null);
|
assertTrue(testBoat.getCurrentPosition() == null);
|
||||||
assertTrue(testBoat.toString().contains("Name can change"));
|
assertTrue(testBoat.toString().contains("Name can change"));
|
||||||
@@ -115,19 +115,19 @@ public class BoatInRaceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getWakeAtProperHeading() throws Exception {
|
public void getWakeAtProperHeading() throws Exception {
|
||||||
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt", 1);
|
SharedModel.BoatInRace boat = new SharedModel.BoatInRace("Test", 1, Color.ALICEBLUE, "tt", 1);
|
||||||
|
|
||||||
// Construct leg of 0 degrees
|
// Construct leg of 0 degrees
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(50, 0));
|
||||||
Leg leg0deg = new Leg("Start", startMarker, endMarker, 0);
|
SharedModel.Leg leg0deg = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||||
boat.setCurrentLeg(leg0deg);
|
boat.setCurrentLeg(leg0deg);
|
||||||
boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||||
|
|
||||||
assertEquals(0, boat.calculateHeading(), 1e-8);
|
assertEquals(0, boat.calculateHeading(), 1e-8);
|
||||||
|
|
||||||
// Construct leg from wake - heading should be 180 degrees
|
// Construct leg from wake - heading should be 180 degrees
|
||||||
Leg leg180deg = new Leg("Start", startMarker, new Marker(boat.getWake()), 0);
|
SharedModel.Leg leg180deg = new SharedModel.Leg("Start", startMarker, new SharedModel.Marker(boat.getWake()), 0);
|
||||||
boat.setCurrentLeg(leg180deg);
|
boat.setCurrentLeg(leg180deg);
|
||||||
|
|
||||||
assertEquals(180, boat.calculateHeading(), 1e-8);
|
assertEquals(180, boat.calculateHeading(), 1e-8);
|
||||||
@@ -136,12 +136,12 @@ public class BoatInRaceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getWakeProportionalToVelocity() throws Exception {
|
public void getWakeProportionalToVelocity() throws Exception {
|
||||||
BoatInRace boat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 1);
|
SharedModel.BoatInRace boat = new SharedModel.BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 1);
|
||||||
|
|
||||||
// Construct leg of 0 degrees at 0 N
|
// Construct leg of 0 degrees at 0 N
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(50, 0));
|
||||||
Leg leg0deg = new Leg("Start", startMarker, endMarker, 0);
|
SharedModel.Leg leg0deg = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||||
boat.setCurrentLeg(leg0deg);
|
boat.setCurrentLeg(leg0deg);
|
||||||
boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import javafx.scene.paint.Color;
|
|||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import seng302.GPSCoordinate;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
@@ -34,8 +35,8 @@ import static org.mockito.Mockito.verify;
|
|||||||
public class RaceTest {
|
public class RaceTest {
|
||||||
|
|
||||||
private static MockOutput mockOutput;
|
private static MockOutput mockOutput;
|
||||||
Leg START_LEG = new Leg("Start", new Marker(new GPSCoordinate(0, 0)), new Marker(new GPSCoordinate(1, 1)), 0);
|
SharedModel.Leg START_LEG = new SharedModel.Leg("Start", new SharedModel.Marker(new SharedModel.GPSCoordinate(0, 0)), new SharedModel.Marker(new SharedModel.GPSCoordinate(1, 1)), 0);
|
||||||
Leg FINISH_LEG = new Leg("Finish", new Marker(new GPSCoordinate(1, 1)), new Marker(new GPSCoordinate(2, 2)), 0);
|
SharedModel.Leg FINISH_LEG = new SharedModel.Leg("Finish", new SharedModel.Marker(new SharedModel.GPSCoordinate(1, 1)), new SharedModel.Marker(new SharedModel.GPSCoordinate(2, 2)), 0);
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() {
|
public static void setUp() {
|
||||||
@@ -76,13 +77,13 @@ public class RaceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void timerCanBeDisabled() {
|
public void timerCanBeDisabled() {
|
||||||
BoatInRace boat1 = new BoatInRace("Test 1", 10000, Color.ALICEBLUE, "t1", 1);
|
SharedModel.BoatInRace boat1 = new SharedModel.BoatInRace("Test 1", 10000, Color.ALICEBLUE, "t1", 1);
|
||||||
BoatInRace boat2 = new BoatInRace("Test 2", 10000, Color.BURLYWOOD, "t2", 2);
|
SharedModel.BoatInRace boat2 = new SharedModel.BoatInRace("Test 2", 10000, Color.BURLYWOOD, "t2", 2);
|
||||||
List<BoatInRace> boats = new ArrayList<>();
|
List<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||||
boats.add(boat1);
|
boats.add(boat1);
|
||||||
boats.add(boat2);
|
boats.add(boat2);
|
||||||
|
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||||
legs.add(START_LEG);
|
legs.add(START_LEG);
|
||||||
legs.add(FINISH_LEG);
|
legs.add(FINISH_LEG);
|
||||||
|
|
||||||
@@ -97,15 +98,15 @@ public class RaceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void checkPositionUpdatesNumberFinishedBoats() {
|
public void checkPositionUpdatesNumberFinishedBoats() {
|
||||||
|
|
||||||
BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt", 1);
|
SharedModel.BoatInRace finishedBoat = new SharedModel.BoatInRace("Test", 1000, Color.ALICEBLUE, "tt", 1);
|
||||||
finishedBoat.setDistanceTravelledInLeg(500);
|
finishedBoat.setDistanceTravelledInLeg(500);
|
||||||
|
|
||||||
finishedBoat.setCurrentLeg(FINISH_LEG);
|
finishedBoat.setCurrentLeg(FINISH_LEG);
|
||||||
|
|
||||||
ArrayList<BoatInRace> boats = new ArrayList<>();
|
ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||||
boats.add(finishedBoat);
|
boats.add(finishedBoat);
|
||||||
|
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||||
legs.add(FINISH_LEG);
|
legs.add(FINISH_LEG);
|
||||||
|
|
||||||
Race race = new Race(boats, legs, 5, mockOutput);
|
Race race = new Race(boats, legs, 5, mockOutput);
|
||||||
@@ -122,15 +123,15 @@ public class RaceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void checkPositionDoesntUpdateNumberFinishedBoats() {
|
public void checkPositionDoesntUpdateNumberFinishedBoats() {
|
||||||
|
|
||||||
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 1);
|
SharedModel.BoatInRace unFinishedBoat = new SharedModel.BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 1);
|
||||||
unFinishedBoat.setDistanceTravelledInLeg(0);
|
unFinishedBoat.setDistanceTravelledInLeg(0);
|
||||||
|
|
||||||
unFinishedBoat.setCurrentLeg(FINISH_LEG);
|
unFinishedBoat.setCurrentLeg(FINISH_LEG);
|
||||||
|
|
||||||
ArrayList<BoatInRace> boats = new ArrayList<>();
|
ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||||
boats.add(unFinishedBoat);
|
boats.add(unFinishedBoat);
|
||||||
|
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||||
legs.add(FINISH_LEG);
|
legs.add(FINISH_LEG);
|
||||||
|
|
||||||
|
|
||||||
@@ -145,9 +146,9 @@ public class RaceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
||||||
|
|
||||||
ArrayList<BoatInRace> boats = new ArrayList<>();
|
ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||||
|
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||||
|
|
||||||
legs.add(START_LEG);
|
legs.add(START_LEG);
|
||||||
legs.add(FINISH_LEG);
|
legs.add(FINISH_LEG);
|
||||||
@@ -155,7 +156,7 @@ public class RaceTest {
|
|||||||
Race race = new Race(boats, legs, 1, mockOutput);
|
Race race = new Race(boats, legs, 1, mockOutput);
|
||||||
race.setDnfChance(0);
|
race.setDnfChance(0);
|
||||||
|
|
||||||
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 1);
|
SharedModel.BoatInRace unFinishedBoat = new SharedModel.BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 4);
|
||||||
unFinishedBoat.setDistanceTravelledInLeg(100);
|
unFinishedBoat.setDistanceTravelledInLeg(100);
|
||||||
unFinishedBoat.setCurrentLeg(START_LEG);
|
unFinishedBoat.setCurrentLeg(START_LEG);
|
||||||
|
|
||||||
@@ -169,9 +170,9 @@ public class RaceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void timerDelaysByHalfSecond() throws InterruptedException {
|
public void timerDelaysByHalfSecond() throws InterruptedException {
|
||||||
|
|
||||||
ArrayList<BoatInRace> boats = new ArrayList<>();
|
ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||||
|
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||||
legs.add(START_LEG);
|
legs.add(START_LEG);
|
||||||
|
|
||||||
Race race = new Race(boats, legs, 1, mockOutput);
|
Race race = new Race(boats, legs, 1, mockOutput);
|
||||||
@@ -195,17 +196,17 @@ public class RaceTest {
|
|||||||
float vel2 = (float) 1.999;
|
float vel2 = (float) 1.999;
|
||||||
float vel3 = (float) 32.5;
|
float vel3 = (float) 32.5;
|
||||||
float vel4 = 500;
|
float vel4 = 500;
|
||||||
BoatInRace boat1 = new BoatInRace("test", vel1, Color.ALICEBLUE, "tt", 1);
|
SharedModel.BoatInRace boat1 = new SharedModel.BoatInRace("test", vel1, Color.ALICEBLUE, "tt",1);
|
||||||
BoatInRace boat2 = new BoatInRace("test", vel2, Color.ALICEBLUE, "tt", 2);
|
SharedModel.BoatInRace boat2 = new SharedModel.BoatInRace("test", vel2, Color.ALICEBLUE, "tt", 2);
|
||||||
BoatInRace boat3 = new BoatInRace("test", vel3, Color.ALICEBLUE, "tt", 3);
|
SharedModel.BoatInRace boat3 = new SharedModel.BoatInRace("test", vel3, Color.ALICEBLUE, "tt", 3);
|
||||||
BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt", 4);
|
SharedModel.BoatInRace boat4 = new SharedModel.BoatInRace("test", vel4, Color.ALICEBLUE, "tt", 4);
|
||||||
ArrayList<BoatInRace> boats = new ArrayList<>();
|
ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
|
||||||
boats.add(boat1);
|
boats.add(boat1);
|
||||||
boats.add(boat2);
|
boats.add(boat2);
|
||||||
boats.add(boat3);
|
boats.add(boat3);
|
||||||
boats.add(boat4);
|
boats.add(boat4);
|
||||||
|
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||||
legs.add(START_LEG);
|
legs.add(START_LEG);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ public class BoatInRace extends Boat {
|
|||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
private StringProperty position;
|
private StringProperty position;
|
||||||
private double heading;
|
private double heading;
|
||||||
|
private int sourceID;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///While generating BoatLocationMessages, each one needs a sequence number relating to each boat.
|
///While generating BoatLocationMessages, each one needs a sequence number relating to each boat.
|
||||||
private long sequenceNumber = 0;
|
private long sequenceNumber = 0;
|
||||||
@@ -45,8 +48,11 @@ public class BoatInRace extends Boat {
|
|||||||
setColour(colour);
|
setColour(colour);
|
||||||
currentLegName = new SimpleStringProperty("");
|
currentLegName = new SimpleStringProperty("");
|
||||||
position = new SimpleStringProperty("-");
|
position = new SimpleStringProperty("-");
|
||||||
|
this.sourceID = sourceID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts an azimuth to a bearing
|
* Converts an azimuth to a bearing
|
||||||
*
|
*
|
||||||
@@ -264,6 +270,15 @@ public class BoatInRace extends Boat {
|
|||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSourceID() {
|
||||||
|
return sourceID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceID(int sourceID) {
|
||||||
|
this.sourceID = sourceID;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current sequence number, and increments the internal value, such that that next call will return a value 1 larger than the current call.
|
* Returns the current sequence number, and increments the internal value, such that that next call will return a value 1 larger than the current call.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user