You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.6 KiB
104 lines
2.6 KiB
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 CompoundMarker startCompoundMarker;
|
|
private CompoundMarker endCompoundMarker;
|
|
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, CompoundMarker start, CompoundMarker end, int number) {
|
|
this.name = name;
|
|
this.startCompoundMarker = start;
|
|
this.endCompoundMarker = 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 CompoundMarker getStartCompoundMarker() {
|
|
return startCompoundMarker;
|
|
}
|
|
|
|
public void setStartCompoundMarker(CompoundMarker startCompoundMarker) {
|
|
this.startCompoundMarker = startCompoundMarker;
|
|
}
|
|
|
|
public CompoundMarker getEndCompoundMarker() {
|
|
return endCompoundMarker;
|
|
}
|
|
|
|
public void setEndCompoundMarker(CompoundMarker endCompoundMarker) {
|
|
this.endCompoundMarker = endCompoundMarker;
|
|
}
|
|
|
|
/**
|
|
* 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.startCompoundMarker.getAverageGPSCoordinate();
|
|
GPSCoordinate endMarker = this.endCompoundMarker.getAverageGPSCoordinate();
|
|
calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude());
|
|
calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude());
|
|
this.distance = calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
|
|
}
|
|
|
|
|
|
}
|