diff --git a/src/main/java/seng302/server/simulator/GeoUtility.java b/src/main/java/seng302/server/simulator/GeoUtility.java index a93be4b3..288e0ee1 100644 --- a/src/main/java/seng302/server/simulator/GeoUtility.java +++ b/src/main/java/seng302/server/simulator/GeoUtility.java @@ -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 */ diff --git a/src/main/java/seng302/server/simulator/mark/Corner.java b/src/main/java/seng302/server/simulator/mark/Corner.java index 70f231b5..136212f2 100644 --- a/src/main/java/seng302/server/simulator/mark/Corner.java +++ b/src/main/java/seng302/server/simulator/mark/Corner.java @@ -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; + } } diff --git a/src/main/java/seng302/server/simulator/mark/Mark.java b/src/main/java/seng302/server/simulator/mark/Mark.java index 0dd2d761..41f00bb6 100644 --- a/src/main/java/seng302/server/simulator/mark/Mark.java +++ b/src/main/java/seng302/server/simulator/mark/Mark.java @@ -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; } } diff --git a/src/main/java/seng302/server/simulator/mark/Position.java b/src/main/java/seng302/server/simulator/mark/Position.java new file mode 100644 index 00000000..74200e9d --- /dev/null +++ b/src/main/java/seng302/server/simulator/mark/Position.java @@ -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; + } +} diff --git a/src/main/java/seng302/server/simulator/parsers/CourseParser.java b/src/main/java/seng302/server/simulator/parsers/CourseParser.java index d055f88e..f7be46cd 100644 --- a/src/main/java/seng302/server/simulator/parsers/CourseParser.java +++ b/src/main/java/seng302/server/simulator/parsers/CourseParser.java @@ -29,7 +29,7 @@ public class CourseParser extends FileParser { } // TODO: should handle error / invalid file gracefully - public List getCourse() { + protected List getCourse() { compoundMarksMap = getCompoundMarks(doc.getDocumentElement()); List 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;