Merge remote-tracking branch 'origin/splitIntoTwoModules' into splitIntoTwoModules

main
hba56 9 years ago
commit 7cb4b2228d

@ -52,12 +52,6 @@
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>seng302</groupId>
<artifactId>sharedModel</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>

@ -29,7 +29,6 @@ public class App extends Application {
@Override
public void start(Stage primaryStage) {
try {
RaceDataSource raceData = new RaceXMLReader("raceXML/bermuda_AC35.xml");
RegattaDataSource regattaData = new RegattaXMLReader("mockXML/regattaTest.xml");
Event raceEvent = new Event(raceData, regattaData);

@ -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,7 +4,8 @@ import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import seng302.Exceptions.InvalidBoatDataException;
import SharedModel.BoatInRace;
import seng302.Model.Boat;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@ -23,10 +24,10 @@ import java.util.List;
public class BoatData {
Document doc;
private List<BoatInRace> boatData;
private List<Boat> boatData;
public BoatData(List<BoatInRace> boatData) {
public BoatData(List<Boat> boatData) {
this.boatData = boatData;
}

@ -4,9 +4,9 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
import seng302.DataInput.RaceDataSource;
import seng302.Exceptions.InvalidRaceDataException;
import SharedModel.BoatInRace;
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;
@ -129,7 +129,7 @@ public class RaceData {
private void appendParticipants() {
Element participantsElement = doc.createElement("Participants");
for (BoatInRace boat : dataSource.getBoats()) {
for (Boat boat : dataSource.getBoats()) {
Element yachtElement = doc.createElement("Yacht");
yachtElement.setAttribute("SourceID", boat.getSourceID() + "");
participantsElement.appendChild(yachtElement);

@ -1,9 +1,10 @@
package seng302.DataInput;
import SharedModel.BoatInRace;
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;
@ -11,7 +12,7 @@ import java.util.List;
* Created by connortaylorbrown on 19/04/17.
*/
public interface RaceDataSource {
List<BoatInRace> getBoats();
List<Boat> getBoats();
List<Leg> getLegs();

@ -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.BoatInRace;
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;
@ -20,7 +21,7 @@ import java.util.List;
public class RaceXMLReader extends XMLReader implements RaceDataSource {
private static double COORDINATEPADDING = 0.0005;
private String raceID;
private List<BoatInRace> boats = new ArrayList<>();
private List<Boat> boats = new ArrayList<>();
private Color[] colors = {Color.BLUEVIOLET, Color.BLACK, Color.RED, Color.ORANGE, Color.DARKOLIVEGREEN, Color.LIMEGREEN};//TODO make this established in xml or come up with a better system.
private List<Leg> legs = new ArrayList<>();
private GPSCoordinate mark, startPt1, startPt2, finishPt1, finishPt2, leewardPt1, leewardPt2, windwardPt1, windwardPt2;
@ -87,7 +88,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
String abbrev = getTextValueOfNode((Element) nBoats.item(i), "abbr");
double velo = Double.parseDouble(getTextValueOfNode((Element) nBoats.item(i), "speed"));
int sourceID = Integer.parseInt(getTextValueOfNode((Element) nBoats.item(i), "sourceID"));
BoatInRace boat = new BoatInRace(name, velo, colors[i], abbrev, sourceID);
Boat boat = new Boat(name, velo, abbrev, sourceID);
boat.setCurrentPosition(startPt1);
if (legs.size() > 0) {
boat.setCurrentLeg(legs.get(0));
@ -301,7 +302,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
return new GPSCoordinate(startLat, startLong);
}
public List<BoatInRace> getBoats() {
public List<Boat> getBoats() {
return boats;
}

@ -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;

@ -0,0 +1,152 @@
package seng302.Model;
import org.geotools.referencing.GeodeticCalculator;
/**
* Created by esa46 on 1/05/17.
*/
public class Boat {
private String name;
private double velocity;
private double scaledVelocity;
private String abbrev;
private int sourceID;
private Leg currentLeg;
private double distanceTravelledInLeg;
private GPSCoordinate currentPosition;
private long timeFinished = -1;
private boolean started = false;
private double heading;
/**
* 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.abbrev = abbrev;
this.name = name;
this.sourceID = sourceID;
}
/**
* 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 calculateHeading() {
double azimuth = this.calculateAzimuth();
if (azimuth >= 0) {
return azimuth;
} else {
return azimuth + 360;
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getVelocity() {
return velocity;
}
public void setVelocity(double velocity) {
this.velocity = velocity;
}
public double getScaledVelocity() {
return scaledVelocity;
}
public void setScaledVelocity(double scaledVelocity) {
this.scaledVelocity = scaledVelocity;
}
public String getAbbrev() {
return abbrev;
}
public void setAbbrev(String abbrev) {
this.abbrev = abbrev;
}
public int getSourceID() {
return sourceID;
}
public void setSourceID(int sourceID) {
this.sourceID = sourceID;
}
public Leg getCurrentLeg() {
return currentLeg;
}
public void setCurrentLeg(Leg currentLeg) {
this.currentLeg = currentLeg;
}
public double getDistanceTravelledInLeg() {
return distanceTravelledInLeg;
}
public void setDistanceTravelledInLeg(double distanceTravelledInLeg) {
this.distanceTravelledInLeg = distanceTravelledInLeg;
}
public GPSCoordinate getCurrentPosition() {
return currentPosition;
}
public void setCurrentPosition(GPSCoordinate currentPosition) {
this.currentPosition = currentPosition;
}
public long getTimeFinished() {
return timeFinished;
}
public void setTimeFinished(long timeFinished) {
this.timeFinished = timeFinished;
}
public boolean isStarted() {
return started;
}
public void setStarted(boolean started) {
this.started = started;
}
public double getHeading() {
return heading;
}
public void setHeading(double heading) {
this.heading = heading;
}
}

@ -41,8 +41,11 @@ public class Event {
public void start() {
System.out.println("Sending Regatta");
sendRegattaData();
System.out.println("Sending Race");
sendRaceData();
System.out.println("Sending Boat");
sendBoatData();
Race newRace = new Race(raceDataSource, 15, mockOutput);

@ -1,4 +1,4 @@
package SharedModel;
package seng302.Model;
/**
* GPS Coordinate for the world map.

@ -1,6 +1,7 @@
package SharedModel;
package seng302.Model;
import org.geotools.referencing.GeodeticCalculator;
import seng302.Constants;
/**

@ -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;
@ -24,9 +25,9 @@ import java.util.Random;
* Created by fwy13 on 3/03/17.
*/
public class Race implements Runnable {
//protected SharedModel.BoatInRace[] startingBoats;
protected ObservableList<SharedModel.BoatInRace> startingBoats;
protected List<SharedModel.Leg> legs;
//protected Boat[] startingBoats;
protected ObservableList<Boat> startingBoats;
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<SharedModel.BoatInRace> 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,9 +144,10 @@ public class Race implements Runnable {
*/
private void simulateRace() {
System.out.println("Running");
System.setProperty("javafx.animation.fullspeed", "true");
for (SharedModel.BoatInRace boat : startingBoats) {
for (Boat boat : startingBoats) {
boat.setStarted(true);
}
@ -160,12 +165,13 @@ public class Race implements Runnable {
ArrayList<BoatStatusMessage> boatStatusMessages = new ArrayList<BoatStatusMessage>();
//For each boat, we update it's position, and generate a BoatLocationMessage.
for (SharedModel.BoatInRace boat : startingBoats) {
if (boat != null && !boat.isFinished()) {
for (Boat boat : startingBoats) {
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 {
@ -179,33 +185,18 @@ public class Race implements Runnable {
}.start();
}
/**
* Update position of boats in race, no position if on starting leg or DNF.
*/
protected void updatePositions() {
FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
for (SharedModel.BoatInRace boat : startingBoats) {
if (boat != null) {
boat.setPosition(Integer.toString(startingBoats.indexOf(boat) + 1));
//System.out.println(boat.toString() + " " + boat.getPosition());//TEMP debug print
if (boat.getCurrentLeg().getName().equals("DNF") || boat.getCurrentLeg().getLegNumber() == 0)
boat.setPosition("-");
}
}
//System.out.println("=====");//TEMP debug print
}
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++) {
SharedModel.BoatInRace boat = startingBoats.get(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);
@ -221,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());
@ -236,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);
@ -271,7 +262,7 @@ public class Race implements Runnable {
* @param boat to be updated
* @param millisecondsElapsed since last update
*/
protected void updatePosition(SharedModel.BoatInRace boat, int millisecondsElapsed) {
protected void updatePosition(Boat boat, int millisecondsElapsed) {
//distanceTravelled = velocity (nm p hr) * time taken to update loop
double distanceTravelled = (boat.getScaledVelocity() * millisecondsElapsed) / 3600000;
@ -289,43 +280,41 @@ public class Race implements Runnable {
}
}
protected void checkPosition(SharedModel.BoatInRace boat, long timeElapsed) {
protected void checkPosition(Boat boat, long timeElapsed) {
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()) {
//boat has passed onto new leg
if (boat.getCurrentLeg().getName().equals("Finish")) {
//boat has finished
boatsFinished++;
boat.setFinished(true);
boat.setTimeFinished(timeElapsed);
boat.setTimeFinished(timeElapsed);
} else if (doNotFinish()) {
boatsFinished++;
boat.setFinished(true);
boat.setCurrentLeg(new SharedModel.Leg("DNF", -1));
boat.setTimeFinished(timeElapsed);
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
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
}
//Update the boat display table in the GUI to reflect the leg change
updatePositions();
}
}
/**
* Returns the boats that have started the race.
*
* @return ObservableList of SharedModel.BoatInRace class that participated in the race.
* @return ObservableList of Boat class that participated in the race.
* @see ObservableList
* @see SharedModel.BoatInRace
* @see Boat
*/
public ObservableList<SharedModel.BoatInRace> getStartingBoats() {
public ObservableList<Boat> getStartingBoats() {
return startingBoats;
}
}

@ -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,155 +0,0 @@
package seng302.Model;
import javafx.scene.paint.Color;
import org.junit.Test;
import SharedModel.*;
import static junit.framework.TestCase.*;
/**
* Created by esa46 on 22/03/17.
*/
public class BoatInRaceTest {
private GPSCoordinate ORIGIN_COORDS = new GPSCoordinate(0, 0);
private SharedModel.BoatInRace TEST_BOAT = new SharedModel.BoatInRace("Test", 1, Color.ALICEBLUE, "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);
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);
TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8);
}
@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);
TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8);
}
@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);
TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8);
}
@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);
TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateHeading(), 0, 1e-8);
}
@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);
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);
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);
TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateHeading(), 270, 1e-8);
}
@Test
public void createNewBoatCreatesInstanceOfSuperClass() {
SharedModel.BoatInRace testBoat = new SharedModel.BoatInRace("Boat", 20, Color.ALICEBLUE, "tt", 1);
testBoat.setName("Name can change");
assertTrue(testBoat instanceof SharedModel.Boat);
assertTrue(testBoat.getCurrentLeg() == null);
assertTrue(testBoat.getCurrentPosition() == null);
assertTrue(testBoat.toString().contains("Name can change"));
assertEquals(testBoat.getVelocity(), 20.0);
assertTrue(testBoat.getVelocityProp().toString().contains("20"));
assertTrue(testBoat.getAbbrev().equals("tt"));
assertTrue(testBoat.getColour().equals(Color.ALICEBLUE));
assertEquals(testBoat.getSourceID(), 1);
assertFalse(testBoat.isFinished());
}
@Test
public void getWakeAtProperHeading() throws Exception {
SharedModel.BoatInRace boat = new SharedModel.BoatInRace("Test", 1, Color.ALICEBLUE, "tt", 1);
// Construct leg of 0 degrees
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(50, 0));
SharedModel.Leg leg0deg = new SharedModel.Leg("Start", startMarker, endMarker, 0);
boat.setCurrentLeg(leg0deg);
boat.setCurrentPosition(new GPSCoordinate(0, 0));
assertEquals(0, boat.calculateHeading(), 1e-8);
// Construct leg from wake - heading should be 180 degrees
SharedModel.Leg leg180deg = new SharedModel.Leg("Start", startMarker, new SharedModel.Marker(boat.getWake()), 0);
boat.setCurrentLeg(leg180deg);
assertEquals(180, boat.calculateHeading(), 1e-8);
}
@Test
public void getWakeProportionalToVelocity() throws Exception {
SharedModel.BoatInRace boat = new SharedModel.BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 1);
// Construct leg of 0 degrees at 0 N
SharedModel.Marker startMarker = new SharedModel.Marker(ORIGIN_COORDS);
SharedModel.Marker endMarker = new SharedModel.Marker(new GPSCoordinate(50, 0));
SharedModel.Leg leg0deg = new SharedModel.Leg("Start", startMarker, endMarker, 0);
boat.setCurrentLeg(leg0deg);
boat.setCurrentPosition(new GPSCoordinate(0, 0));
// Get latitude of endpoint of wake at 10 kn (longitude is 0)
double endpointAt10Kn = boat.getWake().getLatitude();
// Latitude of endpoint at 20 kn should be twice endpoint at 10 kn
boat.setVelocity(20);
assertEquals(2 * endpointAt10Kn, boat.getWake().getLatitude(), 1e-8);
}
}

@ -0,0 +1,98 @@
package seng302.Model;
import org.junit.Test;
import static junit.framework.TestCase.*;
/**
* Created by esa46 on 22/03/17.
*/
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() {
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() {
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);
}
@Test
public void calculateDueEastAzimuthReturns90() {
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);
}
@Test
public void calculateDueWestAzimuthReturnsNegative90() {
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);
}
@Test
public void calculateDueNorthHeadingReturns0() {
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);
}
@Test
public void calculateDueEastHeadingReturns90() {
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() {
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() {
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() {
@ -75,13 +75,13 @@ public class RaceTest {
//
// @Test
// public void timerCanBeDisabled() {
// SharedModel.BoatInRace boat1 = new SharedModel.BoatInRace("Test 1", 10000, Color.ALICEBLUE, "t1", 1);
// SharedModel.BoatInRace boat2 = new SharedModel.BoatInRace("Test 2", 10000, Color.BURLYWOOD, "t2", 2);
// List<SharedModel.BoatInRace> boats = new ArrayList<>();
// Boat boat1 = new Boat("Test 1", 10000, Color.ALICEBLUE, "t1", 1);
// Boat boat2 = new Boat("Test 2", 10000, Color.BURLYWOOD, "t2", 2);
// List<Boat> boats = new ArrayList<>();
// 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);
//
@ -96,15 +96,15 @@ public class RaceTest {
// @Test
// public void checkPositionUpdatesNumberFinishedBoats() {
//
// SharedModel.BoatInRace finishedBoat = new SharedModel.BoatInRace("Test", 1000, Color.ALICEBLUE, "tt", 1);
// Boat finishedBoat = new Boat("Test", 1000, Color.ALICEBLUE, "tt", 1);
// finishedBoat.setDistanceTravelledInLeg(500);
//
// finishedBoat.setCurrentLeg(FINISH_LEG);
//
// ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
// 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);
@ -121,15 +121,15 @@ public class RaceTest {
// @Test
// public void checkPositionDoesntUpdateNumberFinishedBoats() {
//
// SharedModel.BoatInRace unFinishedBoat = new SharedModel.BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 1);
// Boat unFinishedBoat = new Boat("Test", 10, Color.ALICEBLUE, "tt", 1);
// unFinishedBoat.setDistanceTravelledInLeg(0);
//
// unFinishedBoat.setCurrentLeg(FINISH_LEG);
//
// ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
// ArrayList<Boat> boats = new ArrayList<>();
// boats.add(unFinishedBoat);
//
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
// ArrayList<.Leg> legs = new ArrayList<>();
// legs.add(FINISH_LEG);
//
//
@ -144,9 +144,9 @@ public class RaceTest {
// @Test
// public void distanceTravelledBeforeUpdatingLegIsRetained() {
//
// ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
// ArrayList<Boat> boats = new ArrayList<>();
//
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
// ArrayList<.Leg> legs = new ArrayList<>();
//
// legs.add(START_LEG);
// legs.add(FINISH_LEG);
@ -154,7 +154,7 @@ public class RaceTest {
// Race race = new Race(boats, legs, 1, mockOutput);
// race.setDnfChance(0);
//
// SharedModel.BoatInRace unFinishedBoat = new SharedModel.BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 4);
// Boat unFinishedBoat = new Boat("Test", 10, Color.ALICEBLUE, "tt", 4);
// unFinishedBoat.setDistanceTravelledInLeg(100);
// unFinishedBoat.setCurrentLeg(START_LEG);
//
@ -168,9 +168,9 @@ public class RaceTest {
// @Test
// public void timerDelaysByHalfSecond() throws InterruptedException {
//
// ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
// 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);
@ -194,17 +194,17 @@ public class RaceTest {
// float vel2 = (float) 1.999;
// float vel3 = (float) 32.5;
// float vel4 = 500;
// SharedModel.BoatInRace boat1 = new SharedModel.BoatInRace("test", vel1, Color.ALICEBLUE, "tt",1);
// SharedModel.BoatInRace boat2 = new SharedModel.BoatInRace("test", vel2, Color.ALICEBLUE, "tt", 2);
// SharedModel.BoatInRace boat3 = new SharedModel.BoatInRace("test", vel3, Color.ALICEBLUE, "tt", 3);
// SharedModel.BoatInRace boat4 = new SharedModel.BoatInRace("test", vel4, Color.ALICEBLUE, "tt", 4);
// ArrayList<SharedModel.BoatInRace> boats = new ArrayList<>();
// Boat boat1 = new Boat("test", vel1, Color.ALICEBLUE, "tt",1);
// Boat boat2 = new Boat("test", vel2, Color.ALICEBLUE, "tt", 2);
// Boat boat3 = new Boat("test", vel3, Color.ALICEBLUE, "tt", 3);
// Boat boat4 = new Boat("test", vel4, Color.ALICEBLUE, "tt", 4);
// ArrayList<Boat> boats = new ArrayList<>();
// boats.add(boat1);
// boats.add(boat2);
// boats.add(boat3);
// boats.add(boat4);
//
// ArrayList<SharedModel.Leg> legs = new ArrayList<>();
// ArrayList<.Leg> legs = new ArrayList<>();
// legs.add(START_LEG);
//
//

@ -5,7 +5,7 @@ package seng302.Model;/**
import org.junit.Ignore;
import org.junit.Test;
import seng302.DataInput.RaceXMLReader;
import SharedModel.BoatInRace;
import java.util.List;
@ -29,29 +29,29 @@ public class RaceXMLTest {
try {
RaceXMLReader raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml", false);
raceXMLReader.readBoats();
List<BoatInRace> boats = raceXMLReader.getBoats();
List<Boat> boats = raceXMLReader.getBoats();
assertTrue(boats.size() == 6);
//test boat 1
assertEquals(boats.get(0).getName().getValue(), "ORACLE TEAM USA");
assertEquals(boats.get(0).getName(), "ORACLE TEAM USA");
assertTrue(boats.get(0).getVelocity() == 20);
//test boat 2
assertEquals(boats.get(1).getName().getValue(), "Land Rover BAR");
assertEquals(boats.get(1).getName(), "Land Rover BAR");
assertTrue(boats.get(1).getVelocity() == 30);
assertEquals(boats.get(1).getAbbrev(), "GBR");
//test boat 3
assertEquals(boats.get(2).getName().getValue(), "SoftBank Team Japan");
assertEquals(boats.get(2).getName(), "SoftBank Team Japan");
assertTrue(boats.get(2).getVelocity() == 25);
assertEquals(boats.get(2).getAbbrev(), "JPN");
//test boat 4
assertEquals(boats.get(3).getName().getValue(), "Groupama Team France");
assertEquals(boats.get(3).getName(), "Groupama Team France");
assertTrue(boats.get(3).getVelocity() == 20);
assertEquals(boats.get(3).getAbbrev(), "FRA");
//test boat 5
assertEquals(boats.get(4).getName().getValue(), "Artemis Racing");
assertEquals(boats.get(4).getName(), "Artemis Racing");
assertTrue(boats.get(4).getVelocity() == 29);
assertEquals(boats.get(4).getAbbrev(), "SWE");
//test boat 6
assertEquals(boats.get(5).getName().getValue(), "Emirates Team New Zealand");
assertEquals(boats.get(5).getName(), "Emirates Team New Zealand");
assertTrue(boats.get(5).getVelocity() == 62);
assertEquals(boats.get(5).getAbbrev(), "NZL");
} catch (Exception e) {

@ -1,7 +1,7 @@
package seng302.Networking;
import SharedModel.BoatInRace;
import com.sun.jmx.remote.internal.ArrayQueue;
import seng302.Model.Boat;
import seng302.Networking.MessageEncoders.RaceVisionByteEncoder;
import seng302.Networking.MessageEncoders.XMLMessageEncoder;
import seng302.Networking.Utils.BoatLocationMessage;
@ -10,7 +10,7 @@ import seng302.Networking.Utils.RaceStatus;
import java.io.*;
import java.net.*;
import java.util.ArrayList;
import java.util.concurrent.ArrayBlockingQueue;
/**
@ -37,7 +37,7 @@ public class MockOutput implements Runnable
public MockOutput() throws IOException {
lastHeartbeatTime = System.currentTimeMillis();
serverSocket = new ServerSocket(5003);
serverSocket = new ServerSocket(4942);
}
/**
* calculates the time since last heartbeat
@ -78,7 +78,7 @@ public class MockOutput implements Runnable
/**
* Used to give the mocOutput information about boat location to be made into a message and sent
*/
public synchronized void parseBoatLocation(BoatInRace boat){
public synchronized void parseBoatLocation(Boat boat){
BoatLocationMessage boatLocationMessage = new BoatLocationMessage(boat, boatLocationSequenceNumber);
//iterates the sequence number
boatLocationSequenceNumber++;

@ -4,9 +4,8 @@ package seng302.Networking.Utils;
* Created by f123 on 21-Apr-17.
*/
import SharedModel.BoatInRace;
import SharedModel.Constants;
import SharedModel.GPSCoordinate;
import seng302.Model.Boat;
import static seng302.Networking.Utils.AC35UnitConverter.convertGPSToInt;
@ -151,7 +150,7 @@ public class BoatLocationMessage extends AC35Data
this.rudderAngle = rudderAngle;
}
public BoatLocationMessage(BoatInRace boat, long sequenceNumber) {
public BoatLocationMessage(Boat boat, long sequenceNumber) {
super(MessageType.BOATLOCATION);
this.messageVersionNumber = (byte) 1;

@ -1,24 +1,17 @@
package seng302.Networking;
import org.xml.sax.SAXException;
import seng302.Mock.*;
import seng302.Networking.BinaryMessageDecoder;
import seng302.Networking.MessageDecoders.*;
import seng302.Networking.Utils.*;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import java.net.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.text.ParseException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static seng302.Networking.Utils.ByteConverter.bytesToInt;
import static seng302.Networking.Utils.ByteConverter.bytesToShort;
import static seng302.Networking.Utils.MessageType.*;
/**
* TCP server to act as the mock AC35 streaming interface
@ -39,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();
@ -103,6 +95,7 @@ public class VisualiserInput implements Runnable
public void run(){
try{
System.out.println("running");
//receiver loop that gets the input
boolean receiverLoop = true;
while(receiverLoop) {
@ -136,7 +129,7 @@ public class VisualiserInput implements Runnable
//no decoder for this.
break;
case XMLMESSAGE:
// System.out.println("XML Message!");
System.out.println("XML Message!");
XMLMessage xml = (XMLMessage) data;
try {
if (xml.getXmlMsgSubType() == xml.XMLTypeRegatta){
@ -179,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!");
@ -210,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;
}
}

@ -28,6 +28,8 @@ public class Boat {
protected StringProperty position;
protected boolean started = false;
private double wakeScale = 1 / 50;
private int sourceID;
protected Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
protected long nextValidTime = 0;
@ -226,4 +228,8 @@ public class Boat {
public StringProperty getCurrentLegName() {
return currentLegName;
}
public int getSourceID() {
return this.sourceID;
}
}

Loading…
Cancel
Save