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.
122 lines
2.9 KiB
122 lines
2.9 KiB
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 String name; //nautical miles
|
|
private double distance;
|
|
private Marker startMarker;
|
|
private Marker endMarker;
|
|
private int legNumber;
|
|
|
|
/**
|
|
* Leg Initialiser
|
|
*
|
|
* @param name Name of the Leg
|
|
*/
|
|
public Leg(String name, Marker start, Marker end, int number) {
|
|
this.name = name;
|
|
this.startMarker = start;
|
|
this.endMarker = 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;
|
|
}
|
|
|
|
|
|
// public Leg createCopy() {
|
|
// Leg copy = new Leg(this.name, this.startMarker1, this.startMarker2,
|
|
// this.endMarker1, this.endMarker2, this.legNumber);
|
|
// return copy;
|
|
// }
|
|
|
|
/**
|
|
* Returns the leg number that the leg exists in the Race
|
|
*
|
|
* @return Returns the Leg
|
|
* @see Race
|
|
*/
|
|
public int getLegNumber() {
|
|
return legNumber;
|
|
}
|
|
|
|
|
|
public void setName(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public void setDistance(double distance) {
|
|
this.distance = distance;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public void setLegNumber(int legNumber) {
|
|
this.legNumber = 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();
|
|
//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());
|
|
return calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
|
|
|
|
}
|
|
|
|
}
|