mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +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;
|
package seng302.server.simulator;
|
||||||
|
|
||||||
import javafx.geometry.Pos;
|
|
||||||
import seng302.server.simulator.mark.Mark;
|
|
||||||
import seng302.server.simulator.mark.Position;
|
import seng302.server.simulator.mark.Position;
|
||||||
|
|
||||||
public class GeoUtility {
|
public class GeoUtility {
|
||||||
|
|
||||||
private static double EARTH_RADIUS = 6378.137;
|
private static double EARTH_RADIUS = 6378.137;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the euclidean distance between two markers on the canvas using xy coordinates
|
* 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
|
* @param p2 second geographical position
|
||||||
* @return the distance in meter between two points in meters
|
* @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 dLat = Math.toRadians(p2.getLat() - p1.getLat());
|
||||||
double dLon = Math.toRadians(p2.getLng() - p1.getLng());
|
double dLon = Math.toRadians(p2.getLng() - p1.getLng());
|
||||||
@@ -53,6 +52,7 @@ public class GeoUtility {
|
|||||||
/**
|
/**
|
||||||
* Given an existing point in lat/lng, distance in (in meter) and bearing
|
* Given an existing point in lat/lng, distance in (in meter) and bearing
|
||||||
* (in degrees), calculates the new lat/lng.
|
* (in degrees), calculates the new lat/lng.
|
||||||
|
*
|
||||||
* @param origin the original position within lat / lng
|
* @param origin the original position within lat / lng
|
||||||
* @param bearing the bearing in degree, from original position to the new position
|
* @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
|
* @param distance the distance in meter, from original position to the new position
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ public class Corner {
|
|||||||
private RoundingType roundingType;
|
private RoundingType roundingType;
|
||||||
private int zoneSize; // size of the zone around a mark in boat-lengths.
|
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) {
|
public Corner(int seqID, CompoundMark compoundMark, RoundingType roundingType, int zoneSize) {
|
||||||
this.seqID = seqID;
|
this.seqID = seqID;
|
||||||
this.compoundMark = compoundMark;
|
this.compoundMark = compoundMark;
|
||||||
@@ -56,4 +60,30 @@ public class Corner {
|
|||||||
public void setZoneSize(int zoneSize) {
|
public void setZoneSize(int zoneSize) {
|
||||||
this.zoneSize = 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
|
* An abstract class to represent general marks
|
||||||
* Created by Haoming Yin (hyi25) on 17/3/17.
|
* Created by Haoming Yin (hyi25) on 17/3/17.
|
||||||
*/
|
*/
|
||||||
public class Mark {
|
public class Mark extends Position {
|
||||||
|
|
||||||
private int seqID;
|
private int seqID;
|
||||||
private String name;
|
private String name;
|
||||||
private double lat;
|
private int sourceID;
|
||||||
private double lng;
|
|
||||||
//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.name = name;
|
||||||
this.lat = lat;
|
this.sourceID = sourceID;
|
||||||
this.lng = lng;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,7 +22,7 @@ public class Mark {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
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() {
|
public int getSeqID() {
|
||||||
@@ -43,20 +41,12 @@ public class Mark {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getLat() {
|
public int getSourceID() {
|
||||||
return lat;
|
return sourceID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLat(double lat) {
|
public void setSourceID(int sourceID) {
|
||||||
this.lat = lat;
|
this.sourceID = sourceID;
|
||||||
}
|
|
||||||
|
|
||||||
public double getLng() {
|
|
||||||
return lng;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLng(double lng) {
|
|
||||||
this.lng = lng;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
// TODO: should handle error / invalid file gracefully
|
||||||
public List<Corner> getCourse() {
|
protected List<Corner> getCourse() {
|
||||||
compoundMarksMap = getCompoundMarks(doc.getDocumentElement());
|
compoundMarksMap = getCompoundMarks(doc.getDocumentElement());
|
||||||
List<Corner> corners = new ArrayList<>();
|
List<Corner> corners = new ArrayList<>();
|
||||||
NodeList cMarksSequence = doc.getElementsByTagName("Corner");
|
NodeList cMarksSequence = doc.getElementsByTagName("Corner");
|
||||||
@@ -104,8 +104,9 @@ public class CourseParser extends FileParser {
|
|||||||
String name = e.getAttribute("Name");
|
String name = e.getAttribute("Name");
|
||||||
Double lat = Double.valueOf(e.getAttribute("TargetLat"));
|
Double lat = Double.valueOf(e.getAttribute("TargetLat"));
|
||||||
Double lng = Double.valueOf(e.getAttribute("TargetLng"));
|
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);
|
mark.setSeqID(seqId);
|
||||||
|
|
||||||
return mark;
|
return mark;
|
||||||
|
|||||||
Reference in New Issue
Block a user