Merge remote-tracking branch 'origin/splitIntoTwoModules' into splitIntoTwoModules
# Conflicts: # mock/src/test/java/seng302/Model/RaceTest.java
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>
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package seng302.Model;
|
||||
|
||||
/**
|
||||
* GPS Coordinate for the world map.
|
||||
* Created by esa46 on 15/03/17.
|
||||
*/
|
||||
public class GPSCoordinate {
|
||||
|
||||
private double latitude;
|
||||
private double longitude;
|
||||
|
||||
/**
|
||||
* Constructor Method
|
||||
*
|
||||
* @param latitude latitude the coordinate is located at.
|
||||
* @param longitude Longitude that the coordinate is located at.
|
||||
*/
|
||||
public GPSCoordinate(double latitude, double longitude) {
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Latitude that the Coordinate is at.
|
||||
*
|
||||
* @return Returns the latitude of the Coordinate.
|
||||
*/
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Longitude that the Coordinate is at.
|
||||
*
|
||||
* @return Returns the longitude of the Coordinate.
|
||||
*/
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
/**
|
||||
* To String method of the Coordinate in the form Latitude: $f, Longitude: $f.
|
||||
*
|
||||
* @return A String representation of the GPSCoordinate Class.
|
||||
*/
|
||||
public String toString() {
|
||||
return String.format("Latitude: %f, Longitude: %f", latitude, longitude);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
GPSCoordinate that = (GPSCoordinate) o;
|
||||
|
||||
if (Math.abs(this.latitude - that.latitude) > 1e-7) return false;
|
||||
return (Math.abs(this.longitude - that.longitude) < 1e-7);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(latitude);
|
||||
result = (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(longitude);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
package seng302.Model;
|
||||
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import seng302.Constants;
|
||||
|
||||
|
||||
/**
|
||||
* Created by cbt24 on 6/03/17.
|
||||
*/
|
||||
public class Leg {
|
||||
private String name; //nautical miles
|
||||
private double distance;
|
||||
private Marker startMarker;
|
||||
private Marker endMarker;
|
||||
private int legNumber;
|
||||
|
||||
/**
|
||||
* Leg Initialiser
|
||||
*
|
||||
* @param name Name of the Leg
|
||||
* @param start marker
|
||||
* @param end marker
|
||||
* @param number Leg's position in race
|
||||
*/
|
||||
public Leg(String name, Marker start, Marker end, int number) {
|
||||
this.name = name;
|
||||
this.startMarker = start;
|
||||
this.endMarker = end;
|
||||
this.legNumber = number;
|
||||
calculateDistance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construction Method
|
||||
*
|
||||
* @param name Name of the Leg
|
||||
* @param number leg number
|
||||
*/
|
||||
public Leg(String name, int number) {
|
||||
this.name = name;
|
||||
this.legNumber = number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the Leg
|
||||
*
|
||||
* @return Returns the name of the Leg
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the distance in nautical miles
|
||||
*
|
||||
* @return Returns the total distance of the leg.
|
||||
*/
|
||||
public double getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the leg number that the leg exists in the Race
|
||||
*
|
||||
* @return Returns the Leg
|
||||
*/
|
||||
public int getLegNumber() {
|
||||
return legNumber;
|
||||
}
|
||||
|
||||
|
||||
public Marker getStartMarker() {
|
||||
return startMarker;
|
||||
}
|
||||
|
||||
public void setStartMarker(Marker startMarker) {
|
||||
this.startMarker = startMarker;
|
||||
}
|
||||
|
||||
public Marker getEndMarker() {
|
||||
return endMarker;
|
||||
}
|
||||
|
||||
public void setEndMarker(Marker endMarker) {
|
||||
this.endMarker = endMarker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the distance that the legs are in nautical miles (1.852 km).
|
||||
*/
|
||||
public void calculateDistance() {
|
||||
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
//Load start and end of leg
|
||||
GPSCoordinate startMarker = this.startMarker.getAverageGPSCoordinate();
|
||||
GPSCoordinate endMarker = this.endMarker.getAverageGPSCoordinate();
|
||||
calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude());
|
||||
calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude());
|
||||
this.distance = calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package seng302.Model;
|
||||
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 29/03/17.
|
||||
*/
|
||||
public class Marker {
|
||||
|
||||
private GPSCoordinate averageGPSCoordinate;
|
||||
private GPSCoordinate mark1;
|
||||
private GPSCoordinate mark2;
|
||||
private String name;
|
||||
private boolean doubleMarker = false;
|
||||
|
||||
public Marker(GPSCoordinate mark1) {
|
||||
|
||||
this.mark1 = mark1;
|
||||
this.mark2 = mark1;
|
||||
this.averageGPSCoordinate = calculateAverage();
|
||||
|
||||
}
|
||||
|
||||
public Marker(GPSCoordinate mark1, GPSCoordinate mark2) {
|
||||
|
||||
this.mark1 = mark1;
|
||||
this.mark2 = mark2;
|
||||
this.averageGPSCoordinate = calculateAverage();
|
||||
|
||||
}
|
||||
|
||||
public Marker(String name, GPSCoordinate mark1, GPSCoordinate mark2) {
|
||||
|
||||
this.name = name;
|
||||
this.mark1 = mark1;
|
||||
this.mark2 = mark2;
|
||||
this.averageGPSCoordinate = calculateAverage();
|
||||
|
||||
}
|
||||
|
||||
public GPSCoordinate getMark1() {
|
||||
return mark1;
|
||||
}
|
||||
|
||||
public GPSCoordinate getMark2() {
|
||||
return mark2;
|
||||
}
|
||||
|
||||
public GPSCoordinate getAverageGPSCoordinate() {
|
||||
return averageGPSCoordinate;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
private GPSCoordinate calculateAverage() {
|
||||
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
calc.setStartingGeographicPoint(mark1.getLongitude(), mark1.getLatitude());
|
||||
calc.setDestinationGeographicPoint(mark2.getLongitude(), mark2.getLatitude());
|
||||
double azimuth = calc.getAzimuth();
|
||||
double distance = calc.getOrthodromicDistance();
|
||||
|
||||
GeodeticCalculator middleCalc = new GeodeticCalculator();
|
||||
middleCalc.setStartingGeographicPoint(mark1.getLongitude(), mark1.getLatitude());
|
||||
middleCalc.setDirection(azimuth, distance / 2);
|
||||
Point2D middlePoint = middleCalc.getDestinationGeographicPoint();
|
||||
return new GPSCoordinate(middlePoint.getY(), middlePoint.getX());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
@@ -46,11 +47,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;
|
||||
|
||||
@@ -70,14 +71,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
|
||||
|
||||
@@ -86,11 +87,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());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,6 +99,8 @@ public class Race implements Runnable {
|
||||
*/
|
||||
public void run() {
|
||||
initialiseBoats();
|
||||
|
||||
System.out.println("Beginning");
|
||||
countdownTimer();
|
||||
}
|
||||
|
||||
@@ -120,6 +123,7 @@ public class Race implements Runnable {
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
timeLeft = startTime - currentTime;
|
||||
System.out.println(timeLeft);
|
||||
if (timeLeft <= 0) {
|
||||
countdownFinish = true;
|
||||
stop();
|
||||
@@ -146,9 +150,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);
|
||||
}
|
||||
|
||||
@@ -166,12 +171,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 {
|
||||
@@ -185,33 +191,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);
|
||||
@@ -227,10 +218,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());
|
||||
@@ -242,12 +233,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);
|
||||
@@ -277,7 +268,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;
|
||||
@@ -295,43 +286,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;
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user