Merge branch 'story9' of https://eng-git.canterbury.ac.nz/seng302-2017/team-7 into story9
This commit is contained in:
@@ -20,7 +20,6 @@ public class BoatInRace extends Boat {
|
|||||||
private long timeFinished;
|
private long timeFinished;
|
||||||
private Color colour;
|
private Color colour;
|
||||||
private boolean finished = false;
|
private boolean finished = false;
|
||||||
private StringProperty currentLegName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor method.
|
* Constructor method.
|
||||||
@@ -31,7 +30,6 @@ public class BoatInRace extends Boat {
|
|||||||
public BoatInRace(String name, double velocity, Color colour, String abbrev) {
|
public BoatInRace(String name, double velocity, Color colour, String abbrev) {
|
||||||
super(name, velocity, abbrev);
|
super(name, velocity, abbrev);
|
||||||
setColour(colour);
|
setColour(colour);
|
||||||
currentLegName = new SimpleStringProperty("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,10 +90,14 @@ public class BoatInRace extends Boat {
|
|||||||
*/
|
*/
|
||||||
public void setCurrentLeg(Leg currentLeg) {
|
public void setCurrentLeg(Leg currentLeg) {
|
||||||
this.currentLeg = currentLeg;
|
this.currentLeg = currentLeg;
|
||||||
this.currentLegName.setValue(currentLeg.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringProperty getCurrentLegName(){
|
public StringProperty getCurrentLegName(){
|
||||||
|
|
||||||
|
StringProperty currentLegName = new SimpleStringProperty("");
|
||||||
|
if (currentLeg != null) {
|
||||||
|
currentLegName.setValue(currentLeg.getName());
|
||||||
|
}
|
||||||
return currentLegName;
|
return currentLegName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,19 +134,39 @@ public class BoatInRace extends Boat {
|
|||||||
this.finished = bool;
|
this.finished = bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the bearing of the travel via map coordinates of the raceMarkers
|
* Calculates the azimuth of the travel via map coordinates of the raceMarkers
|
||||||
* @return the heading that the boat is heading towards in degrees.
|
* @return the direction that the boat is heading towards in degrees (-180 to 180).
|
||||||
*/
|
*/
|
||||||
public double calculateAzimuth(){
|
public double calculateAzimuth(){
|
||||||
//to be changed to coordinates when used to match reality.
|
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLongitude(), currentLeg.getStartGraphCoordinate().getLatitude());
|
calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLongitude(), currentLeg.getStartGraphCoordinate().getLatitude());
|
||||||
calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLongitude(), currentLeg.getEndGraphCoordinate().getLatitude());
|
calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLongitude(), currentLeg.getEndGraphCoordinate().getLatitude());
|
||||||
|
|
||||||
return calc.getAzimuth();
|
return calc.getAzimuth();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an azimuth to a bearing
|
||||||
|
* @param azimuth azimuth valuye 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 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.util.ArrayList;
|
|||||||
* Created by cbt24 on 6/03/17.
|
* Created by cbt24 on 6/03/17.
|
||||||
*/
|
*/
|
||||||
public class ConstantVelocityRace extends Race {
|
public class ConstantVelocityRace extends Race {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialiser for a Race with constant velocity.
|
* Initialiser for a Race with constant velocity.
|
||||||
* @param startingBoats array of boats
|
* @param startingBoats array of boats
|
||||||
|
|||||||
@@ -55,15 +55,6 @@ public class Leg {
|
|||||||
return distance;
|
return distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return Returns the name of the Leg
|
|
||||||
*/
|
|
||||||
public String toString() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the coordinates in GPSCoordinate class of the boats starting coordinate.
|
* Returns the coordinates in GPSCoordinate class of the boats starting coordinate.
|
||||||
* @return Returns the coordinate of the start of the leg.
|
* @return Returns the coordinate of the start of the leg.
|
||||||
@@ -101,5 +92,6 @@ public class Leg {
|
|||||||
calc.setStartingGeographicPoint(startGPSCoordinate.getLongitude(), startGPSCoordinate.getLatitude());
|
calc.setStartingGeographicPoint(startGPSCoordinate.getLongitude(), startGPSCoordinate.getLatitude());
|
||||||
calc.setDestinationGeographicPoint(endGPSCoordinate.getLongitude(), endGPSCoordinate.getLatitude());
|
calc.setDestinationGeographicPoint(endGPSCoordinate.getLongitude(), endGPSCoordinate.getLatitude());
|
||||||
return calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
|
return calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
import com.sun.xml.internal.bind.v2.runtime.reflect.opt.Const;
|
|
||||||
import javafx.scene.canvas.Canvas;
|
import javafx.scene.canvas.Canvas;
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
@@ -11,9 +11,6 @@ import seng302.GPSCoordinate;
|
|||||||
import seng302.GraphCoordinate;
|
import seng302.GraphCoordinate;
|
||||||
import seng302.RaceMap;
|
import seng302.RaceMap;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This creates a JavaFX Canvas that is fills it's parent.
|
* This creates a JavaFX Canvas that is fills it's parent.
|
||||||
* Cannot be downsized.
|
* Cannot be downsized.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
|
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
import org.geotools.referencing.GeodeticCalculator;
|
import org.geotools.referencing.GeodeticCalculator;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.opengis.geometry.coordinate.Geodesic;
|
import org.opengis.geometry.coordinate.Geodesic;
|
||||||
@@ -8,6 +9,7 @@ import seng302.Constants;
|
|||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
|
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
@@ -16,10 +18,50 @@ import static org.junit.Assert.assertEquals;
|
|||||||
*/
|
*/
|
||||||
public class ConstantVelocityRaceTest {
|
public class ConstantVelocityRaceTest {
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updatePositionChangesDistanceTravelled() {
|
||||||
|
|
||||||
|
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||||
|
Leg start = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0);
|
||||||
|
boat.setCurrentLeg(start);
|
||||||
|
boat.setDistanceTravelledInLeg(0);
|
||||||
|
int timeElapsed = 3600000; //1 hr
|
||||||
|
|
||||||
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>());
|
||||||
|
|
||||||
|
race.updatePosition(boat, timeElapsed);
|
||||||
|
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() * timeElapsed / 3600000, 1e-8);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updatePositionHandlesNoChangeToDistanceTravelled() {
|
||||||
|
|
||||||
|
BoatInRace boat = new BoatInRace("Test", 0, Color.ALICEBLUE, "tt");
|
||||||
|
Leg start = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0);
|
||||||
|
boat.setCurrentLeg(start);
|
||||||
|
boat.setDistanceTravelledInLeg(0);
|
||||||
|
int timeElapsed = 3600000; //1 hr
|
||||||
|
|
||||||
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>());
|
||||||
|
|
||||||
|
race.updatePosition(boat, timeElapsed);
|
||||||
|
assertEquals(boat.getDistanceTravelledInLeg(), 0, 1e-8);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void changesToDistanceTravelledAreAdditive() {
|
||||||
|
BoatInRace boat = new BoatInRace("Test", 5, Color.ALICEBLUE, "tt");
|
||||||
|
Leg start = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0);
|
||||||
|
boat.setCurrentLeg(start);
|
||||||
|
boat.setDistanceTravelledInLeg(50);
|
||||||
|
int timeElapsed = 3600000; //1 hr
|
||||||
|
|
||||||
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>());
|
||||||
|
|
||||||
|
race.updatePosition(boat, timeElapsed);
|
||||||
|
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() * timeElapsed / 3600000 + 50, 1e-8);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void travelling10nmNorthGivesCorrectNewCoordinates() {
|
public void travelling10nmNorthGivesCorrectNewCoordinates() {
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package seng302.Model;
|
||||||
|
|
||||||
|
import org.geotools.referencing.GeodeticCalculator;
|
||||||
|
import org.junit.Test;
|
||||||
|
import seng302.Constants;
|
||||||
|
import seng302.GPSCoordinate;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by esa46 on 22/03/17.
|
||||||
|
*/
|
||||||
|
public class LegTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void calculateDistanceHandles5nmNorth() {
|
||||||
|
GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
|
calc.setStartingGeographicPoint(0, 0);
|
||||||
|
calc.setDirection(0, 5 * Constants.NMToMetersConversion);
|
||||||
|
|
||||||
|
GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||||
|
GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
|
||||||
|
Leg test= new Leg("Test", startPoint, endPoint, 0);
|
||||||
|
assertEquals(test.getDistance(), 5, 1e-8);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void calculateDistanceHandles12nmEast() {
|
||||||
|
GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
|
calc.setStartingGeographicPoint(0, 0);
|
||||||
|
calc.setDirection(90, 12 * Constants.NMToMetersConversion);
|
||||||
|
|
||||||
|
GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||||
|
GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
|
||||||
|
Leg test= new Leg("Test", startPoint, endPoint, 0);
|
||||||
|
assertEquals(test.getDistance(), 12, 1e-8);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void calculateDistanceHandlesHalfnmSouth() {
|
||||||
|
GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
|
calc.setStartingGeographicPoint(0, 0);
|
||||||
|
calc.setDirection(180, 0.5 * Constants.NMToMetersConversion);
|
||||||
|
|
||||||
|
GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||||
|
GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
|
||||||
|
Leg test= new Leg("Test", startPoint, endPoint, 0);
|
||||||
|
assertEquals(test.getDistance(), 0.5, 1e-8);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void calculateDistanceHandlesPoint1nmWest() {
|
||||||
|
GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
|
calc.setStartingGeographicPoint(0, 0);
|
||||||
|
calc.setDirection(-90, 0.1 * Constants.NMToMetersConversion);
|
||||||
|
|
||||||
|
GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||||
|
GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX());
|
||||||
|
Leg test= new Leg("Test", startPoint, endPoint, 0);
|
||||||
|
assertEquals(test.getDistance(), 0.1, 1e-8);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void calculateDistanceHandlesZeroDifference() {
|
||||||
|
GPSCoordinate startPoint = new GPSCoordinate(0, 0);
|
||||||
|
GPSCoordinate endPoint = new GPSCoordinate(0, 0);
|
||||||
|
Leg test= new Leg("Test", startPoint, endPoint, 0);
|
||||||
|
assertEquals(test.getDistance(), 0, 1e-8);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,31 +22,6 @@ import static org.junit.Assert.assertTrue;
|
|||||||
public class RaceTest {
|
public class RaceTest {
|
||||||
|
|
||||||
|
|
||||||
// @Ignore
|
|
||||||
// @Test
|
|
||||||
// public void singleBoatRaceRunsAndFinishes(){
|
|
||||||
//
|
|
||||||
// BoatInRace boat = new BoatInRace("NZ", 240);
|
|
||||||
// ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
||||||
// boats.add(boat);
|
|
||||||
// ArrayList<Leg> legs = new ArrayList<>();
|
|
||||||
// legs.add(new Leg("Start", new GPSCoordinate(0,0), new GPSCoordinate(1,1), 0));
|
|
||||||
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs);
|
|
||||||
// race.run();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// public void fasterBoatFinishesFirst() {
|
|
||||||
// BoatInRace fasterBoat = new BoatInRace("NZ", 2800);
|
|
||||||
// BoatInRace slowerBoat = new BoatInRace("AU", 1800);
|
|
||||||
// BoatInRace[] boats = new BoatInRace[] {slowerBoat, fasterBoat};
|
|
||||||
// Leg leg1 = new Leg("first leg", 1, new GPSCoordinate(0, 0), new GPSCoordinate(3, 4), 0);
|
|
||||||
// ArrayList<Leg> legs = new ArrayList<>();
|
|
||||||
// legs.add(leg1);
|
|
||||||
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs);
|
|
||||||
// race.run();
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void finishOrderDeterminedByVelocity() {
|
public void finishOrderDeterminedByVelocity() {
|
||||||
BoatInRace[] boats = {
|
BoatInRace[] boats = {
|
||||||
|
|||||||
Reference in New Issue
Block a user