Long method class smells See merge request !15main
commit
93c1199392
@ -1,13 +0,0 @@
|
|||||||
package SharedModel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constants that are used throughout the program
|
|
||||||
* Created by Erika on 19-Mar-17.
|
|
||||||
*/
|
|
||||||
public class Constants {
|
|
||||||
//Knots x this = meters per second.
|
|
||||||
public static final double KnotsToMetersPerSecondConversionFactor = 0.514444;
|
|
||||||
|
|
||||||
public static final double wakeScale = 10;
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,99 +0,0 @@
|
|||||||
package SharedModel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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,17 +0,0 @@
|
|||||||
package seng302.Controllers;
|
|
||||||
|
|
||||||
import javafx.fxml.FXML;
|
|
||||||
import javafx.scene.layout.Pane;
|
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Joseph on 22/05/2017.
|
|
||||||
*/
|
|
||||||
public class ArrowController extends Controller {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,284 @@
|
|||||||
|
package seng302.Model;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
|
import javafx.scene.control.RadioButton;
|
||||||
|
import javafx.scene.control.Toggle;
|
||||||
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that processes user selected annotation visibility options to
|
||||||
|
* display the requested information on the
|
||||||
|
* {@link seng302.Model.ResizableRaceMap ResizbleRaceMap}. These are displayed
|
||||||
|
* via the {@link seng302.Controllers.RaceController RaceController}. <br>
|
||||||
|
* Annotation options for a {@link seng302.Model.Boat Boat} include: its name,
|
||||||
|
* abbreviation, speed, the time since it passed the last
|
||||||
|
* {@link seng302.Model.Marker Marker}, estimated time to the next marker,
|
||||||
|
* and a path it has travelled made up of
|
||||||
|
* {@link seng302.Model.TrackPoint TrackPoint}s.
|
||||||
|
*/
|
||||||
|
public class Annotations {
|
||||||
|
private ResizableRaceCanvas raceMap;
|
||||||
|
|
||||||
|
// checkable objects in the anchor pane
|
||||||
|
private Map<String, CheckBox> checkBoxes = new HashMap<>();
|
||||||
|
private Map<String, Toggle> annoToggles = new HashMap<>();
|
||||||
|
|
||||||
|
// maps of selected and saved annotations
|
||||||
|
private Map<String, Boolean> importantAnno = new HashMap<>();
|
||||||
|
private Map<String, Boolean> annoShownBeforeHide = new HashMap<>();
|
||||||
|
|
||||||
|
// string values match the fx:id value of check boxes
|
||||||
|
private static String nameCheckAnno = "showName";
|
||||||
|
private static String abbrevCheckAnno = "showAbbrev";
|
||||||
|
private static String speedCheckAnno = "showSpeed";
|
||||||
|
private static String pathCheckAnno = "showBoatPath";
|
||||||
|
private static String timeCheckAnno = "showTime";
|
||||||
|
private static String estTimeCheckAnno = "showEstTime";
|
||||||
|
|
||||||
|
// string values match the fx:id value of radio buttons
|
||||||
|
private static String noBtn = "noBtn";
|
||||||
|
private static String hideBtn = "hideAnnoRBtn";
|
||||||
|
private static String showBtn = "showAnnoRBtn";
|
||||||
|
private static String partialBtn = "partialAnnoRBtn";
|
||||||
|
private static String importantBtn = "importantAnnoRBtn";
|
||||||
|
|
||||||
|
private Boolean selectShow = false;
|
||||||
|
private String buttonChecked;
|
||||||
|
private String prevBtnChecked;
|
||||||
|
@FXML Button saveAnnoBtn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to set up and display initial annotations
|
||||||
|
* @param annotationPane javaFX pane containing annotation options
|
||||||
|
* @param raceMap the canvas to update annotation displays
|
||||||
|
*/
|
||||||
|
public Annotations(AnchorPane annotationPane, ResizableRaceCanvas raceMap){
|
||||||
|
this.raceMap = raceMap;
|
||||||
|
|
||||||
|
for (Node child : annotationPane.getChildren()) {
|
||||||
|
// collect all check boxes into a map
|
||||||
|
if (child.getClass()==CheckBox.class){
|
||||||
|
checkBoxes.put(child.getId(), (CheckBox)child);
|
||||||
|
}
|
||||||
|
// collect annotation toggle radio buttons into a map
|
||||||
|
else if (child.getClass()== RadioButton.class){
|
||||||
|
//annotationGroup.getToggles().add((RadioButton)child);
|
||||||
|
annoToggles.put(child.getId(), (RadioButton)child);
|
||||||
|
}
|
||||||
|
else if (child.getClass() == Button.class){
|
||||||
|
saveAnnoBtn = (Button)child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
initializeAnnotations();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up initial boat annotations and shows all data.
|
||||||
|
* Defines partial annotations.
|
||||||
|
* Creates listeners for when the user selects a different annotation
|
||||||
|
* visibility.
|
||||||
|
*/
|
||||||
|
public void initializeAnnotations() {
|
||||||
|
for (Map.Entry<String, CheckBox> checkBox : checkBoxes.entrySet())
|
||||||
|
{ annoShownBeforeHide.put(checkBox.getKey(), true); }
|
||||||
|
|
||||||
|
addCheckBoxListeners();
|
||||||
|
addSaveAnnoListener();
|
||||||
|
addAnnoToggleListeners();
|
||||||
|
|
||||||
|
annoToggles.get(showBtn).setSelected(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates listeners for each checkbox so the annotation display is
|
||||||
|
* updated when a user selects a different level of annotation visibility.
|
||||||
|
*/
|
||||||
|
private void addCheckBoxListeners(){
|
||||||
|
//listener for show name in annotation
|
||||||
|
checkBoxes.get(nameCheckAnno).selectedProperty()
|
||||||
|
.addListener((ov, old_val, new_val) -> {
|
||||||
|
if (old_val != new_val) {
|
||||||
|
raceMap.toggleAnnoName();
|
||||||
|
storeCurrentAnnotationState(nameCheckAnno, new_val);
|
||||||
|
raceMap.update();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//listener for show abbreviation for annotation
|
||||||
|
checkBoxes.get(abbrevCheckAnno).selectedProperty()
|
||||||
|
.addListener((ov, old_val, new_val) -> {
|
||||||
|
if (old_val != new_val) {
|
||||||
|
raceMap.toggleAnnoAbbrev();
|
||||||
|
storeCurrentAnnotationState(abbrevCheckAnno, new_val);
|
||||||
|
raceMap.update();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//listener for show boat path for annotation
|
||||||
|
checkBoxes.get(pathCheckAnno).selectedProperty()
|
||||||
|
.addListener((ov, old_val, new_val) -> {
|
||||||
|
if (old_val != new_val) {
|
||||||
|
raceMap.toggleBoatPath();
|
||||||
|
storeCurrentAnnotationState(pathCheckAnno, new_val);
|
||||||
|
raceMap.update();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//listener to show speed for annotation
|
||||||
|
checkBoxes.get(speedCheckAnno).selectedProperty()
|
||||||
|
.addListener((ov, old_val, new_val) -> {
|
||||||
|
if (old_val != new_val) {
|
||||||
|
raceMap.toggleAnnoSpeed();
|
||||||
|
storeCurrentAnnotationState(speedCheckAnno, new_val);
|
||||||
|
raceMap.update();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//listener to show time for annotation
|
||||||
|
checkBoxes.get(timeCheckAnno).selectedProperty()
|
||||||
|
.addListener((ov, old_val, new_val) -> {
|
||||||
|
if (old_val != new_val) {
|
||||||
|
raceMap.toggleAnnoTime();
|
||||||
|
storeCurrentAnnotationState(timeCheckAnno, new_val);
|
||||||
|
raceMap.update();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//listener to show estimated time for annotation
|
||||||
|
checkBoxes.get(estTimeCheckAnno).selectedProperty()
|
||||||
|
.addListener((ov, old_val, new_val) -> {
|
||||||
|
if (old_val != new_val) {
|
||||||
|
raceMap.toggleAnnoEstTime();
|
||||||
|
storeCurrentAnnotationState(estTimeCheckAnno, new_val);
|
||||||
|
raceMap.update();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a listener so the system knows when to save a users currently
|
||||||
|
* selected annotation options as important for future use.
|
||||||
|
*/
|
||||||
|
private void addSaveAnnoListener(){
|
||||||
|
//listener to save currently selected annotations as important
|
||||||
|
saveAnnoBtn.setOnAction(event -> {
|
||||||
|
importantAnno.clear();
|
||||||
|
for (Map.Entry<String, CheckBox> checkBox : checkBoxes.entrySet()){
|
||||||
|
importantAnno.put(checkBox.getKey(),
|
||||||
|
checkBox.getValue().isSelected());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates listeners for each visibility option so that the annotation
|
||||||
|
* display is updated when a user selects a different level of annotation
|
||||||
|
* visibility.
|
||||||
|
*/
|
||||||
|
private void addAnnoToggleListeners(){
|
||||||
|
//listener for hiding all annotations
|
||||||
|
RadioButton hideAnnoRBtn = (RadioButton)annoToggles.get(hideBtn);
|
||||||
|
hideAnnoRBtn.setOnAction((e)->{
|
||||||
|
buttonChecked = hideBtn;
|
||||||
|
selectShow = false;
|
||||||
|
for (Map.Entry<String, CheckBox> checkBox : checkBoxes.entrySet()){
|
||||||
|
checkBox.getValue().setSelected(false);
|
||||||
|
}
|
||||||
|
raceMap.update();
|
||||||
|
buttonChecked = noBtn;
|
||||||
|
prevBtnChecked = hideBtn;
|
||||||
|
selectShow = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
//listener for showing previously visible annotations
|
||||||
|
RadioButton showAnnoRBTN = (RadioButton)annoToggles.get(showBtn);
|
||||||
|
showAnnoRBTN.setOnAction((e)->{
|
||||||
|
if (selectShow) {
|
||||||
|
buttonChecked = showBtn;
|
||||||
|
for (Map.Entry<String, CheckBox> checkBox : checkBoxes.entrySet()){
|
||||||
|
checkBox.getValue().setSelected(
|
||||||
|
annoShownBeforeHide.get(checkBox.getKey()));
|
||||||
|
}
|
||||||
|
raceMap.update();
|
||||||
|
buttonChecked = noBtn;
|
||||||
|
prevBtnChecked = showBtn;
|
||||||
|
}
|
||||||
|
selectShow = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
//listener for showing a predetermined subset of annotations
|
||||||
|
RadioButton partialAnnoRBTN = (RadioButton)annoToggles.get(partialBtn);
|
||||||
|
partialAnnoRBTN.setOnAction((e)->{
|
||||||
|
selectShow = false;
|
||||||
|
buttonChecked = partialBtn;
|
||||||
|
for (Map.Entry<String, CheckBox> checkBox : checkBoxes.entrySet()){
|
||||||
|
// the checkbox defaults for partial annotations
|
||||||
|
if (checkBox.getKey().equals(abbrevCheckAnno)
|
||||||
|
|| checkBox.getKey().equals(speedCheckAnno)){
|
||||||
|
checkBox.getValue().setSelected(true);
|
||||||
|
}
|
||||||
|
else { checkBox.getValue().setSelected(false); }
|
||||||
|
}
|
||||||
|
raceMap.update();
|
||||||
|
buttonChecked = noBtn;
|
||||||
|
prevBtnChecked = partialBtn;
|
||||||
|
selectShow = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
//listener for showing all saved important annotations
|
||||||
|
RadioButton importantAnnoRBTN = (RadioButton)annoToggles.get(importantBtn);
|
||||||
|
importantAnnoRBTN.setOnAction((e) ->{
|
||||||
|
selectShow = false;
|
||||||
|
buttonChecked = importantBtn;
|
||||||
|
if (importantAnno.size()>0){
|
||||||
|
for (Map.Entry<String, CheckBox> checkBox : checkBoxes.entrySet()){
|
||||||
|
checkBox.getValue().setSelected
|
||||||
|
(importantAnno.get(checkBox.getKey()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buttonChecked = noBtn;
|
||||||
|
prevBtnChecked = importantBtn;
|
||||||
|
selectShow = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the current state of an annotation so that when a user
|
||||||
|
* deselects the hidden visibility option, the previous annotations will
|
||||||
|
* be displayed again.
|
||||||
|
* @param dictionaryAnnotationKey annotation checkbox
|
||||||
|
* @param selected boolean value representing the state of the checkbox
|
||||||
|
*/
|
||||||
|
private void storeCurrentAnnotationState(String dictionaryAnnotationKey, boolean selected){
|
||||||
|
if (buttonChecked != hideBtn) {
|
||||||
|
//if we are checking the box straight out of hide instead of using the radio buttons
|
||||||
|
annoShownBeforeHide.put(dictionaryAnnotationKey, selected);
|
||||||
|
if (prevBtnChecked == hideBtn && buttonChecked == noBtn){
|
||||||
|
storeCurrentAnnotationDictionary();
|
||||||
|
}
|
||||||
|
if (buttonChecked == noBtn) {
|
||||||
|
selectShow = false;
|
||||||
|
annoToggles.get(showBtn).setSelected(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores all current annotation states so that when a user
|
||||||
|
* deselects the hidden visibility option, the previous annotations will
|
||||||
|
* be displayed again.
|
||||||
|
*/
|
||||||
|
private void storeCurrentAnnotationDictionary(){
|
||||||
|
for (Map.Entry<String, CheckBox> checkBox : checkBoxes.entrySet()){
|
||||||
|
annoShownBeforeHide.put(checkBox.getKey(),
|
||||||
|
checkBox.getValue().isSelected());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,310 +1,311 @@
|
|||||||
package seng302.Model;
|
//package seng302.Model;
|
||||||
|
//
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
//import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.property.StringProperty;
|
//import javafx.beans.property.StringProperty;
|
||||||
import javafx.scene.paint.Color;
|
//import javafx.scene.paint.Color;
|
||||||
import org.geotools.referencing.GeodeticCalculator;
|
//import org.geotools.referencing.GeodeticCalculator;
|
||||||
import seng302.GPSCoordinate;
|
//import seng302.GPSCoordinate;
|
||||||
|
//
|
||||||
import java.awt.geom.Point2D;
|
//import java.awt.geom.Point2D;
|
||||||
import java.util.Queue;
|
//import java.util.Queue;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
//import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* Boat in the Race extends Boat.
|
// * Boat in the Race extends {@link seng302.Model.Boat Boat}.
|
||||||
* Created by esa46 on 15/03/17.
|
// * The extended properties are related to the boats current race position.
|
||||||
*/
|
// * @See seng302.Model.Boat
|
||||||
public class BoatInRace extends Boat {
|
// */
|
||||||
|
//public class BoatInRace extends Boat {
|
||||||
private Leg currentLeg;
|
//
|
||||||
private double scaledVelocity;
|
// private Leg currentLeg;
|
||||||
private double distanceTravelledInLeg;
|
// private double scaledVelocity;
|
||||||
private GPSCoordinate currentPosition;
|
// private double distanceTravelledInLeg;
|
||||||
private long timeFinished;
|
// private GPSCoordinate currentPosition;
|
||||||
private Color colour;
|
// private long timeFinished;
|
||||||
private boolean finished = false;
|
// private Color colour;
|
||||||
private final StringProperty currentLegName;
|
// private boolean finished = false;
|
||||||
private boolean started = false;
|
// private final StringProperty currentLegName;
|
||||||
private final StringProperty position;
|
// private boolean started = false;
|
||||||
private double heading;
|
// private final StringProperty position;
|
||||||
private static final double WAKE_SCALE = 10;
|
// private double heading;
|
||||||
|
// private static final double WAKE_SCALE = 10;
|
||||||
private final Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
|
//
|
||||||
private long nextValidTime = 0;
|
// private final Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
|
||||||
|
// private long nextValidTime = 0;
|
||||||
private static final float BASE_TRACK_POINT_TIME_INTERVAL = 5000;
|
//
|
||||||
private static float trackPointTimeInterval = 5000; // every 1 seconds
|
// private static final float BASE_TRACK_POINT_TIME_INTERVAL = 5000;
|
||||||
|
// private static float trackPointTimeInterval = 5000; // every 1 seconds
|
||||||
/**
|
//
|
||||||
* Constructor method.
|
// /**
|
||||||
*
|
// * Constructor method.
|
||||||
* @param name Name of the boat.
|
// *
|
||||||
* @param velocity Speed that the boat travels.
|
// * @param name Name of the boat.
|
||||||
* @param colour Colour the boat will be displayed as on the map
|
// * @param velocity Speed that the boat travels.
|
||||||
* @param abbrev of boat
|
// * @param colour Colour the boat will be displayed as on the map
|
||||||
*/
|
// * @param abbrev of boat
|
||||||
public BoatInRace(String name, double velocity, Color colour, String abbrev) {
|
// */
|
||||||
super(name, velocity, abbrev);
|
// public BoatInRace(String name, double velocity, Color colour, String abbrev) {
|
||||||
setColour(colour);
|
// super(name, velocity, abbrev);
|
||||||
currentLegName = new SimpleStringProperty("");
|
// setColour(colour);
|
||||||
position = new SimpleStringProperty("-");
|
// currentLegName = new SimpleStringProperty("");
|
||||||
}
|
// position = new SimpleStringProperty("-");
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Calculates the azimuth of the travel via map coordinates of the raceMarkers
|
// /**
|
||||||
*
|
// * 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).
|
// *
|
||||||
*/
|
// * @return the direction that the boat is heading towards in degrees (-180 to 180).
|
||||||
public double calculateAzimuth() {
|
// */
|
||||||
|
// public double calculateAzimuth() {
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
//
|
||||||
GPSCoordinate start = currentLeg.getStartMarker().getAverageGPSCoordinate();
|
// GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
GPSCoordinate end = currentLeg.getEndMarker().getAverageGPSCoordinate();
|
// GPSCoordinate start = currentLeg.getStartMarker().getAverageGPSCoordinate();
|
||||||
|
// GPSCoordinate end = currentLeg.getEndMarker().getAverageGPSCoordinate();
|
||||||
calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude());
|
//
|
||||||
calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude());
|
// calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude());
|
||||||
|
// calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude());
|
||||||
return calc.getAzimuth();
|
//
|
||||||
}
|
// return calc.getAzimuth();
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Converts an azimuth to a bearing
|
// /**
|
||||||
*
|
// * Converts an azimuth to a bearing
|
||||||
* @param azimuth azimuth value to be converted
|
// *
|
||||||
* @return the bearings in degrees (0 to 360).
|
// * @param azimuth azimuth value to be converted
|
||||||
*/
|
// * @return the bearings in degrees (0 to 360).
|
||||||
private static double calculateHeading(double azimuth) {
|
// */
|
||||||
if (azimuth >= 0) {
|
// private static double calculateHeading(double azimuth) {
|
||||||
return azimuth;
|
// if (azimuth >= 0) {
|
||||||
} else {
|
// return azimuth;
|
||||||
return azimuth + 360;
|
// } else {
|
||||||
}
|
// return azimuth + 360;
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
public double getHeading() {
|
//
|
||||||
return heading;
|
// public double getHeading() {
|
||||||
}
|
// return heading;
|
||||||
|
// }
|
||||||
public void setHeading(double heading) {
|
//
|
||||||
this.heading = heading;
|
// public void setHeading(double heading) {
|
||||||
}
|
// this.heading = heading;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Calculates the bearing of the travel via map coordinates of the raceMarkers
|
// /**
|
||||||
*
|
// * 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).
|
// *
|
||||||
*/
|
// * @return the direction that the boat is heading towards in degrees (0 to 360).
|
||||||
public double calculateHeading() {
|
// */
|
||||||
double azimuth = calculateAzimuth();
|
// public double calculateHeading() {
|
||||||
return calculateHeading(azimuth);
|
// double azimuth = 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
|
// * Returns the position of the end of the boat's wake, which is 180 degrees
|
||||||
* speed.
|
// * from the boat's heading, and whose length is proportional to the boat's
|
||||||
*
|
// * speed.
|
||||||
* @return GPSCoordinate of wake endpoint.
|
// *
|
||||||
*/
|
// * @return GPSCoordinate of wake endpoint.
|
||||||
public GPSCoordinate getWake() {
|
// */
|
||||||
double reverseHeading = getHeading() - 180;
|
// public GPSCoordinate getWake() {
|
||||||
double distance = WAKE_SCALE * getVelocity();
|
// double reverseHeading = getHeading() - 180;
|
||||||
|
// double distance = WAKE_SCALE * getVelocity();
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
//
|
||||||
calc.setStartingGeographicPoint(
|
// GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
new Point2D.Double(getCurrentPosition().getLongitude(), getCurrentPosition().getLatitude())
|
// calc.setStartingGeographicPoint(
|
||||||
);
|
// new Point2D.Double(getCurrentPosition().getLongitude(), getCurrentPosition().getLatitude())
|
||||||
calc.setDirection(reverseHeading, distance);
|
// );
|
||||||
Point2D endpoint = calc.getDestinationGeographicPoint();
|
// calc.setDirection(reverseHeading, distance);
|
||||||
return new GPSCoordinate(endpoint.getY(), endpoint.getX());
|
// Point2D endpoint = calc.getDestinationGeographicPoint();
|
||||||
}
|
// return new GPSCoordinate(endpoint.getY(), endpoint.getX());
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* @return Scaled velocity of the boat
|
// /**
|
||||||
*/
|
// * @return Scaled velocity of the boat
|
||||||
public double getScaledVelocity() {
|
// */
|
||||||
return scaledVelocity;
|
// public double getScaledVelocity() {
|
||||||
}
|
// return scaledVelocity;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Sets the boat's scaled velocity
|
// /**
|
||||||
*
|
// * Sets the boat's scaled velocity
|
||||||
* @param velocity of boat
|
// *
|
||||||
*/
|
// * @param velocity of boat
|
||||||
public void setScaledVelocity(double velocity) {
|
// */
|
||||||
this.scaledVelocity = velocity;
|
// public void setScaledVelocity(double velocity) {
|
||||||
}
|
// this.scaledVelocity = velocity;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* @return Returns the current position of the boat in a GPSCoordinate Class.
|
// /**
|
||||||
* @see GPSCoordinate
|
// * @return Returns the current position of the boat in a GPSCoordinate Class.
|
||||||
*/
|
// * @see GPSCoordinate
|
||||||
public GPSCoordinate getCurrentPosition() {
|
// */
|
||||||
return currentPosition;
|
// public GPSCoordinate getCurrentPosition() {
|
||||||
}
|
// return currentPosition;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Sets the current position on the GPS that the boat.
|
// /**
|
||||||
*
|
// * Sets the current position on the GPS that the boat.
|
||||||
* @param position GPSCoordinate of the position that the boat is currently on.
|
// *
|
||||||
* @see GPSCoordinate
|
// * @param position GPSCoordinate of the position that the boat is currently on.
|
||||||
*/
|
// * @see GPSCoordinate
|
||||||
public void setCurrentPosition(GPSCoordinate position) {
|
// */
|
||||||
this.currentPosition = position;
|
// public void setCurrentPosition(GPSCoordinate position) {
|
||||||
}
|
// this.currentPosition = position;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* @return Returns the time that the boat finished the race.
|
// /**
|
||||||
*/
|
// * @return Returns the time that the boat finished the race.
|
||||||
public long getTimeFinished() {
|
// */
|
||||||
return timeFinished;
|
// public long getTimeFinished() {
|
||||||
}
|
// return timeFinished;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Sets the time that the boat finished the race.
|
// /**
|
||||||
*
|
// * Sets the time that the boat finished the race.
|
||||||
* @param timeFinished Time the boat finished the race.
|
// *
|
||||||
*/
|
// * @param timeFinished Time the boat finished the race.
|
||||||
public void setTimeFinished(long timeFinished) {
|
// */
|
||||||
this.timeFinished = timeFinished;
|
// public void setTimeFinished(long timeFinished) {
|
||||||
}
|
// this.timeFinished = timeFinished;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* @return Returns the colour of the boat.
|
// /**
|
||||||
*/
|
// * @return Returns the colour of the boat.
|
||||||
public Color getColour() {
|
// */
|
||||||
return colour;
|
// public Color getColour() {
|
||||||
}
|
// return colour;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Sets the colour that boat will be shown as when drawn on the ResizableRaceCanvas.
|
// /**
|
||||||
*
|
// * 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.
|
// *
|
||||||
* @see ResizableRaceCanvas
|
// * @param colour Colour that the boat is to be set to.
|
||||||
*/
|
// * @see ResizableRaceCanvas
|
||||||
private void setColour(Color colour) {
|
// */
|
||||||
this.colour = colour;
|
// private void setColour(Color colour) {
|
||||||
}
|
// this.colour = colour;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Gets the current leg that the boat is on.
|
// /**
|
||||||
*
|
// * Gets the current leg that the boat is on.
|
||||||
* @return returns the leg the boat is on in a Leg class
|
// *
|
||||||
* @see Leg
|
// * @return returns the leg the boat is on in a Leg class
|
||||||
*/
|
// * @see Leg
|
||||||
public Leg getCurrentLeg() {
|
// */
|
||||||
return currentLeg;
|
// public Leg getCurrentLeg() {
|
||||||
}
|
// return currentLeg;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Sets the boat's current leg.
|
// /**
|
||||||
*
|
// * Sets the boat's current leg.
|
||||||
* @param currentLeg Leg class that the boat is currently on.
|
// *
|
||||||
* @see Leg
|
// * @param currentLeg Leg class that the boat is currently on.
|
||||||
*/
|
// * @see Leg
|
||||||
public void setCurrentLeg(Leg currentLeg) {
|
// */
|
||||||
this.currentLeg = currentLeg;
|
// public void setCurrentLeg(Leg currentLeg) {
|
||||||
this.currentLegName.setValue(currentLeg.getName());
|
// this.currentLeg = currentLeg;
|
||||||
}
|
// this.currentLegName.setValue(currentLeg.getName());
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* @return Name of boat's current leg
|
// /**
|
||||||
*/
|
// * @return Name of boat's current leg
|
||||||
public StringProperty getCurrentLegName() {
|
// */
|
||||||
return currentLegName;
|
// public StringProperty getCurrentLegName() {
|
||||||
}
|
// return currentLegName;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Gets the distance travelled by the boat in the leg.
|
// /**
|
||||||
*
|
// * Gets the distance travelled by the boat in the leg.
|
||||||
* @return Returns the value in nautical miles (1.852km) that the boat has traversed.
|
// *
|
||||||
*/
|
// * @return Returns the value in nautical miles (1.852km) that the boat has traversed.
|
||||||
public double getDistanceTravelledInLeg() {
|
// */
|
||||||
return distanceTravelledInLeg;
|
// public double getDistanceTravelledInLeg() {
|
||||||
}
|
// return distanceTravelledInLeg;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Sets the distance travelled by the boat in the leg in nautical miles (1.852km)
|
// /**
|
||||||
*
|
// * 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.
|
// *
|
||||||
*/
|
// * @param distanceTravelledInLeg Distance travelled by the boat in nautical miles.
|
||||||
public void setDistanceTravelledInLeg(double distanceTravelledInLeg) {
|
// */
|
||||||
this.distanceTravelledInLeg = distanceTravelledInLeg;
|
// public void setDistanceTravelledInLeg(double distanceTravelledInLeg) {
|
||||||
}
|
// this.distanceTravelledInLeg = distanceTravelledInLeg;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* @return true if boat has finished, false if not
|
// /**
|
||||||
*/
|
// * @return true if boat has finished, false if not
|
||||||
public boolean isFinished() {
|
// */
|
||||||
return this.finished;
|
// public boolean isFinished() {
|
||||||
}
|
// return this.finished;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Sets whether boat is finished or not
|
// /**
|
||||||
*
|
// * Sets whether boat is finished or not
|
||||||
* @param bool is finished value
|
// *
|
||||||
*/
|
// * @param bool is finished value
|
||||||
public void setFinished(boolean bool) {
|
// */
|
||||||
this.finished = bool;
|
// public void setFinished(boolean bool) {
|
||||||
}
|
// this.finished = bool;
|
||||||
|
// }
|
||||||
public boolean isStarted() {
|
//
|
||||||
return started;
|
// public boolean isStarted() {
|
||||||
}
|
// return started;
|
||||||
|
// }
|
||||||
public void setStarted(boolean started) {
|
//
|
||||||
this.started = started;
|
// public void setStarted(boolean started) {
|
||||||
}
|
// this.started = started;
|
||||||
|
// }
|
||||||
public String getPosition() {
|
//
|
||||||
return position.get();
|
// public String getPosition() {
|
||||||
}
|
// return position.get();
|
||||||
|
// }
|
||||||
public StringProperty positionProperty() {
|
//
|
||||||
return position;
|
// public StringProperty positionProperty() {
|
||||||
}
|
// return position;
|
||||||
|
// }
|
||||||
public void setPosition(String position) {
|
//
|
||||||
this.position.set(position);
|
// public void setPosition(String position) {
|
||||||
}
|
// this.position.set(position);
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Adds a new point to boat's track.
|
// /**
|
||||||
* @param coordinate of point on track
|
// * Adds a new point to boat's track.
|
||||||
* @see seng302.Model.TrackPoint
|
// * @param coordinate of point on track
|
||||||
*/
|
// * @see seng302.Model.TrackPoint
|
||||||
public void addTrackPoint(GPSCoordinate coordinate) {
|
// */
|
||||||
Boolean added = System.currentTimeMillis() >= nextValidTime;
|
// public void addTrackPoint(GPSCoordinate coordinate) {
|
||||||
long currentTime = System.currentTimeMillis();
|
// Boolean added = System.currentTimeMillis() >= nextValidTime;
|
||||||
if (added && this.started) {
|
// long currentTime = System.currentTimeMillis();
|
||||||
nextValidTime = currentTime + (long) trackPointTimeInterval;
|
// if (added && this.started) {
|
||||||
int TRACK_POINT_LIMIT = 10;
|
// nextValidTime = currentTime + (long) trackPointTimeInterval;
|
||||||
track.add(new TrackPoint(coordinate, currentTime, TRACK_POINT_LIMIT * (long) trackPointTimeInterval));
|
// int TRACK_POINT_LIMIT = 10;
|
||||||
}
|
// track.add(new TrackPoint(coordinate, currentTime, TRACK_POINT_LIMIT * (long) trackPointTimeInterval));
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Returns the boat's sampled track between start of race and current time.
|
// /**
|
||||||
* @return queue of track points
|
// * Returns the boat's sampled track between start of race and current time.
|
||||||
* @see seng302.Model.TrackPoint
|
// * @return queue of track points
|
||||||
*/
|
// * @see seng302.Model.TrackPoint
|
||||||
public Queue<TrackPoint> getTrack() {
|
// */
|
||||||
return track;
|
// public Queue<TrackPoint> getTrack() {
|
||||||
}
|
// return track;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Get base track point time interval
|
// /**
|
||||||
* @return base track point time interval
|
// * Get base track point time interval
|
||||||
*/
|
// * @return base track point time interval
|
||||||
public static float getBaseTrackPointTimeInterval() {
|
// */
|
||||||
return BASE_TRACK_POINT_TIME_INTERVAL;
|
// public static float getBaseTrackPointTimeInterval() {
|
||||||
}
|
// return BASE_TRACK_POINT_TIME_INTERVAL;
|
||||||
|
// }
|
||||||
/**
|
//
|
||||||
* Set track point time interval
|
// /**
|
||||||
* @param value track point time interval value
|
// * Set track point time interval
|
||||||
*/
|
// * @param value track point time interval value
|
||||||
public static void setTrackPointTimeInterval(float value) {
|
// */
|
||||||
trackPointTimeInterval = value;
|
// public static void setTrackPointTimeInterval(float value) {
|
||||||
}
|
// trackPointTimeInterval = value;
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
|
|||||||
@ -0,0 +1,179 @@
|
|||||||
|
package seng302.Model;
|
||||||
|
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.chart.LineChart;
|
||||||
|
import javafx.scene.chart.NumberAxis;
|
||||||
|
import javafx.scene.chart.XYChart;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to process and modify a sparkline display. This display keeps visual
|
||||||
|
* track of {@link seng302.Model.Boat Boats}s in a race and their current
|
||||||
|
* placing position as they complete each {@link seng302.Model.Leg Leg} by
|
||||||
|
* passing a course {@link seng302.Model.Marker Marker}. <br>
|
||||||
|
* This sparkline is displayed using the
|
||||||
|
* {@link seng302.Controllers.RaceController RaceController}.
|
||||||
|
*/
|
||||||
|
public class Sparkline {
|
||||||
|
private ArrayList<String> colours;
|
||||||
|
private ArrayList<Boat> startBoats = new ArrayList<>();
|
||||||
|
private Map<Integer, String> boatColours = new HashMap<>();
|
||||||
|
private Integer legNum;
|
||||||
|
private Integer sparkLineNumber = 0;
|
||||||
|
@FXML LineChart<Number, Number> sparklineChart;
|
||||||
|
@FXML NumberAxis xAxis;
|
||||||
|
@FXML NumberAxis yAxis;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to set up initial sparkline (LineChart) object
|
||||||
|
* @param boats boats to display on the sparkline
|
||||||
|
* @param legNum total number of legs in the race
|
||||||
|
* @param sparklineChart javaFX LineChart for the sparkline
|
||||||
|
*/
|
||||||
|
public Sparkline(ObservableList<Boat> boats, Integer legNum,
|
||||||
|
LineChart<Number,Number> sparklineChart) {
|
||||||
|
this.sparklineChart = sparklineChart;
|
||||||
|
this.legNum = legNum;
|
||||||
|
this.yAxis = (NumberAxis)sparklineChart.getYAxis();
|
||||||
|
this.xAxis = (NumberAxis)sparklineChart.getXAxis();
|
||||||
|
startBoats.addAll(boats);
|
||||||
|
|
||||||
|
makeColours();
|
||||||
|
mapBoatColours();
|
||||||
|
createSparkline();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and sets initial display for Sparkline for race positions.
|
||||||
|
* A data series for each boat in the race is added.
|
||||||
|
* Position numbers are displayed.
|
||||||
|
*/
|
||||||
|
public void createSparkline(){
|
||||||
|
// NOTE: Y axis is in negatives to display correct positions
|
||||||
|
|
||||||
|
// all boats start in 'last' place
|
||||||
|
for (int i=0; i<startBoats.size(); i++){
|
||||||
|
XYChart.Series<Number, Number> series = new XYChart.Series();
|
||||||
|
series.getData().add(new XYChart.Data(0, -startBoats.size()));
|
||||||
|
series.getData().add(new XYChart.Data(0, -startBoats.size()));
|
||||||
|
sparklineChart.getData().add(series);
|
||||||
|
sparklineChart.getData().get(i).getNode().setStyle("-fx-stroke: " +
|
||||||
|
""+boatColours.get(startBoats.get(i).getSourceID())+";");
|
||||||
|
}
|
||||||
|
|
||||||
|
sparklineChart.setCreateSymbols(false);
|
||||||
|
|
||||||
|
// set x axis details
|
||||||
|
xAxis.setAutoRanging(false);
|
||||||
|
xAxis.setTickMarkVisible(false);
|
||||||
|
xAxis.setTickLabelsVisible(false);
|
||||||
|
xAxis.setMinorTickVisible(false);
|
||||||
|
xAxis.setUpperBound((startBoats.size()+1)*legNum);
|
||||||
|
xAxis.setTickUnit((startBoats.size()+1)*legNum);
|
||||||
|
|
||||||
|
// set y axis details
|
||||||
|
yAxis.setLowerBound(-(startBoats.size()+1));
|
||||||
|
yAxis.setUpperBound(0);
|
||||||
|
yAxis.setAutoRanging(false);
|
||||||
|
yAxis.setLabel("Position in Race");
|
||||||
|
yAxis.setTickUnit(1);
|
||||||
|
yAxis.setTickMarkVisible(false);
|
||||||
|
yAxis.setMinorTickVisible(false);
|
||||||
|
|
||||||
|
// hide minus number from displaying on axis
|
||||||
|
yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis) {
|
||||||
|
@Override
|
||||||
|
public String toString(Number value) {
|
||||||
|
if ((Double)value == 0.0
|
||||||
|
|| (Double)value < -startBoats.size()){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return String.format("%7.0f", -value.doubleValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the sparkline to display current boat positions.
|
||||||
|
* New points are plotted to represent each boat when required.
|
||||||
|
* @param boatsInRace current position of the boats in race
|
||||||
|
*/
|
||||||
|
public void updateSparkline(ObservableList<Boat> boatsInRace){
|
||||||
|
int placingVal = boatsInRace.size();
|
||||||
|
sparkLineNumber++;
|
||||||
|
|
||||||
|
for (int i = boatsInRace.size() - 1; i >= 0; i--){
|
||||||
|
for (int j = startBoats.size() - 1; j >= 0; j--){
|
||||||
|
if (boatsInRace.get(i)==startBoats.get(j)){
|
||||||
|
|
||||||
|
// when a boat is on its first leg
|
||||||
|
if (boatsInRace.get(i).getCurrentLeg().getLegNumber()==0){
|
||||||
|
// adjust boats latest point on X axis
|
||||||
|
sparklineChart.getData().get(j).getData().get(1)
|
||||||
|
.setXValue(sparkLineNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
// when a boat first enters its second leg
|
||||||
|
else if (boatsInRace.get(i).getCurrentLeg().getLegNumber
|
||||||
|
()==1 && sparklineChart.getData().get(j).getData
|
||||||
|
().size()==2){
|
||||||
|
// adjust boats position from start mark
|
||||||
|
sparklineChart.getData().get(j).getData().get(1)
|
||||||
|
.setYValue(-placingVal);
|
||||||
|
sparklineChart.getData().get(j).getData().get(1)
|
||||||
|
.setXValue(sparkLineNumber);
|
||||||
|
sparklineChart.getData().get(j).getData().add(new XYChart.Data<>
|
||||||
|
(sparkLineNumber, -placingVal));
|
||||||
|
}
|
||||||
|
|
||||||
|
// plot new point for boats current position
|
||||||
|
else {
|
||||||
|
sparklineChart.getData().get(j).getData().add
|
||||||
|
(new XYChart.Data<>(sparkLineNumber, -placingVal));
|
||||||
|
}
|
||||||
|
placingVal-=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void makeColours() {
|
||||||
|
colours = new ArrayList<>(Arrays.asList(
|
||||||
|
colourToHex(Color.BLUEVIOLET),
|
||||||
|
colourToHex(Color.BLACK),
|
||||||
|
colourToHex(Color.RED),
|
||||||
|
colourToHex(Color.ORANGE),
|
||||||
|
colourToHex(Color.DARKOLIVEGREEN),
|
||||||
|
colourToHex(Color.LIMEGREEN),
|
||||||
|
colourToHex(Color.PURPLE),
|
||||||
|
colourToHex(Color.DARKGRAY),
|
||||||
|
colourToHex(Color.YELLOW)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String colourToHex(Color color) {
|
||||||
|
return String.format( "#%02X%02X%02X",
|
||||||
|
(int)( color.getRed() * 255 ),
|
||||||
|
(int)( color.getGreen() * 255 ),
|
||||||
|
(int)( color.getBlue() * 255 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mapBoatColours() {
|
||||||
|
int currentColour = 0;
|
||||||
|
for (Boat boat : startBoats) {
|
||||||
|
if (!boatColours.containsKey(boat.getSourceID())) {
|
||||||
|
boatColours.put(boat.getSourceID(), colours.get(currentColour));
|
||||||
|
}
|
||||||
|
currentColour = (currentColour + 1) % colours.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,154 +1,149 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
import org.junit.Test;
|
|
||||||
import seng302.GPSCoordinate;
|
|
||||||
|
|
||||||
import static junit.framework.TestCase.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by esa46 on 22/03/17.
|
* Tests various aspects of a boat in race perform correctly.
|
||||||
*/
|
*/
|
||||||
public class BoatInRaceTest {
|
public class BoatInRaceTest {
|
||||||
|
// TODO change this test to use Boat and not BoatInRace ??
|
||||||
|
// TODO delete BoatInRace class
|
||||||
private final GPSCoordinate ORIGIN_COORDS = new GPSCoordinate(0, 0);
|
|
||||||
private final BoatInRace TEST_BOAT = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
// private final GPSCoordinate ORIGIN_COORDS = new GPSCoordinate(0, 0);
|
||||||
|
// private final BoatInRace TEST_BOAT = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||||
|
//
|
||||||
@Test
|
//
|
||||||
public void calculateDueNorthAzimuthReturns0() {
|
// @Test
|
||||||
|
// public void calculateDueNorthAzimuthReturns0() {
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
//
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
// Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8);
|
// TEST_BOAT.setCurrentLeg(start);
|
||||||
}
|
// assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8);
|
||||||
|
// }
|
||||||
@Test
|
//
|
||||||
public void calculateDueSouthAzimuthReturns180() {
|
// @Test
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
// public void calculateDueSouthAzimuthReturns180() {
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
|
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
// Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8);
|
// TEST_BOAT.setCurrentLeg(start);
|
||||||
}
|
// assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8);
|
||||||
|
// }
|
||||||
|
//
|
||||||
@Test
|
//
|
||||||
public void calculateDueEastAzimuthReturns90() {
|
// @Test
|
||||||
|
// public void calculateDueEastAzimuthReturns90() {
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
//
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(0, 50));
|
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
// Marker endMarker = new Marker(new GPSCoordinate(0, 50));
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8);
|
// TEST_BOAT.setCurrentLeg(start);
|
||||||
}
|
// assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8);
|
||||||
|
// }
|
||||||
|
//
|
||||||
@Test
|
//
|
||||||
public void calculateDueWestAzimuthReturnsNegative90() {
|
// @Test
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
// public void calculateDueWestAzimuthReturnsNegative90() {
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(0, -50));
|
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
// Marker endMarker = new Marker(new GPSCoordinate(0, -50));
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8);
|
// TEST_BOAT.setCurrentLeg(start);
|
||||||
|
// assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8);
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
@Test
|
//
|
||||||
public void calculateDueNorthHeadingReturns0() {
|
// @Test
|
||||||
|
// public void calculateDueNorthHeadingReturns0() {
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
//
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
// Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
assertEquals(TEST_BOAT.calculateHeading(), 0, 1e-8);
|
// TEST_BOAT.setCurrentLeg(start);
|
||||||
}
|
// assertEquals(TEST_BOAT.calculateHeading(), 0, 1e-8);
|
||||||
|
// }
|
||||||
|
//
|
||||||
@Test
|
//
|
||||||
public void calculateDueEastHeadingReturns90() {
|
// @Test
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
// public void calculateDueEastHeadingReturns90() {
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(0, 50));
|
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
// Marker endMarker = new Marker(new GPSCoordinate(0, 50));
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
assertEquals(TEST_BOAT.calculateHeading(), 90, 1e-8);
|
// TEST_BOAT.setCurrentLeg(start);
|
||||||
}
|
// assertEquals(TEST_BOAT.calculateHeading(), 90, 1e-8);
|
||||||
|
// }
|
||||||
@Test
|
//
|
||||||
public void calculateDueSouthHeadingReturns180() {
|
// @Test
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
// public void calculateDueSouthHeadingReturns180() {
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
|
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
// Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
assertEquals(TEST_BOAT.calculateHeading(), 180, 1e-8);
|
// TEST_BOAT.setCurrentLeg(start);
|
||||||
}
|
// assertEquals(TEST_BOAT.calculateHeading(), 180, 1e-8);
|
||||||
|
// }
|
||||||
@Test
|
//
|
||||||
public void calculateDueWestHeadingReturns270() {
|
// @Test
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
// public void calculateDueWestHeadingReturns270() {
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(0, -50));
|
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
// Marker endMarker = new Marker(new GPSCoordinate(0, -50));
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
// Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
assertEquals(TEST_BOAT.calculateHeading(), 270, 1e-8);
|
// TEST_BOAT.setCurrentLeg(start);
|
||||||
}
|
// assertEquals(TEST_BOAT.calculateHeading(), 270, 1e-8);
|
||||||
|
// }
|
||||||
@Test
|
//
|
||||||
public void createNewBoatCratesInstanceOfSuperClass() {
|
// @Test
|
||||||
|
// public void createNewBoatCratesInstanceOfSuperClass() {
|
||||||
BoatInRace testBoat = new BoatInRace("Boat", 20, Color.ALICEBLUE, "tt");
|
//
|
||||||
testBoat.setName("Name can change");
|
// BoatInRace testBoat = new BoatInRace("Boat", 20, Color.ALICEBLUE, "tt");
|
||||||
assertTrue(testBoat instanceof Boat);
|
// testBoat.setName("Name can change");
|
||||||
assertTrue(testBoat.getCurrentLeg() == null);
|
// assertTrue(testBoat instanceof Boat);
|
||||||
assertTrue(testBoat.getCurrentPosition() == null);
|
// assertTrue(testBoat.getCurrentLeg() == null);
|
||||||
assertTrue(testBoat.toString().contains("Name can change"));
|
// assertTrue(testBoat.getCurrentPosition() == null);
|
||||||
assertEquals(testBoat.getVelocity(), 20.0);
|
// assertTrue(testBoat.toString().contains("Name can change"));
|
||||||
assertTrue(testBoat.getVelocityProp().toString().contains("20"));
|
// assertEquals(testBoat.getVelocity(), 20.0);
|
||||||
assertTrue(testBoat.getAbbrev().equals("tt"));
|
// assertTrue(testBoat.getVelocityProp().toString().contains("20"));
|
||||||
assertTrue(testBoat.getColour().equals(Color.ALICEBLUE));
|
// assertTrue(testBoat.getAbbrev().equals("tt"));
|
||||||
assertFalse(testBoat.isFinished());
|
// assertTrue(testBoat.getColour().equals(Color.ALICEBLUE));
|
||||||
}
|
// assertFalse(testBoat.isFinished());
|
||||||
|
// }
|
||||||
|
//
|
||||||
@Test
|
//
|
||||||
public void getWakeAtProperHeading() throws Exception {
|
// @Test
|
||||||
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
// public void getWakeAtProperHeading() throws Exception {
|
||||||
|
// BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||||
// Construct leg of 0 degrees
|
//
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
// // Construct leg of 0 degrees
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
Leg leg0deg = new Leg("Start", startMarker, endMarker, 0);
|
// Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||||
boat.setCurrentLeg(leg0deg);
|
// Leg leg0deg = new Leg("Start", startMarker, endMarker, 0);
|
||||||
boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
// boat.setCurrentLeg(leg0deg);
|
||||||
|
// boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||||
assertEquals(0, boat.calculateHeading(), 1e-8);
|
//
|
||||||
|
// assertEquals(0, boat.calculateHeading(), 1e-8);
|
||||||
// Construct leg from wake - heading should be 180 degrees
|
//
|
||||||
Leg leg180deg = new Leg("Start", startMarker, new Marker(boat.getWake()), 0);
|
// // Construct leg from wake - heading should be 180 degrees
|
||||||
boat.setCurrentLeg(leg180deg);
|
// Leg leg180deg = new Leg("Start", startMarker, new Marker(boat.getWake()), 0);
|
||||||
|
// boat.setCurrentLeg(leg180deg);
|
||||||
assertEquals(180, boat.calculateHeading(), 1e-8);
|
//
|
||||||
}
|
// assertEquals(180, boat.calculateHeading(), 1e-8);
|
||||||
|
// }
|
||||||
|
//
|
||||||
@Test
|
//
|
||||||
public void getWakeProportionalToVelocity() throws Exception {
|
// @Test
|
||||||
BoatInRace boat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
// public void getWakeProportionalToVelocity() throws Exception {
|
||||||
|
// BoatInRace boat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||||
// Construct leg of 0 degrees at 0 N
|
//
|
||||||
Marker startMarker = new Marker(ORIGIN_COORDS);
|
// // Construct leg of 0 degrees at 0 N
|
||||||
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
// Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
Leg leg0deg = new Leg("Start", startMarker, endMarker, 0);
|
// Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||||
boat.setCurrentLeg(leg0deg);
|
// Leg leg0deg = new Leg("Start", startMarker, endMarker, 0);
|
||||||
boat.setCurrentPosition(new GPSCoordinate(0, 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();
|
// // 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);
|
// // Latitude of endpoint at 20 kn should be twice endpoint at 10 kn
|
||||||
assertEquals(2 * endpointAt10Kn, boat.getWake().getLatitude(), 1e-8);
|
// boat.setVelocity(20);
|
||||||
}
|
// assertEquals(2 * endpointAt10Kn, boat.getWake().getLatitude(), 1e-8);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
Loading…
Reference in new issue