package seng302.Model; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.scene.paint.Color; import org.geotools.referencing.GeodeticCalculator; import seng302.GPSCoordinate; /** * Boat in the Race extends Boat. * Created by esa46 on 15/03/17. */ public class BoatInRace extends Boat { private Leg currentLeg; private double distanceTravelledInLeg; private GPSCoordinate currentPosition; private long timeFinished; private Color colour; private boolean finished = false; /** * Constructor method. * @param name Name of the boat. * @param velocity Speed that the boat travels. * @param colour Colour the boat will be displayed as on the map */ public BoatInRace(String name, double velocity, Color colour, String abbrev) { super(name, velocity, abbrev); setColour(colour); } /** * * @return Returns the current position of the boat in a GPSCoordinate Class. * @see GPSCoordinate */ public GPSCoordinate getCurrentPosition() { return currentPosition; } /** * * @return Returns the time that the boat finished the race. */ public long getTimeFinished() { return timeFinished; } /** * * @return Returns the colour of the boat. */ public Color getColour() { return colour; } /** * Sets the colour that boat will be shown as when drawn on the ResizableRaceCanvas. * @param colour Colour that the boat is to be set to. * @see ResizableRaceCanvas */ public void setColour(Color colour) { this.colour = colour; } /** * Sets the time that the boat finished the race. * @param timeFinished Time the boat finished the race. */ public void setTimeFinished(long timeFinished) { this.timeFinished = timeFinished; } /** * Gets the current leg that the boat is on. * @return returns the leg the boat is on in a Leg class * @see Leg */ public Leg getCurrentLeg() { return currentLeg; } /** * Sets the current Leg of that the boat is on. * @param currentLeg Leg class that the boat is currently on. * @see Leg */ public void setCurrentLeg(Leg currentLeg) { this.currentLeg = currentLeg; } public StringProperty getCurrentLegName(){ StringProperty currentLegName = new SimpleStringProperty(""); if (currentLeg != null) { currentLegName.setValue(currentLeg.getName()); } return currentLegName; } /** * Gets the distance travelled by the boat in the leg. * @return Returns the value in nautical miles (1.852km) that the boat has traversed. */ public double getDistanceTravelledInLeg() { return distanceTravelledInLeg; } /** * Sets the current position on the GPS that the boat. * @param position GPSCoordinate of the position that the boat is currently on. * @see GPSCoordinate */ public void setCurrentPosition(GPSCoordinate position) { this.currentPosition = position; } /** * Sets the distance travelled by the boat in the leg in nautical miles (1.852km) * @param distanceTravelledInLeg Distance travelled by the boat in nautical miles. */ public void setDistanceTravelledInLeg(double distanceTravelledInLeg) { this.distanceTravelledInLeg = distanceTravelledInLeg; } public boolean isFinished() { return this.finished; } public void setFinished(boolean bool) { this.finished = bool; } /** * Calculates the azimuth of the travel via map coordinates of the raceMarkers * @return the direction that the boat is heading towards in degrees (-180 to 180). */ public double calculateAzimuth(){ GeodeticCalculator calc = new GeodeticCalculator(); calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLongitude(), currentLeg.getStartGraphCoordinate().getLatitude()); calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLongitude(), currentLeg.getEndGraphCoordinate().getLatitude()); 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); } }