commit
7cb4b2228d
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package SharedModel;
|
package seng302.Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GPS Coordinate for the world map.
|
* GPS Coordinate for the world map.
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package SharedModel;
|
package seng302.Model;
|
||||||
|
|
||||||
import org.geotools.referencing.GeodeticCalculator;
|
import org.geotools.referencing.GeodeticCalculator;
|
||||||
|
import seng302.Constants;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1,7 +1,6 @@
|
|||||||
package SharedModel;
|
package seng302.Model;
|
||||||
|
|
||||||
import org.geotools.referencing.GeodeticCalculator;
|
import org.geotools.referencing.GeodeticCalculator;
|
||||||
|
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in new issue