Actually added sub modules this time
#story[778]
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package seng302;
|
||||
|
||||
/**
|
||||
* Created by cbt24 on 15/03/17.
|
||||
*/
|
||||
public class RaceMap {
|
||||
private double x1, x2, y1, y2;
|
||||
private int width, 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 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;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts GPS coordinates to coordinates for container
|
||||
*
|
||||
* @param lat GPS latitude
|
||||
* @param lon GPS longitude
|
||||
* @return GraphCoordinate (pair of doubles)
|
||||
* @see GraphCoordinate
|
||||
*/
|
||||
public GraphCoordinate convertGPS(double lat, double lon) {
|
||||
int difference = Math.abs(width - height);
|
||||
int size = width;
|
||||
if (width > height) {
|
||||
size = height;
|
||||
return new GraphCoordinate((int) ((size * (lon - x1) / (x2 - x1)) + difference / 2), (int) (size - (size * (lat - y1) / (y2 - y1))));
|
||||
} else {
|
||||
return new GraphCoordinate((int) (size * (lon - x1) / (x2 - x1)), (int) ((size - (size * (lat - y1) / (y2 - y1))) + difference / 2));
|
||||
}
|
||||
|
||||
//return new GraphCoordinate((int) (width * (lon - x1) / (x2 - x1)), (int) (height - (height * (lat - y1) / (y2 - y1))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the GPS Coordinate to GraphCoordinates
|
||||
*
|
||||
* @param coordinate GPSCoordinate representation of Latitude and Longitude.
|
||||
* @return GraphCoordinate that the GPS is coordinates are to be displayed on the map.
|
||||
* @see GraphCoordinate
|
||||
* @see GPSCoordinate
|
||||
*/
|
||||
public GraphCoordinate convertGPS(GPSCoordinate coordinate) {
|
||||
return convertGPS(coordinate.getLatitude(), coordinate.getLongitude());
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user