package seng302.Model; import org.geotools.referencing.GeodeticCalculator; import seng302.Constants; import seng302.GPSCoordinate; /** * Created by cbt24 on 6/03/17. */ public class Leg { private final String name; //nautical miles private double distance; private CompoundMark startCompoundMark; private CompoundMark endCompoundMark; private final int legNumber; /** * Leg Initializer * * @param name Name of the Leg * @param start marker * @param end marker * @param number Leg's position in race */ public Leg(String name, CompoundMark start, CompoundMark end, int number) { this.name = name; this.startCompoundMark = start; this.endCompoundMark = 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 * @see Race */ public int getLegNumber() { return legNumber; } public CompoundMark getStartCompoundMark() { return startCompoundMark; } public void setStartCompoundMark(CompoundMark startCompoundMark) { this.startCompoundMark = startCompoundMark; } public CompoundMark getEndCompoundMark() { return endCompoundMark; } public void setEndCompoundMark(CompoundMark endCompoundMark) { this.endCompoundMark = endCompoundMark; } /** * Calculates the distance that the legs are in nautical miles (1.852 km). */ private void calculateDistance() { GeodeticCalculator calc = new GeodeticCalculator(); //Load start and end of leg GPSCoordinate startMarker = this.startCompoundMark.getAverageGPSCoordinate(); GPSCoordinate endMarker = this.endCompoundMark.getAverageGPSCoordinate(); calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude()); calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude()); this.distance = calc.getOrthodromicDistance() / Constants.NMToMetersConversion; } }