mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Added Position class to better use GeoUtility.
- mark now inherit from Position #story[828]
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
package seng302.server.simulator;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import seng302.server.simulator.mark.Mark;
|
||||
import seng302.server.simulator.mark.Position;
|
||||
|
||||
public class GeoUtility {
|
||||
|
||||
private static double EARTH_RADIUS = 6378.137;
|
||||
|
||||
/**
|
||||
* Calculates the euclidean distance between two markers on the canvas using xy coordinates
|
||||
*
|
||||
@@ -14,7 +13,7 @@ public class GeoUtility {
|
||||
* @param p2 second geographical position
|
||||
* @return the distance in meter between two points in meters
|
||||
*/
|
||||
public static Double calculateMarkerDistance(Position p1, Position p2) {
|
||||
public static Double getDistance(Position p1, Position p2) {
|
||||
|
||||
double dLat = Math.toRadians(p2.getLat() - p1.getLat());
|
||||
double dLon = Math.toRadians(p2.getLng() - p1.getLng());
|
||||
@@ -35,7 +34,7 @@ public class GeoUtility {
|
||||
* @param p1 the first geographical position, start point
|
||||
* @param p2 the second geographical position, end point
|
||||
* @return the bearing in degree from p1 to p2, value range (0 ~ 360 deg.).
|
||||
* vertical up is 0 deg. horizontal right is 90 deg.
|
||||
* vertical up is 0 deg. horizontal right is 90 deg.
|
||||
*/
|
||||
public static Double getBearing(Position p1, Position p2) {
|
||||
|
||||
@@ -53,8 +52,9 @@ public class GeoUtility {
|
||||
/**
|
||||
* Given an existing point in lat/lng, distance in (in meter) and bearing
|
||||
* (in degrees), calculates the new lat/lng.
|
||||
* @param origin the original position within lat / lng
|
||||
* @param bearing the bearing in degree, from original position to the new position
|
||||
*
|
||||
* @param origin the original position within lat / lng
|
||||
* @param bearing the bearing in degree, from original position to the new position
|
||||
* @param distance the distance in meter, from original position to the new position
|
||||
* @return the new position
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,10 @@ public class Corner {
|
||||
private RoundingType roundingType;
|
||||
private int zoneSize; // size of the zone around a mark in boat-lengths.
|
||||
|
||||
// TODO: this shouldn't be used in the future!!!!
|
||||
private double bearingToNextCorner, distanceToNextCorner;
|
||||
private Corner nextCorner;
|
||||
|
||||
public Corner(int seqID, CompoundMark compoundMark, RoundingType roundingType, int zoneSize) {
|
||||
this.seqID = seqID;
|
||||
this.compoundMark = compoundMark;
|
||||
@@ -56,4 +60,30 @@ public class Corner {
|
||||
public void setZoneSize(int zoneSize) {
|
||||
this.zoneSize = zoneSize;
|
||||
}
|
||||
|
||||
|
||||
// TODO: next six setters & getters shouldn't be used in the future.
|
||||
public double getBearingToNextCorner() {
|
||||
return bearingToNextCorner;
|
||||
}
|
||||
|
||||
public void setBearingToNextCorner(double bearingToNextCorner) {
|
||||
this.bearingToNextCorner = bearingToNextCorner;
|
||||
}
|
||||
|
||||
public double getDistanceToNextCorner() {
|
||||
return distanceToNextCorner;
|
||||
}
|
||||
|
||||
public void setDistanceToNextCorner(double distanceToNextCorner) {
|
||||
this.distanceToNextCorner = distanceToNextCorner;
|
||||
}
|
||||
|
||||
public Corner getNextCorner() {
|
||||
return nextCorner;
|
||||
}
|
||||
|
||||
public void setNextCorner(Corner nextCorner) {
|
||||
this.nextCorner = nextCorner;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,16 @@ package seng302.server.simulator.mark;
|
||||
* An abstract class to represent general marks
|
||||
* Created by Haoming Yin (hyi25) on 17/3/17.
|
||||
*/
|
||||
public class Mark {
|
||||
public class Mark extends Position {
|
||||
|
||||
private int seqID;
|
||||
private String name;
|
||||
private double lat;
|
||||
private double lng;
|
||||
//private int sourceID;
|
||||
private int sourceID;
|
||||
|
||||
public Mark(String name, double lat, double lng) {
|
||||
public Mark(String name, double lat, double lng, int sourceID) {
|
||||
super(lat, lng);
|
||||
this.name = name;
|
||||
this.lat = lat;
|
||||
this.lng = lng;
|
||||
this.sourceID = sourceID;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,7 +22,7 @@ public class Mark {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Mark: %d (%s), lat: %f, lng: %f", seqID, name, lat, lng);
|
||||
return String.format("Mark%d: %s, source: %d, lat: %f, lng: %f", seqID, name, sourceID, lat, lng);
|
||||
}
|
||||
|
||||
public int getSeqID() {
|
||||
@@ -43,20 +41,12 @@ public class Mark {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public double getLat() {
|
||||
return lat;
|
||||
public int getSourceID() {
|
||||
return sourceID;
|
||||
}
|
||||
|
||||
public void setLat(double lat) {
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
public double getLng() {
|
||||
return lng;
|
||||
}
|
||||
|
||||
public void setLng(double lng) {
|
||||
this.lng = lng;
|
||||
public void setSourceID(int sourceID) {
|
||||
this.sourceID = sourceID;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package seng302.server.simulator.mark;
|
||||
|
||||
public class Position {
|
||||
|
||||
double lat, lng;
|
||||
|
||||
public Position(double lat, double lng) {
|
||||
this.lat = lat;
|
||||
this.lng = lng;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("Position at lat:%f lng:%f.", lat, lng);
|
||||
}
|
||||
|
||||
public double getLat() {
|
||||
return lat;
|
||||
}
|
||||
|
||||
public void setLat(double lat) {
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
public double getLng() {
|
||||
return lng;
|
||||
}
|
||||
|
||||
public void setLng(double lng) {
|
||||
this.lng = lng;
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class CourseParser extends FileParser {
|
||||
}
|
||||
|
||||
// TODO: should handle error / invalid file gracefully
|
||||
public List<Corner> getCourse() {
|
||||
protected List<Corner> getCourse() {
|
||||
compoundMarksMap = getCompoundMarks(doc.getDocumentElement());
|
||||
List<Corner> corners = new ArrayList<>();
|
||||
NodeList cMarksSequence = doc.getElementsByTagName("Corner");
|
||||
@@ -104,8 +104,9 @@ public class CourseParser extends FileParser {
|
||||
String name = e.getAttribute("Name");
|
||||
Double lat = Double.valueOf(e.getAttribute("TargetLat"));
|
||||
Double lng = Double.valueOf(e.getAttribute("TargetLng"));
|
||||
Integer sourceId = Integer.valueOf(e.getAttribute("SourceID"));
|
||||
|
||||
Mark mark = new Mark(name, lat, lng);
|
||||
Mark mark = new Mark(name, lat, lng, sourceId);
|
||||
mark.setSeqID(seqId);
|
||||
|
||||
return mark;
|
||||
|
||||
Reference in New Issue
Block a user