Removed the rest of the shared model classes needed by mock
#story[778]
This commit is contained in:
@@ -52,12 +52,6 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>seng302</groupId>
|
||||
<artifactId>sharedModel</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package seng302;
|
||||
|
||||
/**
|
||||
* Constants that are used throughout the program
|
||||
* Created by Erika on 19-Mar-17.
|
||||
*/
|
||||
public class Constants {
|
||||
|
||||
public static final int NMToMetersConversion = 1852; // 1 nautical mile = 1852 meters
|
||||
|
||||
//Knots x this = meters per second.
|
||||
public static final double KnotsToMetersPerSecondConversionFactor = 0.514444;
|
||||
|
||||
public static final double wakeScale = 10;
|
||||
|
||||
}
|
||||
@@ -4,9 +4,9 @@ import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import seng302.DataInput.RaceDataSource;
|
||||
import seng302.Exceptions.InvalidRaceDataException;
|
||||
import SharedModel.GPSCoordinate;
|
||||
import SharedModel.Marker;
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.GPSCoordinate;
|
||||
import seng302.Model.Marker;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package seng302.DataInput;
|
||||
|
||||
import SharedModel.GPSCoordinate;
|
||||
import SharedModel.Leg;
|
||||
import SharedModel.Marker;
|
||||
;
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.GPSCoordinate;
|
||||
import seng302.Model.Leg;
|
||||
import seng302.Model.Marker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -4,10 +4,11 @@ import javafx.scene.paint.Color;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
import SharedModel.GPSCoordinate;
|
||||
import SharedModel.Leg;
|
||||
import SharedModel.Marker;
|
||||
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.GPSCoordinate;
|
||||
import seng302.Model.Leg;
|
||||
import seng302.Model.Marker;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package seng302.DataInput;
|
||||
|
||||
import SharedModel.Regatta;
|
||||
|
||||
import seng302.Model.Regatta;
|
||||
|
||||
/**
|
||||
* Created by zwu18 on 25/04/17.
|
||||
|
||||
@@ -3,7 +3,8 @@ package seng302.DataInput;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
import SharedModel.Regatta;
|
||||
import seng302.Model.Regatta;
|
||||
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package seng302.Model;
|
||||
|
||||
import SharedModel.*;
|
||||
import SharedModel.Leg;
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
|
||||
|
||||
@@ -14,7 +12,7 @@ public class Boat {
|
||||
private double scaledVelocity;
|
||||
private String abbrev;
|
||||
private int sourceID;
|
||||
private SharedModel.Leg currentLeg;
|
||||
private Leg currentLeg;
|
||||
private double distanceTravelledInLeg;
|
||||
private GPSCoordinate currentPosition;
|
||||
private long timeFinished = -1;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package SharedModel;
|
||||
package seng302.Model;
|
||||
|
||||
/**
|
||||
* GPS Coordinate for the world map.
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package SharedModel;
|
||||
package seng302.Model;
|
||||
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import seng302.Constants;
|
||||
|
||||
|
||||
/**
|
||||
+1
-2
@@ -1,7 +1,6 @@
|
||||
package SharedModel;
|
||||
package seng302.Model;
|
||||
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
/**
|
||||
@@ -7,6 +7,7 @@ import javafx.collections.ObservableList;
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
|
||||
|
||||
import seng302.Constants;
|
||||
import seng302.DataInput.RaceDataSource;
|
||||
import seng302.Networking.MockOutput;
|
||||
import seng302.Networking.Utils.BoatStatusMessage;
|
||||
@@ -26,7 +27,7 @@ import java.util.Random;
|
||||
public class Race implements Runnable {
|
||||
//protected Boat[] startingBoats;
|
||||
protected ObservableList<Boat> startingBoats;
|
||||
protected List<SharedModel.Leg> legs;
|
||||
protected List<Leg> legs;
|
||||
protected int boatsFinished = 0;
|
||||
protected long totalTimeElapsed;
|
||||
protected int scaleFactor;
|
||||
@@ -44,11 +45,11 @@ public class Race implements Runnable {
|
||||
* @param legs Number of marks in order that the boats pass in order to complete the race.
|
||||
* @param scaleFactor for race
|
||||
*/
|
||||
public Race(List<Boat> boats, List<SharedModel.Leg> legs, int scaleFactor, MockOutput mockOutput) {
|
||||
public Race(List<Boat> boats, List<Leg> legs, int scaleFactor, MockOutput mockOutput) {
|
||||
|
||||
this.startingBoats = FXCollections.observableArrayList(boats);
|
||||
this.legs = legs;
|
||||
this.legs.add(new SharedModel.Leg("Finish", this.legs.size()));
|
||||
this.legs.add(new Leg("Finish", this.legs.size()));
|
||||
this.scaleFactor = scaleFactor;
|
||||
this.mockOutput = mockOutput;
|
||||
|
||||
@@ -68,14 +69,14 @@ public class Race implements Runnable {
|
||||
this.raceId = raceId;
|
||||
}
|
||||
/**
|
||||
* Calculates the boats next SharedModel.GPS position based on its distance travelled and heading
|
||||
* Calculates the boats next GPS position based on its distance travelled and heading
|
||||
*
|
||||
* @param oldCoordinates SharedModel.GPS coordinates of the boat's starting position
|
||||
* @param oldCoordinates GPS coordinates of the boat's starting position
|
||||
* @param distanceTravelled distance in nautical miles
|
||||
* @param azimuth boat's current direction. Value between -180 and 180
|
||||
* @return The boat's new coordinate
|
||||
*/
|
||||
public static SharedModel.GPSCoordinate calculatePosition(SharedModel.GPSCoordinate oldCoordinates, double distanceTravelled, double azimuth) {
|
||||
public static GPSCoordinate calculatePosition(GPSCoordinate oldCoordinates, double distanceTravelled, double azimuth) {
|
||||
|
||||
//Find new coordinate using current heading and distance
|
||||
|
||||
@@ -84,11 +85,11 @@ public class Race implements Runnable {
|
||||
Point2D startPoint = new Point2D.Double(oldCoordinates.getLongitude(), oldCoordinates.getLatitude());
|
||||
geodeticCalculator.setStartingGeographicPoint(startPoint);
|
||||
//load direction and distance tranvelled into calculator
|
||||
geodeticCalculator.setDirection(azimuth, distanceTravelled * SharedModel.Constants.NMToMetersConversion);
|
||||
geodeticCalculator.setDirection(azimuth, distanceTravelled * Constants.NMToMetersConversion);
|
||||
//get new point
|
||||
Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint();
|
||||
|
||||
return new SharedModel.GPSCoordinate(endPoint.getY(), endPoint.getX());
|
||||
return new GPSCoordinate(endPoint.getY(), endPoint.getX());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,6 +97,8 @@ public class Race implements Runnable {
|
||||
*/
|
||||
public void run() {
|
||||
initialiseBoats();
|
||||
|
||||
System.out.println("Beginning");
|
||||
countdownTimer();
|
||||
}
|
||||
|
||||
@@ -118,6 +121,7 @@ public class Race implements Runnable {
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
timeLeft = startTime - currentTime;
|
||||
System.out.println(timeLeft);
|
||||
if (timeLeft <= 0) {
|
||||
stop();
|
||||
simulateRace();
|
||||
@@ -140,6 +144,7 @@ public class Race implements Runnable {
|
||||
*/
|
||||
private void simulateRace() {
|
||||
|
||||
System.out.println("Running");
|
||||
System.setProperty("javafx.animation.fullspeed", "true");
|
||||
|
||||
for (Boat boat : startingBoats) {
|
||||
@@ -161,11 +166,12 @@ public class Race implements Runnable {
|
||||
|
||||
//For each boat, we update it's position, and generate a BoatLocationMessage.
|
||||
for (Boat boat : startingBoats) {
|
||||
if (boat != null && boat.getTimeFinished() > 0) {
|
||||
if (boat != null && boat.getTimeFinished() < 0) {
|
||||
//Update position.
|
||||
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
||||
checkPosition(boat, totalTimeElapsed);
|
||||
mockOutput.parseBoatLocation(boat);
|
||||
System.out.println("Sending boat status");
|
||||
boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(),
|
||||
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber()));
|
||||
} else {
|
||||
@@ -181,16 +187,16 @@ public class Race implements Runnable {
|
||||
|
||||
|
||||
public void initialiseBoats() {
|
||||
SharedModel.Leg officialStart = legs.get(0);
|
||||
Leg officialStart = legs.get(0);
|
||||
String name = officialStart.getName();
|
||||
SharedModel.Marker endMarker = officialStart.getEndMarker();
|
||||
Marker endMarker = officialStart.getEndMarker();
|
||||
|
||||
ArrayList<SharedModel.Marker> startMarkers = getSpreadStartingPositions();
|
||||
ArrayList<Marker> startMarkers = getSpreadStartingPositions();
|
||||
for (int i = 0; i < startingBoats.size(); i++) {
|
||||
Boat boat = startingBoats.get(i);
|
||||
if (boat != null) {
|
||||
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
|
||||
SharedModel.Leg startLeg = new SharedModel.Leg(name, 0);
|
||||
Leg startLeg = new Leg(name, 0);
|
||||
boat.setCurrentPosition(startMarkers.get(i).getAverageGPSCoordinate());
|
||||
startLeg.setStartMarker(startMarkers.get(i));
|
||||
startLeg.setEndMarker(endMarker);
|
||||
@@ -206,10 +212,10 @@ public class Race implements Runnable {
|
||||
*
|
||||
* @return list of starting positions
|
||||
*/
|
||||
public ArrayList<SharedModel.Marker> getSpreadStartingPositions() {
|
||||
public ArrayList<Marker> getSpreadStartingPositions() {
|
||||
|
||||
int nBoats = startingBoats.size();
|
||||
SharedModel.Marker marker = legs.get(0).getStartMarker();
|
||||
Marker marker = legs.get(0).getStartMarker();
|
||||
|
||||
GeodeticCalculator initialCalc = new GeodeticCalculator();
|
||||
initialCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
||||
@@ -221,12 +227,12 @@ public class Race implements Runnable {
|
||||
|
||||
GeodeticCalculator positionCalc = new GeodeticCalculator();
|
||||
positionCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
||||
ArrayList<SharedModel.Marker> positions = new ArrayList<>();
|
||||
ArrayList<Marker> positions = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < nBoats; i++) {
|
||||
positionCalc.setDirection(azimuth, distanceBetweenBoats);
|
||||
Point2D position = positionCalc.getDestinationGeographicPoint();
|
||||
positions.add(new SharedModel.Marker(new SharedModel.GPSCoordinate(position.getY(), position.getX())));
|
||||
positions.add(new Marker(new GPSCoordinate(position.getY(), position.getX())));
|
||||
|
||||
positionCalc = new GeodeticCalculator();
|
||||
positionCalc.setStartingGeographicPoint(position);
|
||||
@@ -285,14 +291,14 @@ public class Race implements Runnable {
|
||||
} else if (doNotFinish()) {
|
||||
boatsFinished++;
|
||||
boat.setTimeFinished(timeElapsed);
|
||||
boat.setCurrentLeg(new SharedModel.Leg("DNF", -1));
|
||||
boat.setCurrentLeg(new Leg("DNF", -1));
|
||||
boat.setVelocity(0);
|
||||
boat.setScaledVelocity(0);
|
||||
} else {
|
||||
//Calculate how much the boat overshot the marker by
|
||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
||||
//Move boat on to next leg
|
||||
SharedModel.Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
||||
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
||||
|
||||
boat.setCurrentLeg(nextLeg);
|
||||
//Add overshoot distance into the distance travelled for the next leg
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.github.bfsmith.geotimezone.TimeZoneLookup;
|
||||
import com.github.bfsmith.geotimezone.TimeZoneResult;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import SharedModel.GPSCoordinate;
|
||||
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package seng302.Model;
|
||||
|
||||
/**
|
||||
* Created by jjg64 on 19/04/17.
|
||||
*/
|
||||
public class Regatta {
|
||||
int regattaID;
|
||||
String RegattaName;
|
||||
int raceID = 0;
|
||||
String courseName;
|
||||
double centralLatitude;
|
||||
double centralLongitude;
|
||||
double centralAltitude;
|
||||
float utcOffset;
|
||||
float magneticVariation;
|
||||
|
||||
public Regatta(int regattaID, String regattaName, String courseName, double centralLatitude, double centralLongitude, double centralAltitude, float utcOffset, float magneticVariation) {
|
||||
this.regattaID = regattaID;
|
||||
this.RegattaName = regattaName;
|
||||
this.courseName = courseName;
|
||||
this.centralLatitude = centralLatitude;
|
||||
this.centralLongitude = centralLongitude;
|
||||
this.centralAltitude = centralAltitude;
|
||||
this.utcOffset = utcOffset;
|
||||
this.magneticVariation = magneticVariation;
|
||||
}
|
||||
|
||||
public int getRegattaID() {
|
||||
return regattaID;
|
||||
}
|
||||
|
||||
public void setRegattaID(int ID) {
|
||||
this.regattaID = ID;
|
||||
}
|
||||
|
||||
public String getRegattaName() {
|
||||
return RegattaName;
|
||||
}
|
||||
|
||||
public void setRegattaName(String regattaName) {
|
||||
RegattaName = regattaName;
|
||||
}
|
||||
|
||||
public int getRaceID() {
|
||||
return raceID;
|
||||
}
|
||||
|
||||
public void setRaceID(int raceID) {
|
||||
this.raceID = raceID;
|
||||
}
|
||||
|
||||
public String getCourseName() {
|
||||
return courseName;
|
||||
}
|
||||
|
||||
public void setCourseName(String courseName) {
|
||||
this.courseName = courseName;
|
||||
}
|
||||
|
||||
public double getCentralLatitude() {
|
||||
return centralLatitude;
|
||||
}
|
||||
|
||||
public void setCentralLatitude(double centralLatitude) {
|
||||
this.centralLatitude = centralLatitude;
|
||||
}
|
||||
|
||||
public double getCentralLongitude() {
|
||||
return centralLongitude;
|
||||
}
|
||||
|
||||
public void setCentralLongitude(double centralLongitude) {
|
||||
this.centralLongitude = centralLongitude;
|
||||
}
|
||||
|
||||
public double getCentralAltitude() {
|
||||
return centralAltitude;
|
||||
}
|
||||
|
||||
public void setCentralAltitude(double centralAltitude) {
|
||||
this.centralAltitude = centralAltitude;
|
||||
}
|
||||
|
||||
public float getUtcOffset() {
|
||||
return utcOffset;
|
||||
}
|
||||
|
||||
public void setUtcOffset(float utcOffset) {
|
||||
this.utcOffset = utcOffset;
|
||||
}
|
||||
|
||||
public float getMagneticVariation() {
|
||||
return magneticVariation;
|
||||
}
|
||||
|
||||
public void setMagneticVariation(float magneticVariation) {
|
||||
this.magneticVariation = magneticVariation;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package seng302.DataInput;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import SharedModel.Regatta;
|
||||
import seng302.Model.Regatta;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package seng302.Model;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
import org.junit.Test;
|
||||
import SharedModel.*;
|
||||
|
||||
|
||||
import static junit.framework.TestCase.*;
|
||||
|
||||
@@ -15,22 +15,21 @@ public class BoatTest {
|
||||
private GPSCoordinate ORIGIN_COORDS = new GPSCoordinate(0, 0);
|
||||
private Boat TEST_BOAT = new Boat("Test", 1, "tt", 1);
|
||||
|
||||
|
||||
@Test
|
||||
public void calculateDueNorthAzimuthReturns0() {
|
||||
|
||||
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(50, 0));
|
||||
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueSouthAzimuthReturns180() {
|
||||
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(-50, 0));
|
||||
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8);
|
||||
}
|
||||
@@ -39,9 +38,9 @@ public class BoatTest {
|
||||
@Test
|
||||
public void calculateDueEastAzimuthReturns90() {
|
||||
|
||||
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(0, 50));
|
||||
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(0, 50));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8);
|
||||
}
|
||||
@@ -49,9 +48,9 @@ public class BoatTest {
|
||||
|
||||
@Test
|
||||
public void calculateDueWestAzimuthReturnsNegative90() {
|
||||
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(0, -50));
|
||||
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(0, -50));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8);
|
||||
|
||||
@@ -60,9 +59,9 @@ public class BoatTest {
|
||||
@Test
|
||||
public void calculateDueNorthHeadingReturns0() {
|
||||
|
||||
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(50, 0));
|
||||
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateHeading(), 0, 1e-8);
|
||||
}
|
||||
@@ -70,27 +69,27 @@ public class BoatTest {
|
||||
|
||||
@Test
|
||||
public void calculateDueEastHeadingReturns90() {
|
||||
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(0, 50));
|
||||
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(0, 50));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateHeading(), 90, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueSouthHeadingReturns180() {
|
||||
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(-50, 0));
|
||||
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateHeading(), 180, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculateDueWestHeadingReturns270() {
|
||||
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
|
||||
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(0, -50));
|
||||
SharedModel.Leg start = new SharedModel.Leg("Start", startMarker, endMarker, 0);
|
||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||
Marker endMarker = new Marker(new GPSCoordinate(0, -50));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateHeading(), 270, 1e-8);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@ package seng302.Model;
|
||||
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import org.junit.Test;
|
||||
import SharedModel.Constants;
|
||||
import SharedModel.GPSCoordinate;
|
||||
import SharedModel.Leg;
|
||||
import SharedModel.Marker;
|
||||
import seng302.Constants;
|
||||
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@ package seng302.Model;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import SharedModel.GPSCoordinate;
|
||||
import SharedModel.Marker;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package seng302.Model;
|
||||
|
||||
import SharedModel.*;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
@@ -33,8 +33,8 @@ import static org.mockito.Mockito.verify;
|
||||
public class RaceTest {
|
||||
//
|
||||
// private static MockOutput mockOutput;
|
||||
// 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);
|
||||
// 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);
|
||||
// Leg START_LEG = new Leg("Start", new Marker(new GPSCoordinate(0, 0)), new Marker(new GPSCoordinate(1, 1)), 0);
|
||||
// Leg FINISH_LEG = new Leg("Finish", new Marker(new GPSCoordinate(1, 1)), new Marker(new GPSCoordinate(2, 2)), 0);
|
||||
//
|
||||
// @BeforeClass
|
||||
// public static void setUp() {
|
||||
@@ -81,7 +81,7 @@ public class RaceTest {
|
||||
// boats.add(boat1);
|
||||
// boats.add(boat2);
|
||||
//
|
||||
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
// ArrayList<.Leg> legs = new ArrayList<>();
|
||||
// legs.add(START_LEG);
|
||||
// legs.add(FINISH_LEG);
|
||||
//
|
||||
@@ -104,7 +104,7 @@ public class RaceTest {
|
||||
// ArrayList<Boat> boats = new ArrayList<>();
|
||||
// boats.add(finishedBoat);
|
||||
//
|
||||
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
// ArrayList<.Leg> legs = new ArrayList<>();
|
||||
// legs.add(FINISH_LEG);
|
||||
//
|
||||
// Race race = new Race(boats, legs, 5, mockOutput);
|
||||
@@ -129,7 +129,7 @@ public class RaceTest {
|
||||
// ArrayList<Boat> boats = new ArrayList<>();
|
||||
// boats.add(unFinishedBoat);
|
||||
//
|
||||
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
// ArrayList<.Leg> legs = new ArrayList<>();
|
||||
// legs.add(FINISH_LEG);
|
||||
//
|
||||
//
|
||||
@@ -146,7 +146,7 @@ public class RaceTest {
|
||||
//
|
||||
// ArrayList<Boat> boats = new ArrayList<>();
|
||||
//
|
||||
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
// ArrayList<.Leg> legs = new ArrayList<>();
|
||||
//
|
||||
// legs.add(START_LEG);
|
||||
// legs.add(FINISH_LEG);
|
||||
@@ -170,7 +170,7 @@ public class RaceTest {
|
||||
//
|
||||
// ArrayList<Boat> boats = new ArrayList<>();
|
||||
//
|
||||
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
// ArrayList<.Leg> legs = new ArrayList<>();
|
||||
// legs.add(START_LEG);
|
||||
//
|
||||
// Race race = new Race(boats, legs, 1, mockOutput);
|
||||
@@ -204,7 +204,7 @@ public class RaceTest {
|
||||
// boats.add(boat3);
|
||||
// boats.add(boat4);
|
||||
//
|
||||
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
|
||||
// ArrayList<.Leg> legs = new ArrayList<>();
|
||||
// legs.add(START_LEG);
|
||||
//
|
||||
//
|
||||
|
||||
@@ -32,7 +32,6 @@ public class VisualiserInput implements Runnable
|
||||
|
||||
public VisualiserInput(Socket connectionSocket) throws IOException{
|
||||
|
||||
//connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
||||
this.connectionSocket = connectionSocket;
|
||||
|
||||
this.course = new StreamedCourse();
|
||||
@@ -173,7 +172,7 @@ public class VisualiserInput implements Runnable
|
||||
}else{
|
||||
boatLocation.put(msg.getSourceID(), msg);
|
||||
}
|
||||
// System.out.println("Boat Location Message!");
|
||||
System.out.println("Boat Location Message!");
|
||||
break;
|
||||
case MARKROUNDING:
|
||||
// System.out.println("Mark Rounding Message!");
|
||||
@@ -204,7 +203,9 @@ public class VisualiserInput implements Runnable
|
||||
public static void main(String argv[]) throws Exception
|
||||
{
|
||||
//this is the test data that streams form the AC35 website
|
||||
Socket socket = new Socket("livedata.americascup.com",4941);
|
||||
|
||||
Socket socket = new Socket(InetAddress.getLocalHost(), 4942);
|
||||
// Socket socket = new Socket("livedata.americascup.com",4941);
|
||||
VisualiserInput receiver = new VisualiserInput(socket);
|
||||
receiver.run();
|
||||
}
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
package SharedModel;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 3/03/17.
|
||||
*/
|
||||
public class Boat {
|
||||
|
||||
private StringProperty name;
|
||||
private double velocity;
|
||||
private StringProperty velocityProp;
|
||||
private String abbrev;
|
||||
private int sourceID;
|
||||
|
||||
/**
|
||||
* Boat initialiser which keeps all of the information of the boat.
|
||||
*
|
||||
* @param name Name of the Boat.
|
||||
* @param velocity Speed in m/s that the boat travels at.
|
||||
* @param abbrev nam abbreviation
|
||||
* @param sourceID id of boat
|
||||
*/
|
||||
public Boat(String name, double velocity, String abbrev, int sourceID) {
|
||||
this.velocity = velocity;
|
||||
this.velocityProp = new SimpleStringProperty(String.valueOf(Math.round(velocity)));
|
||||
this.abbrev = abbrev;
|
||||
this.name = new SimpleStringProperty(name);
|
||||
this.sourceID = sourceID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Name of the boat
|
||||
*/
|
||||
public StringProperty getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the boat name
|
||||
*
|
||||
* @param name of boat
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name.setValue(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Speed of the boat.
|
||||
*/
|
||||
public double getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the speed of the boat in knots.
|
||||
*
|
||||
* @param velocity speed in knots
|
||||
*/
|
||||
public void setVelocity(double velocity) {
|
||||
this.velocity = velocity;
|
||||
this.velocityProp.setValue(String.valueOf(Math.round(velocity)));
|
||||
}
|
||||
|
||||
public int getSourceID() {
|
||||
return sourceID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print method prints the name of the boat
|
||||
*
|
||||
* @return Name of the boat.
|
||||
*/
|
||||
public String toString() {
|
||||
return getName().getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Velocity String Property of the boat
|
||||
*/
|
||||
public StringProperty getVelocityProp() {
|
||||
return velocityProp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Abbreviation of the boat
|
||||
*/
|
||||
public String getAbbrev() {
|
||||
return abbrev;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,296 +0,0 @@
|
||||
package SharedModel;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.scene.paint.Color;
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
/**
|
||||
* Boat in the Race extends Boat.
|
||||
* Created by esa46 on 15/03/17.
|
||||
*/
|
||||
public class BoatInRace extends Boat {
|
||||
|
||||
private Leg currentLeg;
|
||||
private double scaledVelocity;
|
||||
private double distanceTravelledInLeg;
|
||||
private GPSCoordinate currentPosition;
|
||||
private long timeFinished;
|
||||
private Color colour;
|
||||
private boolean finished = false;
|
||||
private StringProperty currentLegName;
|
||||
private boolean started = false;
|
||||
private StringProperty position;
|
||||
private double heading;
|
||||
private int sourceID;
|
||||
|
||||
|
||||
|
||||
///While generating BoatLocationMessages, each one needs a sequence number relating to each boat.
|
||||
private long sequenceNumber = 0;
|
||||
|
||||
private boolean trackVisible = true;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
*
|
||||
* @param name Name of the boat.
|
||||
* @param velocity Speed that the boat travels.
|
||||
* @param colour Colour the boat will be displayed as on the map
|
||||
* @param abbrev of boat
|
||||
* @param sourceID id of boat
|
||||
*/
|
||||
public BoatInRace(String name, double velocity, Color colour, String abbrev, int sourceID) {
|
||||
super(name, velocity, abbrev, sourceID);
|
||||
setColour(colour);
|
||||
currentLegName = new SimpleStringProperty("");
|
||||
position = new SimpleStringProperty("-");
|
||||
this.sourceID = sourceID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts an azimuth to a bearing
|
||||
*
|
||||
* @param azimuth azimuth value to be converted
|
||||
* @return the bearings in degrees (0 to 360).
|
||||
*/
|
||||
public static double calculateHeading(double azimuth) {
|
||||
if (azimuth >= 0) {
|
||||
return azimuth;
|
||||
} else {
|
||||
return azimuth + 360;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the azimuth of the travel via map coordinates of the raceMarkers
|
||||
*
|
||||
* @return the direction that the boat is heading towards in degrees (-180 to 180).
|
||||
*/
|
||||
public double calculateAzimuth() {
|
||||
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
GPSCoordinate start = currentLeg.getStartMarker().getAverageGPSCoordinate();
|
||||
GPSCoordinate end = currentLeg.getEndMarker().getAverageGPSCoordinate();
|
||||
|
||||
calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude());
|
||||
calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude());
|
||||
|
||||
return calc.getAzimuth();
|
||||
}
|
||||
|
||||
public double getHeading() {
|
||||
return heading;
|
||||
}
|
||||
|
||||
public void setHeading(double heading) {
|
||||
this.heading = heading;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the bearing of the travel via map coordinates of the raceMarkers
|
||||
*
|
||||
* @return the direction that the boat is heading towards in degrees (0 to 360).
|
||||
*/
|
||||
public double calculateHeading() {
|
||||
double azimuth = this.calculateAzimuth();
|
||||
return calculateHeading(azimuth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position of the end of the boat's wake, which is 180 degrees
|
||||
* from the boat's heading, and whose length is proportional to the boat's
|
||||
* speed.
|
||||
*
|
||||
* @return GPSCoordinate of wake endpoint.
|
||||
*/
|
||||
public GPSCoordinate getWake() {
|
||||
double reverseHeading = getHeading() - 180;
|
||||
double distance = Constants.wakeScale * getVelocity();
|
||||
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
calc.setStartingGeographicPoint(
|
||||
new Point2D.Double(getCurrentPosition().getLongitude(), getCurrentPosition().getLatitude())
|
||||
);
|
||||
calc.setDirection(reverseHeading, distance);
|
||||
Point2D endpoint = calc.getDestinationGeographicPoint();
|
||||
return new GPSCoordinate(endpoint.getY(), endpoint.getX());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Scaled velocity of the boat
|
||||
*/
|
||||
public double getScaledVelocity() {
|
||||
return scaledVelocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the boat's scaled velocity
|
||||
*
|
||||
* @param velocity of boat
|
||||
*/
|
||||
public void setScaledVelocity(double velocity) {
|
||||
this.scaledVelocity = velocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the current position of the boat in a GPSCoordinate Class.
|
||||
* @see GPSCoordinate
|
||||
*/
|
||||
public GPSCoordinate getCurrentPosition() {
|
||||
return currentPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current position on the GPS that the boat.
|
||||
*
|
||||
* @param position GPSCoordinate of the position that the boat is currently on.
|
||||
* @see GPSCoordinate
|
||||
*/
|
||||
public void setCurrentPosition(GPSCoordinate position) {
|
||||
this.currentPosition = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the time that the boat finished the race.
|
||||
*/
|
||||
public long getTimeFinished() {
|
||||
return timeFinished;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time that the boat finished the race.
|
||||
*
|
||||
* @param timeFinished Time the boat finished the race.
|
||||
*/
|
||||
public void setTimeFinished(long timeFinished) {
|
||||
this.timeFinished = timeFinished;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the colour of the boat.
|
||||
*/
|
||||
public Color getColour() {
|
||||
return colour;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the colour that boat will be shown as when drawn on the ResizableRaceCanvas.
|
||||
*
|
||||
* @param colour Colour that the boat is to be set to.
|
||||
*/
|
||||
public void setColour(Color colour) {
|
||||
this.colour = colour;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current leg that the boat is on.
|
||||
*
|
||||
* @return returns the leg the boat is on in a Leg class
|
||||
* @see Leg
|
||||
*/
|
||||
public Leg getCurrentLeg() {
|
||||
return currentLeg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the boat's current leg.
|
||||
*
|
||||
* @param currentLeg Leg class that the boat is currently on.
|
||||
* @see Leg
|
||||
*/
|
||||
public void setCurrentLeg(Leg currentLeg) {
|
||||
this.currentLeg = currentLeg;
|
||||
this.currentLegName.setValue(currentLeg.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Name of boat's current leg
|
||||
*/
|
||||
public StringProperty getCurrentLegName() {
|
||||
return currentLegName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the distance travelled by the boat in the leg.
|
||||
*
|
||||
* @return Returns the value in nautical miles (1.852km) that the boat has traversed.
|
||||
*/
|
||||
public double getDistanceTravelledInLeg() {
|
||||
return distanceTravelledInLeg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the distance travelled by the boat in the leg in nautical miles (1.852km)
|
||||
*
|
||||
* @param distanceTravelledInLeg Distance travelled by the boat in nautical miles.
|
||||
*/
|
||||
public void setDistanceTravelledInLeg(double distanceTravelledInLeg) {
|
||||
this.distanceTravelledInLeg = distanceTravelledInLeg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if boat has finished, false if not
|
||||
*/
|
||||
public boolean isFinished() {
|
||||
return this.finished;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether boat is finished or not
|
||||
*
|
||||
* @param bool is finished value
|
||||
*/
|
||||
public void setFinished(boolean bool) {
|
||||
this.finished = bool;
|
||||
}
|
||||
|
||||
public boolean isStarted() {
|
||||
return started;
|
||||
}
|
||||
|
||||
public void setStarted(boolean started) {
|
||||
this.started = started;
|
||||
}
|
||||
|
||||
public String getPosition() {
|
||||
return position.get();
|
||||
}
|
||||
|
||||
public void setPosition(String position) {
|
||||
this.position.set(position);
|
||||
}
|
||||
|
||||
public StringProperty positionProperty() {
|
||||
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.
|
||||
*
|
||||
* @return Current sequence number.
|
||||
*/
|
||||
public long getNextSequenceNumber() {
|
||||
//Make a copy of current value.
|
||||
long oldNumber = this.sequenceNumber;
|
||||
//Increment.
|
||||
this.sequenceNumber += 1;
|
||||
//Return the previous value.
|
||||
return oldNumber;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user