package seng302.Model; import org.geotools.referencing.Console; import org.geotools.referencing.GeodeticCalculator; import seng302.Constants; import seng302.GPSCoordinate; import seng302.GraphCoordinate; /** * Created by cbt24 on 6/03/17. */ public class Leg { private String name; //nautical miles private double distance; private int legNumber; private GPSCoordinate startGPSCoordinate; private GPSCoordinate endGPSCoordinate; /** * Leg Initialiser * @param name Name of the Leg */ public Leg(String name, GPSCoordinate start, GPSCoordinate end, int number) { this.name = name; this.startGPSCoordinate = start; this.endGPSCoordinate = end; this.legNumber = number; this.distance = calculateDistance(); } /** * Construction Method * @param name Name of the Leg */ 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 coordinates in GPSCoordinate class of the boats starting coordinate. * @return Returns the coordinate of the start of the leg. * @see GPSCoordinate */ public GPSCoordinate getStartGraphCoordinate() { return startGPSCoordinate; } /** * Returns the coordinates in a GPSCoordinate class that the boat ends on. * @return Returns the coordinate of the end of the leg. * @see GPSCoordinate */ public GPSCoordinate getEndGraphCoordinate() { return endGPSCoordinate; } /** * Returns the leg number that the leg exists in the Race * @return Returns the Leg * @see Race */ public int getLegNumber() { return legNumber; } /** * Calculates the distance that the legs are in nautical miles (1.852 km). * @return Returns the leg distance. */ private double calculateDistance() { GeodeticCalculator calc = new GeodeticCalculator(); calc.setStartingGeographicPoint(startGPSCoordinate.getLongitude(), startGPSCoordinate.getLatitude()); calc.setDestinationGeographicPoint(endGPSCoordinate.getLongitude(), endGPSCoordinate.getLatitude()); return calc.getOrthodromicDistance() / Constants.NMToMetersConversion; } }