/** * Constructs a new LatLong with the given latitude and longitude values, measured in * microdegrees. * * @param latitudeE6 the latitude value in microdegrees. * @param longitudeE6 the longitude value in microdegrees. * @return the LatLong * @throws IllegalArgumentException if the latitudeE6 or longitudeE6 value is invalid. */ public static LatLong fromMicroDegrees(int latitudeE6, int longitudeE6) { return new LatLong(LatLongUtils.microdegreesToDegrees(latitudeE6), LatLongUtils.microdegreesToDegrees(longitudeE6)); }
/** * Returns the longitude value in microdegrees of this coordinate. * * @return the longitude value in microdegrees of this coordinate. */ public int getLongitudeE6() { return LatLongUtils.degreesToMicrodegrees(this.longitude); }
private static double[] computeTileEnlargement(double lat, int enlargementInMeter) { if (enlargementInMeter == 0) { return EPSILON_ZERO; } double[] epsilons = new double[2]; epsilons[0] = LatLongUtils.latitudeDistance(enlargementInMeter); epsilons[1] = LatLongUtils.longitudeDistance(enlargementInMeter, lat); return epsilons; }
/** * Constructs a new LatLong with the given latitude and longitude values, measured in * degrees. * * @param latitude the latitude value in degrees. * @param longitude the longitude value in degrees. * @throws IllegalArgumentException if the latitude or longitude value is invalid. */ public LatLong(double latitude, double longitude) throws IllegalArgumentException { this.latitude = LatLongUtils.validateLatitude(latitude); this.longitude = LatLongUtils.validateLongitude(longitude); }
@Override public void windowOpened(WindowEvent e) { final Model model = mapView.getModel(); model.init(preferencesFacade); if (model.mapViewPosition.getZoomLevel() == 0 || !boundingBox.contains(model.mapViewPosition.getCenter())) { byte zoomLevel = LatLongUtils.zoomForBounds(model.mapViewDimension.getDimension(), boundingBox, model.displayModel.getTileSize()); model.mapViewPosition.setMapPosition(new MapPosition(boundingBox.getCenterPoint(), zoomLevel)); } } });
@Test public void sphericalDistanceAndVincentyDistance_originToNearOfSriLanka_bothShouldBeNearlyTheSame() { // This is the origin of the WGS-84 reference system LatLong zeroZero = new LatLong(0d, 0d); // These coordinates are 1/4 Earth circumference from zero on the equator LatLong nearSriLanka = new LatLong(0d, 90d); // On the equator the result of the different distance calculation methods should be // about the same double spherical = LatLongUtils.sphericalDistance(zeroZero, nearSriLanka); double vincenty = LatLongUtils.vincentyDistance(zeroZero, nearSriLanka); assertEquals(spherical, vincenty, 1E-4); }
@Test(expected = IllegalArgumentException.class) public void validateLongitude_lowerThanMinValue_throwException() { LatLongUtils.validateLatitude(LatLongUtils.LONGITUDE_MIN - 1); } }
/** * Calculate the spherical distance from this LatLong to another. * <p/> * Use vincentyDistance for more accuracy but less performance. * * @param other The LatLong to calculate the distance to * @return the distance in meters as a double */ public double sphericalDistance(LatLong other) { return LatLongUtils.sphericalDistance(this, other); }
if (!LatLongUtils.isClosedWay(way.latLongs[0]) || !LatLongUtils.contains(way.latLongs[0], tapLatLong)) { continue;
private static void verifyInvalidLongitude(double longitude) { try { LatLongUtils.validateLongitude(longitude); Assert.fail("longitude: " + longitude); } catch (IllegalArgumentException e) { Assert.assertTrue(true); } }
public PolylineContainer(Way way, Tile upperLeft, Tile lowerRight) { this.coordinatesAbsolute = null; this.coordinatesRelativeToTile = null; this.tags = way.tags; this.upperLeft = upperLeft; this.lowerRight = lowerRight; this.layer = way.layer; this.way = way; this.isClosedWay = LatLongUtils.isClosedWay(way.latLongs[0]); if (this.way.labelPosition != null) { this.center = MercatorProjection.getPixelAbsolute(this.way.labelPosition, this.upperLeft.mapSize); } }
public synchronized boolean contains(LatLong tapLatLong) { return LatLongUtils.contains(latLongs, tapLatLong); }
/** * @param minLatitude the minimum latitude coordinate in degrees. * @param minLongitude the minimum longitude coordinate in degrees. * @param maxLatitude the maximum latitude coordinate in degrees. * @param maxLongitude the maximum longitude coordinate in degrees. * @throws IllegalArgumentException if a coordinate is invalid. */ public BoundingBox(double minLatitude, double minLongitude, double maxLatitude, double maxLongitude) { LatLongUtils.validateLatitude(minLatitude); LatLongUtils.validateLongitude(minLongitude); LatLongUtils.validateLatitude(maxLatitude); LatLongUtils.validateLongitude(maxLongitude); if (minLatitude > maxLatitude) { throw new IllegalArgumentException("invalid latitude range: " + minLatitude + ' ' + maxLatitude); } else if (minLongitude > maxLongitude) { throw new IllegalArgumentException("invalid longitude range: " + minLongitude + ' ' + maxLongitude); } this.minLatitude = minLatitude; this.minLongitude = minLongitude; this.maxLatitude = maxLatitude; this.maxLongitude = maxLongitude; }
@Test public void zoomForBoundsTest() { // TODO rewrite this unit tests to make it easier to understand Dimension[] dimensions = {new Dimension(200, 300), new Dimension(500, 400), new Dimension(1000, 600), new Dimension(3280, 1780), new Dimension(100, 200), new Dimension(500, 200)}; BoundingBox[] boundingBoxes = {new BoundingBox(12.2, 0, 34.3, 120), new BoundingBox(-30, 20, 30, 30), new BoundingBox(20.3, 100, 30.4, 120), new BoundingBox(4.4, 2, 4.5, 2.2), new BoundingBox(50.43, 12.23, 50.44, 12.24), new BoundingBox(50.43, 12, 50.44, 40)}; int[] tileSizes = {256, 512, 500, 620, 451}; byte[] results = {1, 0, 0, 0, 0, 2, 1, 1, 1, 1, 3, 2, 2, 2, 2, 10, 9, 9, 9, 9, 14, 13, 13, 13, 13, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 3, 2, 2, 1, 2, 5, 4, 4, 3, 4, 11, 10, 10, 10, 10, 15, 14, 14, 13, 14, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 3, 2, 2, 2, 2, 6, 5, 5, 4, 5, 12, 11, 11, 11, 11, 15, 14, 14, 14, 14, 5, 4, 4, 4, 4, 5, 4, 4, 3, 4, 5, 4, 4, 4, 4, 7, 6, 6, 6, 6, 14, 13, 13, 13, 13, 17, 16, 16, 16, 16, 7, 6, 6, 6, 6, 0, 0, 0, 0, 0, 2, 1, 1, 0, 1, 2, 1, 1, 1, 1, 9, 8, 8, 8, 8, 13, 12, 12, 12, 12, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 0, 1, 4, 3, 3, 3, 3, 11, 10, 10, 10, 10, 14, 13, 13, 12, 13, 4, 3, 3, 3, 3}; int i = 0; for (Dimension dimension : dimensions) { for (BoundingBox boundingBox : boundingBoxes) { for (int tileSize : tileSizes) { Assert.assertEquals(results[i], LatLongUtils.zoomForBounds(dimension, boundingBox, tileSize)); ++i; } } } } }
@Test(expected = IllegalArgumentException.class) public void validateLongitude_higherThanMaxValue_throwException() { LatLongUtils.validateLatitude(LatLongUtils.LONGITUDE_MAX + 1); }
@Test public void sphericalDistance_originToNorthPole_returnQuarterOfEarthEquatorCircumference() { // This is the origin of the WGS-84 reference system LatLong zeroZero = new LatLong(0d, 0d); // Calculating the distance between the north pole and the equator LatLong northPole = new LatLong(90d, 0d); double spherical = LatLongUtils.sphericalDistance(zeroZero, northPole); assertEquals(EARTH_EQUATOR_CIRCUMFERENCE / 4, spherical, 0d); }
@Test public void validateLongitude_legalValue_returnThatValue() { assertEquals(10d, LatLongUtils.validateLongitude(10d), 0d); }
public PolylineContainer(Way way, Tile upperLeft, Tile lowerRight) { this.coordinatesAbsolute = null; this.coordinatesRelativeToTile = null; this.tags = way.tags; this.upperLeft = upperLeft; this.lowerRight = lowerRight; this.layer = way.layer; this.way = way; this.isClosedWay = LatLongUtils.isClosedWay(way.latLongs[0]); if (this.way.labelPosition != null) { this.center = MercatorProjection.getPixelAbsolute(this.way.labelPosition, this.upperLeft.mapSize); } }
public synchronized boolean contains(LatLong tapLatLong) { return LatLongUtils.contains(latLongs, tapLatLong); }
private static Coordinate toCoordinate(int latitude, int longitude) { return new Coordinate(LatLongUtils.microdegreesToDegrees(longitude), LatLongUtils.microdegreesToDegrees(latitude)); }