mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Added unit tests for Mercator projection class.
- changed its methods to static - add some documentation for its methods #story[928]
This commit is contained in:
@@ -9,36 +9,36 @@ package seng302.models.map;
|
||||
*/
|
||||
public class Boundary {
|
||||
|
||||
private double north, east, south, west;
|
||||
private double northLat, eastLng, southLat, westLng;
|
||||
|
||||
public Boundary(double north, double east, double south, double west) {
|
||||
this.north = north;
|
||||
this.east = east;
|
||||
this.south = south;
|
||||
this.west = west;
|
||||
public Boundary(double northLat, double eastLng, double southLat, double westLng) {
|
||||
this.northLat = northLat;
|
||||
this.eastLng = eastLng;
|
||||
this.southLat = southLat;
|
||||
this.westLng = westLng;
|
||||
}
|
||||
|
||||
public double getCentreLat() {
|
||||
return (north + south) / 2;
|
||||
return (northLat + southLat) / 2;
|
||||
}
|
||||
|
||||
public double getCentreLng() {
|
||||
return (east + west) / 2;
|
||||
return (eastLng + westLng) / 2;
|
||||
}
|
||||
|
||||
public double getNorth() {
|
||||
return north;
|
||||
public double getNorthLat() {
|
||||
return northLat;
|
||||
}
|
||||
|
||||
public double getEast() {
|
||||
return east;
|
||||
public double getEastLng() {
|
||||
return eastLng;
|
||||
}
|
||||
|
||||
public double getSouth() {
|
||||
return south;
|
||||
public double getSouthLat() {
|
||||
return southLat;
|
||||
}
|
||||
|
||||
public double getWest() {
|
||||
return west;
|
||||
public double getWestLng() {
|
||||
return westLng;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,21 +2,16 @@ package seng302.models.map;
|
||||
|
||||
public class MercatorProjection {
|
||||
|
||||
private double MERCATOR_RANGE = 256;
|
||||
private double pixelsPerLngDegree, pixelsPerLngRadian;
|
||||
|
||||
|
||||
public MercatorProjection() {
|
||||
pixelsPerLngDegree = MERCATOR_RANGE / 360.0;
|
||||
pixelsPerLngRadian = MERCATOR_RANGE / (2 * Math.PI);
|
||||
}
|
||||
private static final double MERCATOR_RANGE = 256;
|
||||
private static final double pixelsPerLngDegree = MERCATOR_RANGE / 360.0;
|
||||
private static final double pixelsPerLngRadian = MERCATOR_RANGE / (2 * Math.PI);
|
||||
|
||||
/**
|
||||
* A help function keeps the value in bound between -0.9999 and 0.9999.
|
||||
* @param value in bound value
|
||||
* @return the value in bound
|
||||
*/
|
||||
private double bound(double value) {
|
||||
private static double bound(double value) {
|
||||
return Math.min(Math.max(value, -0.9999), 0.9999);
|
||||
}
|
||||
|
||||
@@ -25,7 +20,7 @@ public class MercatorProjection {
|
||||
* @param geo MapGeo (lat, lng) location to be projected
|
||||
* @return the projection GeoPoint (x, y) on planar
|
||||
*/
|
||||
public MapPoint toMapPoint(MapGeo geo) {
|
||||
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);
|
||||
@@ -42,7 +37,7 @@ public class MercatorProjection {
|
||||
* @param point MapPoint (x, y) to be converted back
|
||||
* @return the original Geo location converted from the given projection point
|
||||
*/
|
||||
public MapGeo toMapGeo(MapPoint point) {
|
||||
public static MapGeo toMapGeo(MapPoint point) {
|
||||
MapPoint origin = new MapPoint(MERCATOR_RANGE / 2.0, MERCATOR_RANGE / 2.0);
|
||||
double lng = (point.getX() - origin.getX()) / pixelsPerLngDegree;
|
||||
double latRadians = (point.getY() - origin.getY()) / (-pixelsPerLngRadian);
|
||||
|
||||
Reference in New Issue
Block a user