package seng302.Model; import org.geotools.referencing.GeodeticCalculator; import seng302.Constants; /** * Created by cbt24 on 6/03/17. */ public class Leg { private String name; //nautical miles private double distance; private Marker startMarker; private Marker endMarker; private int legNumber; /** * Leg Initialiser * * @param name Name of the Leg * @param start marker * @param end marker * @param number Leg's position in race */ public Leg(String name, Marker start, Marker end, int number) { this.name = name; this.startMarker = start; this.endMarker = end; this.legNumber = number; calculateDistance(); } /** * Construction Method * * @param name Name of the Leg * @param number leg number */ public Leg(String name, int number) { this.name = name; this.legNumber = number; } /** * Returns the name of the Leg * * @return Returns the name of the Leg */ public String getName() { return name; } /** * Get the distance in nautical miles * * @return Returns the total distance of the leg. */ public double getDistance() { return distance; } /** * Returns the leg number that the leg exists in the Race * * @return Returns the Leg */ public int getLegNumber() { return legNumber; } public Marker getStartMarker() { return startMarker; } public void setStartMarker(Marker startMarker) { this.startMarker = startMarker; } public Marker getEndMarker() { return endMarker; } public void setEndMarker(Marker endMarker) { this.endMarker = endMarker; } /** * Calculates the distance that the legs are in nautical miles (1.852 km). */ public void calculateDistance() { GeodeticCalculator calc = new GeodeticCalculator(); //Load start and end of leg GPSCoordinate startMarker = this.startMarker.getAverageGPSCoordinate(); GPSCoordinate endMarker = this.endMarker.getAverageGPSCoordinate(); calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude()); calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude()); this.distance = calc.getOrthodromicDistance() / Constants.NMToMetersConversion; } }