I had accidentally broken the raceXML construction - fixed it.

Fixed a few issues where boat didn't have nextMark/previousMark times under certain circumstances.
LatestMessages wasn't actually notifying properly - fixed.
The various XML readers now treat a string constructor as containing file contents, not file name - this was how it was mostly already used.
Fixed some issues in RaceXMLReader, including where element.getChildNodes() was used instead of element.getElementsByName(...).
Boat: changes speed to a doubleProperty. Changed leg to a Property<Leg>.
Race.lastFps is now an IntegerProperty.
Added breaks to the case statements in VisualiserInput. Whoops.
ResizableRaceCanvas now handles drawing the race boundary. Tidied up code a bit.
Removed ResizableRaceMap.

Started refactoring Sparkline. Currently doesn't work.
This commit is contained in:
fjc40
2017-07-10 08:35:43 +12:00
parent abbbf70146
commit 7d3cf6ee80
38 changed files with 1414 additions and 775 deletions
@@ -1,40 +1,75 @@
package visualiser.model;
import shared.model.GPSCoordinate;
/**
* The base size of the map to be used for the
* {@link seng302.Model.ResizableRaceMap ResizableRaceMap} and
* {@link seng302.Model.ResizableRaceCanvas ResizableRaceCanvas}. It is used
* to convert {@link seng302.GPSCoordinate GPSCoordinate}s to relative
* {@link seng302.GraphCoordinate GraphCoordinate}s.
* {@link ResizableRaceMap} and
* {@link ResizableRaceCanvas}. It is used
* to convert {@link shared.model.GPSCoordinate}s to relative
* {@link GraphCoordinate}s.
*/
public class RaceMap {
private final double x1;
private final double x2;
private final double y1;
private final double y2;
private int width, height;
/**
* The longitude of the left side of the map.
*/
private final double longLeft;
/**
* The longitude of the right side of the map.
*/
private final double longRight;
/**
* The latitude of the top side of the map.
*/
private final double latTop;
/**
* The latitude of the bottom side of the map.
*/
private final double latBottom;
/**
* The width, in pixels, of the map.
*/
private int width;
/**
* The height, in pixels, of the map.
*/
private int height;
/**
* Constructor Method.
*
* @param x1 Longitude of the top left point.
* @param y1 Latitude of the top left point.
* @param x2 Longitude of the top right point.
* @param y2 Latitude of the top right point.
* @param latTop Latitude of the top left point.
* @param longLeft Longitude of the top left point.
* @param latBottom Latitude of the top right point.
* @param longRight Longitude of the top right point.
* @param width width that the Canvas the race is to be drawn on is.
* @param height height that the Canvas the race is to be drawn on is.
*/
public RaceMap(double y1, double x1, double y2, double x2, int height, int width) {
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
public RaceMap(double latTop, double longLeft, double latBottom, double longRight, int width, int height) {
//Long/lat edges.
this.longLeft = longLeft;
this.longRight = longRight;
this.latTop = latTop;
this.latBottom = latBottom;
//Pixel sizes.
this.width = width;
this.height = height;
}
/**
* Converts GPS coordinates to coordinates for container
* Converts GPS coordinates to coordinates for container.
* It is assumed that the provided GPSCoordinate will always be within the GPSCoordinate boundaries of the RaceMap.
*
* @param lat GPS latitude
* @param lon GPS longitude
@@ -42,20 +77,50 @@ public class RaceMap {
* @see GraphCoordinate
*/
private GraphCoordinate convertGPS(double lat, double lon) {
int difference = Math.abs(width - height);
int size = width;
//Calculate the width/height, in gps coordinates, of the map.
double longWidth = longRight - longLeft;
double latHeight = latBottom - latTop;
//Calculate the distance between the specified coordinate and the edge of the map.
double longDelta = lon - longLeft;
double latDelta = lat - latTop;
//Calculate the proportion along horizontally, from the left, the coordinate should be.
double longProportion = longDelta / longWidth;
//Calculate the proportion along vertically, from the top, the coordinate should be.
double latProportion = latDelta / latHeight;
//Check which pixel dimension of our map is smaller. We use this to ensure that any rendered stuff retains its correct aspect ratio, and that everything is visible on screen.
int smallerDimension = Math.min(width, height);
//Calculate the x and y pixel coordinates.
//We take the complement of latProportion to flip it.
int x = (int) (longProportion * smallerDimension);
int y = (int) ((1 - latProportion) * smallerDimension);
//Because we try to maintain the correct aspect ratio, we will end up with "spare" pixels along the larger dimension (e.g., width 800, height 600, 200 extra pixels along width).
int extraPixels = Math.abs(width - height);
//We therefore "center" the coordinates along this larger dimension, by adding half of the extra pixels.
if (width > height) {
size = height;
return new GraphCoordinate((int) ((size * (lon - x1) / (x2 - x1)) + difference / 2), (int) (size - (size * (lat - y1) / (y2 - y1))));
x += extraPixels / 2;
} else {
return new GraphCoordinate((int) (size * (lon - x1) / (x2 - x1)), (int) ((size - (size * (lat - y1) / (y2 - y1))) + difference / 2));
y += extraPixels / 2;
}
//return new GraphCoordinate((int) (width * (lon - x1) / (x2 - x1)), (int) (height - (height * (lat - y1) / (y2 - y1))));
//Finally, create the GraphCoordinate.
GraphCoordinate graphCoordinate = new GraphCoordinate(x, y);
return graphCoordinate;
}
/**
* Converts the GPS Coordinate to GraphCoordinates
* Converts the GPS Coordinate to GraphCoordinate.
* It is assumed that the provided GPSCoordinate will always be within the GPSCoordinate boundaries of the RaceMap.
*
* @param coordinate GPSCoordinate representation of Latitude and Longitude.
* @return GraphCoordinate that the GPS is coordinates are to be displayed on the map.
@@ -66,10 +131,18 @@ public class RaceMap {
return convertGPS(coordinate.getLatitude(), coordinate.getLongitude());
}
/**
* Sets the width, in pixels, of our RaceMap.
* @param width The new width, in pixels, of the RaceMap.
*/
public void setWidth(int width) {
this.width = width;
}
/**
* Sets the height, in pixels, of our RaceMap.
* @param height The new height, in pixels, of the RaceMap.
*/
public void setHeight(int height) {
this.height = height;
}