mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merge remote-tracking branch 'origin/develop' into Story62_Reading_Keystrokes
This commit is contained in:
@@ -22,9 +22,7 @@ import javafx.scene.layout.Pane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.text.Text;
|
||||
import seng302.fxObjects.BoatAnnotations;
|
||||
import seng302.fxObjects.BoatGroup;
|
||||
import seng302.fxObjects.Wake;
|
||||
import seng302.models.Colors;
|
||||
import seng302.models.Yacht;
|
||||
import seng302.models.mark.GateMark;
|
||||
@@ -39,14 +37,8 @@ import seng302.models.stream.XMLParser;
|
||||
import seng302.models.stream.XMLParser.RaceXMLObject.Limit;
|
||||
import seng302.models.stream.XMLParser.RaceXMLObject.Participant;
|
||||
import seng302.models.stream.packets.BoatPositionPacket;
|
||||
import seng302.server.simulator.GeoUtility;
|
||||
import seng302.server.simulator.mark.Position;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
import seng302.utilities.GeoPoint;
|
||||
import seng302.utilities.GeoUtility;
|
||||
|
||||
/**
|
||||
* Created by ptg19 on 15/03/17.
|
||||
@@ -210,8 +202,8 @@ public class CanvasController {
|
||||
double bearingFromTopLeftToOrigin = Math
|
||||
.toDegrees(Math.atan2(-topLeftPoint.getX(), topLeftPoint.getY()));
|
||||
// the top left extreme
|
||||
Position topLeftPos = new Position(maxLatPoint.getLatitude(), minLonPoint.getLongitude());
|
||||
Position originPos = GeoUtility
|
||||
GeoPoint topLeftPos = new GeoPoint(maxLatPoint.getLatitude(), minLonPoint.getLongitude());
|
||||
GeoPoint originPos = GeoUtility
|
||||
.getGeoCoordinate(topLeftPos, bearingFromTopLeftToOrigin, distanceFromTopLeftToOrigin);
|
||||
|
||||
// distance from origin corner to bottom right corner of the panel
|
||||
@@ -220,7 +212,7 @@ public class CanvasController {
|
||||
.pow(PANEL_WIDTH * metersPerPixelX, 2));
|
||||
double bearingFromOriginToBottomRight = Math
|
||||
.toDegrees(Math.atan2(PANEL_WIDTH, -PANEL_HEIGHT));
|
||||
Position bottomRightPos = GeoUtility
|
||||
GeoPoint bottomRightPos = GeoUtility
|
||||
.getGeoCoordinate(originPos, bearingFromOriginToBottomRight,
|
||||
distanceFromOriginToBottomRight);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import javafx.stage.Stage;
|
||||
import javafx.stage.StageStyle;
|
||||
import javafx.util.Duration;
|
||||
import javafx.util.StringConverter;
|
||||
import seng302.GeometryUtils;
|
||||
import seng302.utilities.GeometryUtils;
|
||||
import seng302.controllers.annotations.Annotation;
|
||||
import seng302.controllers.annotations.ImportantAnnotationController;
|
||||
import seng302.controllers.annotations.ImportantAnnotationDelegate;
|
||||
|
||||
@@ -1,26 +1,22 @@
|
||||
package seng302.fxObjects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import javafx.event.EventHandler;
|
||||
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.CacheHint;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Line;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import seng302.models.Yacht;
|
||||
import seng302.GeometryUtils;
|
||||
import seng302.utilities.GeometryUtils;
|
||||
import seng302.controllers.CanvasController;
|
||||
import seng302.models.mark.GateMark;
|
||||
import seng302.models.mark.Mark;
|
||||
import seng302.models.mark.SingleMark;
|
||||
import seng302.models.stream.StreamParser;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
/**
|
||||
* BoatGroup is a javafx group that by default contains a graphical objects for representing a 2
|
||||
* dimensional boat. It contains a single polygon for the boat, a group of lines to show it's path,
|
||||
|
||||
@@ -12,7 +12,6 @@ import seng302.models.mark.GateMark;
|
||||
import seng302.models.mark.Mark;
|
||||
import seng302.models.mark.MarkType;
|
||||
import seng302.models.mark.SingleMark;
|
||||
import seng302.GeometryUtils;
|
||||
|
||||
/**
|
||||
* Grouping of javaFX objects needed to represent a Mark on screen.
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package seng302.models.map;
|
||||
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.image.Image;
|
||||
import seng302.utilities.GeoPoint;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.net.URL;
|
||||
@@ -65,10 +67,10 @@ public class CanvasMap {
|
||||
|
||||
private MapSize getMapSize(int zoom, Boundary boundary) {
|
||||
double scale = Math.pow(2, zoom);
|
||||
MapGeo geoSW = new MapGeo(boundary.getSouthLat(), boundary.getWestLng());
|
||||
MapGeo geoNE = new MapGeo(boundary.getNorthLat(), boundary.getEastLng());
|
||||
MapPoint pointSW = MercatorProjection.toMapPoint(geoSW);
|
||||
MapPoint pointNE = MercatorProjection.toMapPoint(geoNE);
|
||||
GeoPoint geoSW = new GeoPoint(boundary.getSouthLat(), boundary.getWestLng());
|
||||
GeoPoint geoNE = new GeoPoint(boundary.getNorthLat(), boundary.getEastLng());
|
||||
Point2D pointSW = MercatorProjection.toMapPoint(geoSW);
|
||||
Point2D pointNE = MercatorProjection.toMapPoint(geoNE);
|
||||
return new MapSize(Math.abs(pointNE.getX() - pointSW.getX()) * scale,
|
||||
Math.abs(pointNE.getY() - pointSW.getY()) * scale);
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package seng302.models.map;
|
||||
|
||||
/**
|
||||
* A class represent Geo location (latitude, longitude).
|
||||
* Created by Haoming on 15/5/2017
|
||||
*/
|
||||
class MapGeo {
|
||||
|
||||
private double lat, lng;
|
||||
|
||||
MapGeo(double lat, double lng) {
|
||||
this.lat = lat;
|
||||
this.lng = lng;
|
||||
}
|
||||
|
||||
double getLat() {
|
||||
return lat;
|
||||
}
|
||||
|
||||
void setLat(double lat) {
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
double getLng() {
|
||||
return lng;
|
||||
}
|
||||
|
||||
void setLng(double lng) {
|
||||
this.lng = lng;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package seng302.models.map;
|
||||
|
||||
/**
|
||||
* A class represent euclidean planar point (x, y)
|
||||
* Created by Haoming on 15/5/2017
|
||||
*/
|
||||
class MapPoint {
|
||||
|
||||
private double x, y;
|
||||
|
||||
MapPoint(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
void setX(double x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
void setY(double y) {
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package seng302.models.map;
|
||||
|
||||
import javafx.geometry.Point2D;
|
||||
import seng302.utilities.GeoPoint;
|
||||
|
||||
/**
|
||||
* An utility class useful to convert between Geo locations and Mercator projection
|
||||
* planar coordinates.
|
||||
@@ -22,31 +25,31 @@ public class MercatorProjection {
|
||||
|
||||
/**
|
||||
* Projects a Geo Location (lat, lng) on a planar
|
||||
* @param geo MapGeo (lat, lng) location to be projected
|
||||
* @return the projection GeoPoint (x, y) on planar
|
||||
* @param geo GeoPoint (lat, lng) location to be projected
|
||||
* @return the projection Point2D (x, y) on planar
|
||||
*/
|
||||
public static MapPoint toMapPoint(MapGeo geo) {
|
||||
MapPoint point = new MapPoint(0, 0);
|
||||
MapPoint origin = new MapPoint(MERCATOR_RANGE / 2.0, MERCATOR_RANGE / 2.0);
|
||||
point.setX(origin.getX() + geo.getLng() * pixelsPerLngDegree);
|
||||
public static Point2D toMapPoint(GeoPoint geo) {
|
||||
double x, y;
|
||||
Point2D origin = new Point2D(MERCATOR_RANGE / 2.0, MERCATOR_RANGE / 2.0);
|
||||
x = (origin.getX() + geo.getLng() * pixelsPerLngDegree);
|
||||
|
||||
// NOTE(appleton): Truncating to 0.9999 effectively limits latitude to
|
||||
// 89.189. This is about a third of a tile past the edge of the world tile.
|
||||
double sinY = bound(Math.sin(Math.toRadians(geo.getLat())));
|
||||
point.setY(origin.getY() + 0.5 * Math.log((1 + sinY) / (1 - sinY)) * (-pixelsPerLngRadian));
|
||||
return point;
|
||||
y = origin.getY() + 0.5 * Math.log((1 + sinY) / (1 - sinY)) * (-pixelsPerLngRadian);
|
||||
return new Point2D(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the planar projection (x, y) back to Geo Location (lat, lng)
|
||||
* @param point MapPoint (x, y) to be converted back
|
||||
* @param point Point2D (x, y) to be converted back
|
||||
* @return the original Geo location converted from the given projection point
|
||||
*/
|
||||
public static MapGeo toMapGeo(MapPoint point) {
|
||||
MapPoint origin = new MapPoint(MERCATOR_RANGE / 2.0, MERCATOR_RANGE / 2.0);
|
||||
public static GeoPoint toMapGeo(Point2D point) {
|
||||
Point2D origin = new Point2D(MERCATOR_RANGE / 2.0, MERCATOR_RANGE / 2.0);
|
||||
double lng = (point.getX() - origin.getX()) / pixelsPerLngDegree;
|
||||
double latRadians = (point.getY() - origin.getY()) / (-pixelsPerLngRadian);
|
||||
double lat = Math.toDegrees(2 * Math.atan(Math.exp(latRadians)) - Math.PI / 2.0);
|
||||
return new MapGeo(lat, lng);
|
||||
return new GeoPoint(lat, lng);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package seng302.server.simulator;
|
||||
|
||||
import seng302.server.simulator.mark.Corner;
|
||||
import seng302.server.simulator.mark.Position;
|
||||
import seng302.utilities.GeoPoint;
|
||||
import seng302.utilities.GeoUtility;
|
||||
|
||||
public class Boat {
|
||||
|
||||
@@ -29,8 +30,8 @@ public class Boat {
|
||||
*/
|
||||
public void move(double heading, double duration) {
|
||||
Double distance = speed * duration / 1000000; // convert mm to meter
|
||||
Position originPos = new Position(lat, lng);
|
||||
Position newPos = GeoUtility.getGeoCoordinate(originPos, heading, distance);
|
||||
GeoPoint originPos = new GeoPoint(lat, lng);
|
||||
GeoPoint newPos = GeoUtility.getGeoCoordinate(originPos, heading, distance);
|
||||
this.lat = newPos.getLat();
|
||||
this.lng = newPos.getLng();
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@ package seng302.server.simulator;
|
||||
|
||||
import seng302.server.simulator.mark.Corner;
|
||||
import seng302.server.simulator.mark.Mark;
|
||||
import seng302.server.simulator.mark.Position;
|
||||
import seng302.server.simulator.parsers.RaceParser;
|
||||
import seng302.utilities.GeoPoint;
|
||||
import seng302.utilities.GeoUtility;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
@@ -77,8 +78,8 @@ public class Simulator extends Observable implements Runnable {
|
||||
|
||||
boat.move(boat.getLastPassedCorner().getBearingToNextCorner(), duration);
|
||||
|
||||
Position boatPos = new Position(boat.getLat(), boat.getLng());
|
||||
Position lastMarkPos = boat.getLastPassedCorner().getCompoundMark().getMark1();
|
||||
GeoPoint boatPos = new GeoPoint(boat.getLat(), boat.getLng());
|
||||
GeoPoint lastMarkPos = boat.getLastPassedCorner().getCompoundMark().getMark1();
|
||||
|
||||
double distanceFromLastMark = GeoUtility.getDistance(boatPos, lastMarkPos);
|
||||
// if a boat passes its heading mark
|
||||
@@ -94,13 +95,13 @@ public class Simulator extends Observable implements Runnable {
|
||||
}
|
||||
|
||||
// move compensate distance for the mark just passed
|
||||
Position pos = GeoUtility.getGeoCoordinate(
|
||||
GeoPoint pos = GeoUtility.getGeoCoordinate(
|
||||
boat.getLastPassedCorner().getCompoundMark().getMark1(),
|
||||
boat.getLastPassedCorner().getBearingToNextCorner(),
|
||||
compensateDistance);
|
||||
boat.setLat(pos.getLat());
|
||||
boat.setLng(pos.getLng());
|
||||
distanceFromLastMark = GeoUtility.getDistance(new Position(boat.getLat(), boat.getLng()),
|
||||
distanceFromLastMark = GeoUtility.getDistance(new GeoPoint(boat.getLat(), boat.getLng()),
|
||||
boat.getLastPassedCorner().getCompoundMark().getMark1());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package seng302.server.simulator.mark;
|
||||
|
||||
import seng302.utilities.GeoPoint;
|
||||
|
||||
/**
|
||||
* An abstract class to represent general marks
|
||||
* Created by Haoming Yin (hyi25) on 17/3/17.
|
||||
*/
|
||||
public class Mark extends Position {
|
||||
public class Mark extends GeoPoint {
|
||||
|
||||
private int seqID;
|
||||
private String name;
|
||||
@@ -22,7 +24,7 @@ public class Mark extends Position {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Mark%d: %s, source: %d, lat: %f, lng: %f", seqID, name, sourceID, lat, lng);
|
||||
return String.format("Mark%d: %s, source: %d, lat: %f, lng: %f", seqID, name, sourceID, getLat(), getLng());
|
||||
}
|
||||
|
||||
public int getSeqID() {
|
||||
|
||||
+7
-7
@@ -1,18 +1,18 @@
|
||||
package seng302.server.simulator.mark;
|
||||
package seng302.utilities;
|
||||
|
||||
public class Position {
|
||||
/**
|
||||
* A class represent Geo location (latitude, longitude).
|
||||
* Created by Haoming on 15/5/2017
|
||||
*/
|
||||
public class GeoPoint {
|
||||
|
||||
double lat, lng;
|
||||
|
||||
public Position(double lat, double lng) {
|
||||
public GeoPoint(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;
|
||||
}
|
||||
+5
-7
@@ -1,6 +1,4 @@
|
||||
package seng302.server.simulator;
|
||||
|
||||
import seng302.server.simulator.mark.Position;
|
||||
package seng302.utilities;
|
||||
|
||||
public class GeoUtility {
|
||||
|
||||
@@ -13,7 +11,7 @@ public class GeoUtility {
|
||||
* @param p2 second geographical position
|
||||
* @return the distance in meter between two points in meters
|
||||
*/
|
||||
public static Double getDistance(Position p1, Position p2) {
|
||||
public static Double getDistance(GeoPoint p1, GeoPoint p2) {
|
||||
|
||||
double dLat = Math.toRadians(p2.getLat() - p1.getLat());
|
||||
double dLon = Math.toRadians(p2.getLng() - p1.getLng());
|
||||
@@ -42,7 +40,7 @@ public class GeoUtility {
|
||||
* (≈ Baghdad) to 35°N,135°E (≈ Osaka), you would start on a heading of 60°
|
||||
* and end up on a heading of 120°
|
||||
*/
|
||||
public static Double getBearing(Position p1, Position p2) {
|
||||
public static Double getBearing(GeoPoint p1, GeoPoint p2) {
|
||||
|
||||
double dLon = Math.toRadians(p2.getLng() - p1.getLng());
|
||||
|
||||
@@ -64,7 +62,7 @@ public class GeoUtility {
|
||||
* @param distance the distance in meter, from original position to the new position
|
||||
* @return the new position
|
||||
*/
|
||||
public static Position getGeoCoordinate(Position origin, Double bearing, Double distance) {
|
||||
public static GeoPoint getGeoCoordinate(GeoPoint origin, Double bearing, Double distance) {
|
||||
double b = Math.toRadians(bearing); // bearing to radians
|
||||
double d = distance / 1000.0; // distance to km
|
||||
|
||||
@@ -77,6 +75,6 @@ public class GeoUtility {
|
||||
+ Math.atan2(Math.sin(b) * Math.sin(d / EARTH_RADIUS) * Math.cos(originLat),
|
||||
Math.cos(d / EARTH_RADIUS) - Math.sin(originLat) * Math.sin(endLat));
|
||||
|
||||
return new Position(Math.toDegrees(endLat), Math.toDegrees(endLng));
|
||||
return new GeoPoint(Math.toDegrees(endLat), Math.toDegrees(endLng));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package seng302;
|
||||
package seng302.utilities;
|
||||
|
||||
import javafx.geometry.Point2D;
|
||||
|
||||
Reference in New Issue
Block a user