# Conflicts: # visualiser/src/main/java/seng302/Controllers/RaceController.java # visualiser/src/main/java/seng302/Controllers/StartController.java # visualiser/src/main/java/seng302/Mock/BoatXMLReader.java # visualiser/src/main/java/seng302/Mock/StreamedBoat.java # visualiser/src/main/java/seng302/Mock/StreamedCourse.java # visualiser/src/main/java/seng302/Mock/StreamedRace.java # visualiser/src/main/java/seng302/Model/BoatInRace.java # visualiser/src/main/java/seng302/Model/ConstantVelocityRace.java # visualiser/src/main/java/seng302/Model/Race.java # visualiser/src/main/java/seng302/RaceXMLReader.java # visualiser/src/test/java/seng302/Model/ConstantVelocityRaceTest.javamain
commit
d977d3f146
@ -1,44 +1,48 @@
|
|||||||
package seng302.Mock;
|
package seng302.Mock;
|
||||||
|
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
import org.geotools.referencing.GeodeticCalculator;
|
||||||
|
import seng302.GPSCoordinate;
|
||||||
|
import seng302.Model.Boat;
|
||||||
import seng302.Model.BoatInRace;
|
import seng302.Model.BoatInRace;
|
||||||
|
import seng302.Model.Leg;
|
||||||
|
import seng302.Model.Marker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Joseph on 24/04/2017.
|
* Created by Joseph on 24/04/2017.
|
||||||
*/
|
*/
|
||||||
public class StreamedBoat extends BoatInRace {
|
public class StreamedBoat extends Boat {
|
||||||
private int sourceID;
|
private int sourceID;
|
||||||
private boolean complete;
|
private boolean dnf = false;
|
||||||
|
|
||||||
public StreamedBoat(int sourceID, String name, Color colour, String abbrev) {
|
private void init() {
|
||||||
super(name, colour, abbrev);
|
this.velocity = 0;
|
||||||
this.sourceID = sourceID;
|
|
||||||
this.complete = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamedBoat(int sourceID) {
|
public StreamedBoat(int sourceID, String name, String abbrev) {
|
||||||
super("None", Color.BLACK, "None");
|
super(name, abbrev);
|
||||||
this.sourceID = sourceID;
|
this.sourceID = sourceID;
|
||||||
this.complete = false;
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StreamedBoat(int sourceID) {
|
||||||
/**
|
super("None", "None");
|
||||||
* Overridden to ignore this function
|
this.sourceID = sourceID;
|
||||||
*
|
this.init();
|
||||||
* @return 0
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
public double getScaledVelocity() {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overridden to ignore this function
|
* Calculates the azimuth of the travel via heading of the boat
|
||||||
*
|
*
|
||||||
* @param velocity of boat
|
* @return the direction that the boat is heading towards in degrees (-180 to 180).
|
||||||
* @deprecated
|
|
||||||
*/
|
*/
|
||||||
public void setScaledVelocity(double velocity) {
|
public double calculateAzimuth() {
|
||||||
|
double azimuth;
|
||||||
|
if (heading <= 180) {
|
||||||
|
azimuth = heading;
|
||||||
|
} else {
|
||||||
|
azimuth = -heading + 180;
|
||||||
|
}
|
||||||
|
return azimuth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,209 +1,208 @@
|
|||||||
package seng302.Model;
|
//package seng302.Model;
|
||||||
|
//
|
||||||
import org.geotools.referencing.GeodeticCalculator;
|
//import org.geotools.referencing.GeodeticCalculator;
|
||||||
import seng302.Constants;
|
//import seng302.Constants;
|
||||||
import seng302.Controllers.RaceController;
|
//import seng302.Controllers.RaceController;
|
||||||
import seng302.GPSCoordinate;
|
//import seng302.GPSCoordinate;
|
||||||
import seng302.RaceDataSource;
|
//import seng302.RaceDataSource;
|
||||||
|
//
|
||||||
import java.awt.geom.Point2D;
|
//import java.awt.geom.Point2D;
|
||||||
import java.util.ArrayList;
|
//import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
//import java.util.Arrays;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
import java.util.Random;
|
//import java.util.Random;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* Created by cbt24 on 6/03/17.
|
// * Created by cbt24 on 6/03/17.
|
||||||
*
|
// *
|
||||||
* @deprecated
|
// * @deprecated
|
||||||
*/
|
// */
|
||||||
public class ConstantVelocityRace extends Race {
|
//public class ConstantVelocityRace extends Race {
|
||||||
|
//
|
||||||
private int dnfChance = 0; //%percentage chance a boat fails at each checkpoint
|
// private int dnfChance = 0; //%percentage chance a boat fails at each checkpoint
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Initialiser for a constant velocity race without standard data source
|
// * Initialiser for a constant velocity race without standard data source
|
||||||
*
|
// *
|
||||||
* @param startingBoats in race
|
// * @param startingBoats in race
|
||||||
* @param legs in race
|
// * @param legs in race
|
||||||
* @param controller for graphics
|
// * @param controller for graphics
|
||||||
* @param scaleFactor of timer
|
// * @param scaleFactor of timer
|
||||||
*/
|
// */
|
||||||
public ConstantVelocityRace(List<BoatInRace> startingBoats, List<Leg> legs, RaceController controller, int scaleFactor) {
|
// public ConstantVelocityRace(List<BoatInRace> startingBoats, List<Leg> legs, RaceController controller, int scaleFactor) {
|
||||||
super(startingBoats, legs, controller, scaleFactor);
|
// super(startingBoats, legs, controller, scaleFactor);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Initialiser for legacy tests
|
// * Initialiser for legacy tests
|
||||||
*
|
// *
|
||||||
* @param startingBoats in race
|
// * @param startingBoats in race
|
||||||
* @param legs in race
|
// * @param legs in race
|
||||||
* @param controller for graphics
|
// * @param controller for graphics
|
||||||
* @param scaleFactor of timer
|
// * @param scaleFactor of timer
|
||||||
* @deprecated Please use {@link #ConstantVelocityRace(List, List, RaceController, int) } for future tests.
|
// *
|
||||||
*/
|
// * @deprecated Please use {@link #ConstantVelocityRace(List, List, RaceController, int) } for future tests.
|
||||||
public ConstantVelocityRace(BoatInRace[] startingBoats, List<Leg> legs, RaceController controller, int scaleFactor) {
|
// */
|
||||||
super(Arrays.asList(startingBoats), legs, controller, scaleFactor);
|
// public ConstantVelocityRace(BoatInRace[] startingBoats, List<Leg> legs, RaceController controller, int scaleFactor) {
|
||||||
}
|
// super(Arrays.asList(startingBoats), legs, controller, scaleFactor);
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Initialiser for constant velocity race with standard data source
|
// /**
|
||||||
*
|
// * Initialiser for constant velocity race with standard data source
|
||||||
* @param raceData for race
|
// * @param raceData for race
|
||||||
* @param controller for graphics
|
// * @param controller for graphics
|
||||||
* @param scaleFactor of timer
|
// * @param scaleFactor of timer
|
||||||
*/
|
// */
|
||||||
public ConstantVelocityRace(RaceDataSource raceData, RaceController controller, int scaleFactor) {
|
// public ConstantVelocityRace(RaceDataSource raceData, RaceController controller, int scaleFactor) {
|
||||||
super(raceData, controller, scaleFactor);
|
// super(raceData, controller, scaleFactor);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// public void initialiseBoats() {
|
||||||
* Calculates the boats next GPS position based on its distance travelled and heading
|
// Leg officialStart = legs.get(0);
|
||||||
*
|
// String name = officialStart.getName();
|
||||||
* @param oldCoordinates GPS coordinates of the boat's starting position
|
// Marker endMarker = officialStart.getEndMarker();
|
||||||
* @param distanceTravelled distance in nautical miles
|
//
|
||||||
* @param azimuth boat's current direction. Value between -180 and 180
|
// BoatInRace.setTrackPointTimeInterval(BoatInRace.getBaseTrackPointTimeInterval() / scaleFactor);
|
||||||
* @return The boat's new coordinate
|
//
|
||||||
*/
|
// ArrayList<Marker> startMarkers = getSpreadStartingPositions();
|
||||||
public static GPSCoordinate calculatePosition(GPSCoordinate oldCoordinates, double distanceTravelled, double azimuth) {
|
// for (int i = 0; i < startingBoats.size(); i++) {
|
||||||
|
// BoatInRace boat = startingBoats.get(i);
|
||||||
//Find new coordinate using current heading and distance
|
// if (boat != null) {
|
||||||
|
// boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
|
||||||
GeodeticCalculator geodeticCalculator = new GeodeticCalculator();
|
// Leg startLeg = new Leg(name, 0);
|
||||||
//Load start point into calculator
|
// boat.setCurrentPosition(startMarkers.get(i).getAverageGPSCoordinate());
|
||||||
Point2D startPoint = new Point2D.Double(oldCoordinates.getLongitude(), oldCoordinates.getLatitude());
|
// startLeg.setStartMarker(startMarkers.get(i));
|
||||||
geodeticCalculator.setStartingGeographicPoint(startPoint);
|
// startLeg.setEndMarker(endMarker);
|
||||||
//load direction and distance tranvelled into calculator
|
// startLeg.calculateDistance();
|
||||||
geodeticCalculator.setDirection(azimuth, distanceTravelled * Constants.NMToMetersConversion);
|
// boat.setCurrentLeg(startLeg);
|
||||||
//get new point
|
// boat.setHeading(boat.calculateHeading());
|
||||||
Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint();
|
// }
|
||||||
|
// }
|
||||||
return new GPSCoordinate(endPoint.getY(), endPoint.getX());
|
// }
|
||||||
}
|
//
|
||||||
|
// /**
|
||||||
public void initialiseBoats() {
|
// * Creates a list of starting positions for the different boats, so they do not appear cramped at the start line
|
||||||
Leg officialStart = legs.get(0);
|
// *
|
||||||
String name = officialStart.getName();
|
// * @return list of starting positions
|
||||||
Marker endMarker = officialStart.getEndMarker();
|
// */
|
||||||
|
// public ArrayList<Marker> getSpreadStartingPositions() {
|
||||||
BoatInRace.setTrackPointTimeInterval(BoatInRace.getBaseTrackPointTimeInterval() / scaleFactor);
|
//
|
||||||
|
// int nBoats = startingBoats.size();
|
||||||
ArrayList<Marker> startMarkers = getSpreadStartingPositions();
|
// Marker marker = legs.get(0).getStartMarker();
|
||||||
for (int i = 0; i < startingBoats.size(); i++) {
|
//
|
||||||
BoatInRace boat = startingBoats.get(i);
|
// GeodeticCalculator initialCalc = new GeodeticCalculator();
|
||||||
if (boat != null) {
|
// initialCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
||||||
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
|
// initialCalc.setDestinationGeographicPoint(marker.getMark2().getLongitude(), marker.getMark2().getLatitude());
|
||||||
Leg startLeg = new Leg(name, 0);
|
//
|
||||||
boat.setCurrentPosition(startMarkers.get(i).getAverageGPSCoordinate());
|
// double azimuth = initialCalc.getAzimuth();
|
||||||
startLeg.setStartMarker(startMarkers.get(i));
|
// double distanceBetweenMarkers = initialCalc.getOrthodromicDistance();
|
||||||
startLeg.setEndMarker(endMarker);
|
// double distanceBetweenBoats = distanceBetweenMarkers / (nBoats + 1);
|
||||||
startLeg.calculateDistance();
|
//
|
||||||
boat.setCurrentLeg(startLeg);
|
// GeodeticCalculator positionCalc = new GeodeticCalculator();
|
||||||
boat.setHeading(boat.calculateHeading());
|
// positionCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
||||||
}
|
// ArrayList<Marker> positions = new ArrayList<>();
|
||||||
}
|
//
|
||||||
}
|
// for (int i = 0; i < nBoats; i++) {
|
||||||
|
// positionCalc.setDirection(azimuth, distanceBetweenBoats);
|
||||||
/**
|
// Point2D position = positionCalc.getDestinationGeographicPoint();
|
||||||
* Creates a list of starting positions for the different boats, so they do not appear cramped at the start line
|
// positions.add(new Marker(new GPSCoordinate(position.getY(), position.getX())));
|
||||||
*
|
//
|
||||||
* @return list of starting positions
|
// positionCalc = new GeodeticCalculator();
|
||||||
*/
|
// positionCalc.setStartingGeographicPoint(position);
|
||||||
public ArrayList<Marker> getSpreadStartingPositions() {
|
// }
|
||||||
|
// return positions;
|
||||||
int nBoats = startingBoats.size();
|
// }
|
||||||
Marker marker = legs.get(0).getStartMarker();
|
//
|
||||||
|
// /**
|
||||||
GeodeticCalculator initialCalc = new GeodeticCalculator();
|
// * Sets the chance each boat has of failing at a gate or marker
|
||||||
initialCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
// * @param chance percentage chance a boat has of failing per checkpoint.
|
||||||
initialCalc.setDestinationGeographicPoint(marker.getMark2().getLongitude(), marker.getMark2().getLatitude());
|
// */
|
||||||
|
// protected void setDnfChance(int chance) {
|
||||||
double azimuth = initialCalc.getAzimuth();
|
// if (chance >= 0 && chance <= 100) {
|
||||||
double distanceBetweenMarkers = initialCalc.getOrthodromicDistance();
|
// dnfChance = chance;
|
||||||
double distanceBetweenBoats = distanceBetweenMarkers / (nBoats + 1);
|
// }
|
||||||
|
// }
|
||||||
GeodeticCalculator positionCalc = new GeodeticCalculator();
|
//
|
||||||
positionCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
// protected boolean doNotFinish() {
|
||||||
ArrayList<Marker> positions = new ArrayList<>();
|
// Random rand = new Random();
|
||||||
|
// return rand.nextInt(100) < dnfChance;
|
||||||
for (int i = 0; i < nBoats; i++) {
|
// }
|
||||||
positionCalc.setDirection(azimuth, distanceBetweenBoats);
|
//
|
||||||
Point2D position = positionCalc.getDestinationGeographicPoint();
|
// /**
|
||||||
positions.add(new Marker(new GPSCoordinate(position.getY(), position.getX())));
|
// * Calculates the distance a boat has travelled and updates its current position according to this value.
|
||||||
|
// *
|
||||||
positionCalc = new GeodeticCalculator();
|
// * @param boat to be updated
|
||||||
positionCalc.setStartingGeographicPoint(position);
|
// * @param millisecondsElapsed since last update
|
||||||
}
|
// */
|
||||||
return positions;
|
// protected void updatePosition(BoatInRace boat, int millisecondsElapsed) {
|
||||||
}
|
//
|
||||||
|
// //distanceTravelled = velocity (nm p hr) * time taken to update loop
|
||||||
/**
|
// double distanceTravelled = (boat.getScaledVelocity() * millisecondsElapsed) / 3600000;
|
||||||
* Sets the chance each boat has of failing at a gate or marker
|
//
|
||||||
*
|
// double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg();
|
||||||
* @param chance percentage chance a boat has of failing per checkpoint.
|
//
|
||||||
*/
|
// boolean finish = boat.getCurrentLeg().getName().equals("Finish");
|
||||||
protected void setDnfChance(int chance) {
|
// if (!finish) {
|
||||||
if (chance >= 0 && chance <= 100) {
|
// boat.setHeading(boat.calculateHeading());
|
||||||
dnfChance = chance;
|
// //update boat's distance travelled
|
||||||
}
|
// boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
||||||
}
|
// //Calculate boat's new position by adding the distance travelled onto the start point of the leg
|
||||||
|
// boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartMarker().getAverageGPSCoordinate(),
|
||||||
protected boolean doNotFinish() {
|
// totalDistanceTravelled, boat.calculateAzimuth()));
|
||||||
Random rand = new Random();
|
// }
|
||||||
return rand.nextInt(100) < dnfChance;
|
// }
|
||||||
}
|
//
|
||||||
|
// protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
||||||
/**
|
// if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()) {
|
||||||
* Calculates the distance a boat has travelled and updates its current position according to this value.
|
// //boat has passed onto new leg
|
||||||
*
|
// if (boat.getCurrentLeg().getName().equals("Finish")) {
|
||||||
* @param boat to be updated
|
// //boat has finished
|
||||||
* @param millisecondsElapsed since last update
|
// boatsFinished++;
|
||||||
*/
|
// boat.setFinished(true);
|
||||||
protected void updatePosition(BoatInRace boat, int millisecondsElapsed) {
|
// boat.setTimeFinished(timeElapsed);
|
||||||
|
// } else if (doNotFinish()) {
|
||||||
//distanceTravelled = velocity (nm p hr) * time taken to update loop
|
// boatsFinished++;
|
||||||
double distanceTravelled = (boat.getScaledVelocity() * millisecondsElapsed) / 3600000;
|
// boat.setFinished(true);
|
||||||
|
// boat.setCurrentLeg(new Leg("DNF", -1));
|
||||||
double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg();
|
// boat.setVelocity(0);
|
||||||
|
// boat.setScaledVelocity(0);
|
||||||
boolean finish = boat.getCurrentLeg().getName().equals("Finish");
|
// } else {
|
||||||
if (!finish) {
|
// //Calculate how much the boat overshot the marker by
|
||||||
boat.setHeading(boat.calculateHeading());
|
// boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
||||||
//update boat's distance travelled
|
// //Move boat on to next leg
|
||||||
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
// Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
||||||
//Calculate boat's new position by adding the distance travelled onto the start point of the leg
|
//
|
||||||
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartMarker().getAverageGPSCoordinate(),
|
// boat.setCurrentLeg(nextLeg);
|
||||||
totalDistanceTravelled, boat.calculateAzimuth()));
|
// //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
|
||||||
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
// updatePositions();
|
||||||
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()) {
|
// }
|
||||||
//boat has passed onto new leg
|
// }
|
||||||
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
//
|
||||||
//boat has finished
|
// /**
|
||||||
boatsFinished++;
|
// * Calculates the boats next GPS position based on its distance travelled and heading
|
||||||
boat.setFinished(true);
|
// *
|
||||||
boat.setTimeFinished(timeElapsed);
|
// * @param oldCoordinates GPS coordinates of the boat's starting position
|
||||||
} else if (doNotFinish()) {
|
// * @param distanceTravelled distance in nautical miles
|
||||||
boatsFinished++;
|
// * @param azimuth boat's current direction. Value between -180 and 180
|
||||||
boat.setFinished(true);
|
// * @return The boat's new coordinate
|
||||||
boat.setCurrentLeg(new Leg("DNF", -1));
|
// */
|
||||||
boat.setVelocity(0);
|
// public static GPSCoordinate calculatePosition(GPSCoordinate oldCoordinates, double distanceTravelled, double azimuth) {
|
||||||
boat.setScaledVelocity(0);
|
//
|
||||||
} else {
|
// //Find new coordinate using current heading and distance
|
||||||
//Calculate how much the boat overshot the marker by
|
//
|
||||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
// GeodeticCalculator geodeticCalculator = new GeodeticCalculator();
|
||||||
//Move boat on to next leg
|
// //Load start point into calculator
|
||||||
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
// Point2D startPoint = new Point2D.Double(oldCoordinates.getLongitude(), oldCoordinates.getLatitude());
|
||||||
|
// geodeticCalculator.setStartingGeographicPoint(startPoint);
|
||||||
boat.setCurrentLeg(nextLeg);
|
// //load direction and distance tranvelled into calculator
|
||||||
//Add overshoot distance into the distance travelled for the next leg
|
// geodeticCalculator.setDirection(azimuth, distanceTravelled * Constants.NMToMetersConversion);
|
||||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
|
// //get new point
|
||||||
}
|
// Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint();
|
||||||
//Update the boat display table in the GUI to reflect the leg change
|
//
|
||||||
updatePositions();
|
// return new GPSCoordinate(endPoint.getY(), endPoint.getX());
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
|
//}
|
||||||
}
|
|
||||||
@ -1,139 +1,140 @@
|
|||||||
package seng302.Model;
|
//package seng302.Model;
|
||||||
|
//
|
||||||
|
//
|
||||||
import javafx.scene.paint.Color;
|
//import javafx.scene.paint.Color;
|
||||||
import org.geotools.referencing.GeodeticCalculator;
|
//import org.geotools.referencing.GeodeticCalculator;
|
||||||
import org.junit.Test;
|
//import org.junit.Test;
|
||||||
import seng302.Constants;
|
//import seng302.Constants;
|
||||||
import seng302.GPSCoordinate;
|
//import seng302.GPSCoordinate;
|
||||||
|
//
|
||||||
import java.util.ArrayList;
|
//import java.lang.reflect.Array;
|
||||||
|
//import java.util.ArrayList;
|
||||||
import static org.junit.Assert.assertEquals;
|
//
|
||||||
|
//import static org.junit.Assert.assertEquals;
|
||||||
/**
|
//
|
||||||
* Created by esa46 on 16/03/17.
|
///**
|
||||||
*/
|
// * Created by esa46 on 16/03/17.
|
||||||
public class ConstantVelocityRaceTest {
|
// */
|
||||||
|
//public class ConstantVelocityRaceTest {
|
||||||
Marker START_MARKER = new Marker(new GPSCoordinate(0, 0));
|
//
|
||||||
Marker END_MARKER = new Marker(new GPSCoordinate(10, 10));
|
// Marker START_MARKER = new Marker(new GPSCoordinate(0, 0));
|
||||||
Leg START_LEG = new Leg("Start", START_MARKER, END_MARKER, 0);
|
// Marker END_MARKER = new Marker(new GPSCoordinate(10, 10));
|
||||||
|
// Leg START_LEG = new Leg("Start", START_MARKER, END_MARKER, 0);
|
||||||
int ONE_HOUR = 3600000; //1 hour in milliseconds
|
//
|
||||||
|
// int ONE_HOUR = 3600000; //1 hour in milliseconds
|
||||||
|
//
|
||||||
private ArrayList<Leg> generateLegsArray() {
|
//
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
// private ArrayList<Leg> generateLegsArray() {
|
||||||
legs.add(START_LEG);
|
// ArrayList<Leg> legs = new ArrayList<>();
|
||||||
return legs;
|
// legs.add(START_LEG);
|
||||||
}
|
// return legs;
|
||||||
|
// }
|
||||||
@Test
|
//
|
||||||
public void updatePositionChangesDistanceTravelled() {
|
// @Test
|
||||||
ArrayList<Leg> legs = generateLegsArray();
|
// public void updatePositionChangesDistanceTravelled() {
|
||||||
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
// ArrayList<Leg> legs = generateLegsArray();
|
||||||
boat.setCurrentLeg(legs.get(0));
|
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||||
boat.setDistanceTravelledInLeg(0);
|
// boat.setCurrentLeg(legs.get(0));
|
||||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
// boat.setDistanceTravelledInLeg(0);
|
||||||
|
// BoatInRace[] boats = new BoatInRace[]{boat};
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
//
|
||||||
|
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
||||||
race.updatePosition(boat, ONE_HOUR);
|
//
|
||||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity(), 1e-8);
|
// race.updatePosition(boat, ONE_HOUR);
|
||||||
}
|
// assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity(), 1e-8);
|
||||||
|
// }
|
||||||
|
//
|
||||||
@Test
|
//
|
||||||
public void updatePositionHandlesNoChangeToDistanceTravelled() {
|
// @Test
|
||||||
|
// public void updatePositionHandlesNoChangeToDistanceTravelled() {
|
||||||
ArrayList<Leg> legs = generateLegsArray();
|
//
|
||||||
BoatInRace boat = new BoatInRace("Test", 0, Color.ALICEBLUE, "tt");
|
// ArrayList<Leg> legs = generateLegsArray();
|
||||||
boat.setCurrentLeg(legs.get(0));
|
// BoatInRace boat = new BoatInRace("Test", 0, Color.ALICEBLUE, "tt");
|
||||||
boat.setDistanceTravelledInLeg(0);
|
// boat.setCurrentLeg(legs.get(0));
|
||||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
// boat.setDistanceTravelledInLeg(0);
|
||||||
|
// BoatInRace[] boats = new BoatInRace[]{boat};
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
//
|
||||||
|
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
||||||
race.updatePosition(boat, ONE_HOUR);
|
//
|
||||||
assertEquals(boat.getDistanceTravelledInLeg(), 0, 1e-8);
|
// race.updatePosition(boat, ONE_HOUR);
|
||||||
}
|
// assertEquals(boat.getDistanceTravelledInLeg(), 0, 1e-8);
|
||||||
|
// }
|
||||||
@Test
|
//
|
||||||
public void changesToDistanceTravelledAreAdditive() {
|
// @Test
|
||||||
|
// public void changesToDistanceTravelledAreAdditive() {
|
||||||
ArrayList<Leg> legs = generateLegsArray();
|
//
|
||||||
BoatInRace boat = new BoatInRace("Test", 5, Color.ALICEBLUE, "tt");
|
// ArrayList<Leg> legs = generateLegsArray();
|
||||||
boat.setCurrentLeg(legs.get(0));
|
// BoatInRace boat = new BoatInRace("Test", 5, Color.ALICEBLUE, "tt");
|
||||||
boat.setDistanceTravelledInLeg(50);
|
// boat.setCurrentLeg(legs.get(0));
|
||||||
BoatInRace[] boats = new BoatInRace[]{boat};
|
// boat.setDistanceTravelledInLeg(50);
|
||||||
|
// BoatInRace[] boats = new BoatInRace[]{boat};
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
//
|
||||||
|
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 1);
|
||||||
race.updatePosition(boat, ONE_HOUR);
|
//
|
||||||
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() + 50, 1e-8);
|
// race.updatePosition(boat, ONE_HOUR);
|
||||||
}
|
// assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() + 50, 1e-8);
|
||||||
|
// }
|
||||||
@Test
|
//
|
||||||
public void travelling10nmNorthGivesCorrectNewCoordinates() {
|
// @Test
|
||||||
GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
// public void travelling10nmNorthGivesCorrectNewCoordinates() {
|
||||||
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 0);
|
// GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
||||||
|
// GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 0);
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
//
|
||||||
calc.setStartingGeographicPoint(0, 0);
|
// GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
calc.setDirection(0, 10 * Constants.NMToMetersConversion);
|
// calc.setStartingGeographicPoint(0, 0);
|
||||||
|
// calc.setDirection(0, 10 * Constants.NMToMetersConversion);
|
||||||
assertEquals(newPos.getLongitude(), 0, 1e-8);
|
//
|
||||||
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
// assertEquals(newPos.getLongitude(), 0, 1e-8);
|
||||||
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
// assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
||||||
}
|
// assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
||||||
|
// }
|
||||||
|
//
|
||||||
@Test
|
//
|
||||||
public void travelling10nmEastGivesCorrectNewCoordinates() {
|
// @Test
|
||||||
GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
// public void travelling10nmEastGivesCorrectNewCoordinates() {
|
||||||
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 90);
|
// GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
||||||
|
// GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 90);
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
//
|
||||||
calc.setStartingGeographicPoint(0, 0);
|
// GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
calc.setDirection(90, 10 * Constants.NMToMetersConversion);
|
// calc.setStartingGeographicPoint(0, 0);
|
||||||
|
// calc.setDirection(90, 10 * Constants.NMToMetersConversion);
|
||||||
|
//
|
||||||
assertEquals(newPos.getLatitude(), 0, 1e-8);
|
//
|
||||||
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
// assertEquals(newPos.getLatitude(), 0, 1e-8);
|
||||||
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
// assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
||||||
}
|
// assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
||||||
|
// }
|
||||||
|
//
|
||||||
@Test
|
//
|
||||||
public void travelling10nmWestGivesCorrectNewCoordinates() {
|
// @Test
|
||||||
GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
// public void travelling10nmWestGivesCorrectNewCoordinates() {
|
||||||
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, -90);
|
// GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
||||||
|
// GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, -90);
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
//
|
||||||
calc.setStartingGeographicPoint(0, 0);
|
// GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
calc.setDirection(-90, 10 * Constants.NMToMetersConversion);
|
// calc.setStartingGeographicPoint(0, 0);
|
||||||
|
// calc.setDirection(-90, 10 * Constants.NMToMetersConversion);
|
||||||
|
//
|
||||||
assertEquals(newPos.getLatitude(), 0, 1e-8);
|
//
|
||||||
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
// assertEquals(newPos.getLatitude(), 0, 1e-8);
|
||||||
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
// assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
||||||
}
|
// assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
||||||
|
// }
|
||||||
|
//
|
||||||
@Test
|
//
|
||||||
public void travelling10nmSouthGivesCorrectNewCoordinates() {
|
// @Test
|
||||||
GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
// public void travelling10nmSouthGivesCorrectNewCoordinates() {
|
||||||
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 180);
|
// GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
||||||
|
// GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 180);
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
//
|
||||||
calc.setStartingGeographicPoint(0, 0);
|
// GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
calc.setDirection(180, 10 * Constants.NMToMetersConversion);
|
// calc.setStartingGeographicPoint(0, 0);
|
||||||
|
// calc.setDirection(180, 10 * Constants.NMToMetersConversion);
|
||||||
|
//
|
||||||
assertEquals(newPos.getLongitude(), 0, 1e-8);
|
//
|
||||||
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
// assertEquals(newPos.getLongitude(), 0, 1e-8);
|
||||||
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
// assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
||||||
}
|
// assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
||||||
|
// }
|
||||||
}
|
//
|
||||||
|
//}
|
||||||
|
|||||||
Loading…
Reference in new issue