@Override public String toString() { return String.valueOf(this.asDegrees()); }
/** * @param xAxis * The tile's x index * @param zoom * The zoom level * @return The corresponding longitude */ private Longitude tile2lon(final int xAxis, final int zoom) { final double longitude = xAxis / Math.pow(ZOOM_LEVEL_POWER, zoom) * FULL_ROTATION_DEGREES - HALF_ROTATION_DEGREES; return longitude >= LONGITUDE_BOUNDARY ? Longitude.MAXIMUM : longitude < -LONGITUDE_BOUNDARY ? Longitude.MINIMUM : Longitude.degrees(longitude); } }
/** * @param radians * A Longitude value in Radians * @return The built {@link Longitude} object using the Radians value */ public static Longitude radians(final double radians) { return dm7(Math.round(radians * DM7_PER_RADIAN)); }
@Test public void testAssertCompareAntiMeridian() { final Longitude oneEighty = Longitude.degrees(180); final Longitude minusOneEighty = Longitude.degrees(-180); final Longitude ninety = Longitude.degrees(90); Assert.assertTrue(oneEighty.isGreaterThan(minusOneEighty)); Assert.assertTrue(minusOneEighty.isLessThan(oneEighty)); Assert.assertFalse(minusOneEighty.isGreaterThanOrEqualTo(oneEighty)); Assert.assertTrue(oneEighty.isGreaterThanOrEqualTo(oneEighty)); Assert.assertTrue(oneEighty.isLessThanOrEqualTo(oneEighty)); Assert.assertTrue(oneEighty.isGreaterThan(ninety)); Assert.assertTrue(ninety.isLessThanOrEqualTo(oneEighty)); } }
if (left == null || longitude.isLessThan(left)) if (right == null || longitude.isGreaterThan(right))
protected Long nodeIdentifierForLocation(final Location location) { buildNodeSpatialIndexIfNecessary(); final Iterator<Node> nodes; final Rectangle bounds = location.bounds(); // Handle the anti-meridian case. +180 and -180 are identical in the Atlas, if this happens // to be the Longitude of the passed in Location, make sure to also check the equivalent // Location across the anti-meridian. if (location.getLongitude().equals(Longitude.ANTIMERIDIAN_EAST) || location.getLongitude().equals(Longitude.ANTIMERIDIAN_WEST)) { final Location locationAcrossAntiMeridian = new Location(location.getLatitude(), Longitude.dm7(-location.getLongitude().asDm7())); final Rectangle boundsAcrossAntiMeridian = locationAcrossAntiMeridian.bounds(); nodes = new MultiIterable<>(this.getNodeSpatialIndex().get(bounds), this.getNodeSpatialIndex().get(boundsAcrossAntiMeridian)).iterator(); } else { nodes = this.getNodeSpatialIndex().get(bounds).iterator(); } if (nodes.hasNext()) { return nodes.next().getIdentifier(); } return null; }
/** * @param bounds * Bounds to constrain the result * @return A random location within the bounds */ public static Location random(final Rectangle bounds) { final int latitude = RANDOM.ints((int) bounds.lowerLeft().getLatitude().asDm7(), (int) bounds.upperRight().getLatitude().asDm7()).iterator().next(); final int longitude = RANDOM.ints((int) bounds.lowerLeft().getLongitude().asDm7(), (int) bounds.upperRight().getLongitude().asDm7()).iterator().next(); return new Location(Latitude.dm7(latitude), Longitude.dm7(longitude)); }
/** * Test if this rectangle fully encloses a {@link Located} item * * @param item * The item to test * @return True if this rectangle contains a {@link Located} item */ public boolean fullyGeometricallyEncloses(final Located item) { final Rectangle bounds = item instanceof Rectangle ? (Rectangle) item : item.bounds(); return this.lowerLeft().getLatitude().isLessThanOrEqualTo(bounds.lowerLeft().getLatitude()) && this.lowerLeft().getLongitude() .isLessThanOrEqualTo(bounds.lowerLeft().getLongitude()) && this.upperRight().getLatitude() .isGreaterThanOrEqualTo(bounds.upperRight().getLatitude()) && this.upperRight().getLongitude() .isGreaterThanOrEqualTo(bounds.upperRight().getLongitude()); }
/** * @param that * The other {@link Longitude} to relate to * @return True if those two longitudes are closer to each other on the Antimeridian side than * on the Greenwich side. */ public boolean isCloserViaAntimeridianTo(final Longitude that) { // The difference in numerical longitude is larger than half a revolution return Math.abs(this.asDm7() - that.asDm7()) > REVOLUTION_DM7 / 2; }
/** * @param other * The other {@link Location} to test * @return True if this {@link Location} is east of the other {@link Location}. */ public boolean isEastOf(final Location other) { return this.getLongitude().isGreaterThan(other.getLongitude()); }
/** * @param other * The other {@link Location} to test * @return True if this {@link Location} is east or on the same {@link Longitude} as the other * {@link Location}. */ public boolean isEastOfOrOnTheSameLatitudeAs(final Location other) { return this.getLongitude().isGreaterThanOrEqualTo(other.getLongitude()); }
/** * @param dm7 * A longitude value in degree of magnitude 7 (dm7) * @return The built {@link Longitude} object using the dm7 value */ public static Longitude dm7(final long dm7) { // Here we allow dm7 = MAXIMUM_DM7, even though Longitude stops short of that number. The // value in that case will be picked up by the "assertDm7" function if (dm7 < MINIMUM_DM7 || dm7 > MAXIMUM_DM7) { throw new IllegalArgumentException("Cannot have a longitude of " + dm7 / DM7_PER_DEGREE + " degrees which is outside of " + MINIMUM_DM7 / DM7_PER_DEGREE + " degrees -> " + MAXIMUM_DM7 / DM7_PER_DEGREE + " degrees."); } // This constructor depends on the Angle Constructor, which allows for overriding the // "assertDm7" method. return new Longitude((int) dm7); }
final double p0X = this.start().getLongitude().asDegrees(); final double p0Y = this.start().getLatitude().asDegrees(); final double p1X = this.end().getLongitude().asDegrees(); final double p1Y = this.end().getLatitude().asDegrees(); final double p2X = that.start().getLongitude().asDegrees(); final double p2Y = that.start().getLatitude().asDegrees(); final double p3X = that.end().getLongitude().asDegrees(); final double p3Y = that.end().getLatitude().asDegrees(); Longitude.degrees(p0X + tValue * s1X));
@Override public boolean overlaps(final PolyLine other) { if (other instanceof Rectangle) { final Rectangle otherRectangle = (Rectangle) other; return !(otherRectangle.lowerLeft.getLongitude() .isGreaterThan(this.upperRight.getLongitude()) || otherRectangle.upperRight.getLongitude() .isLessThan(this.lowerLeft.getLongitude()) || otherRectangle.upperRight.getLatitude() .isLessThan(this.lowerLeft.getLatitude()) || otherRectangle.lowerLeft.getLatitude() .isGreaterThan(this.upperRight.getLatitude())); } else { return super.overlaps(other); } }
final double latitudeAsDm7 = shape.start().getLatitude().asDm7() + offsetDistance / shape.dotProductLength() * shape.latitudeSpan(); final double longitudeAsDm7 = shape.start().getLongitude().asDm7() + offsetDistance / shape.dotProductLength() * shape.longitudeSpan(); final Location snapped = new Location(Latitude.dm7(Math.round(latitudeAsDm7)), Longitude.dm7(Math.round(longitudeAsDm7))); return new SnappedLocation(origin, snapped, shape);
/** * @return A dm7 latitude and dm7 longitude concatenated in a long. The first 32 bits are for * the dm7 latitude, and the last 32 bits are for the dm7 longitude. */ public long asConcatenation() { long result = this.latitude.asDm7(); result <<= INT_SIZE; result |= this.longitude.asDm7() & INT_FULL_MASK_AS_LONG; return result; }
.isGreaterThan(newUpperRight.getLatitude()); final boolean tooShortWidth = newLowerLeft.getLongitude() .isGreaterThan(newUpperRight.getLongitude()); if (tooShortHeight && tooShortWidth)
@Test public void testMidPoint() { final Location location1 = new Location(Latitude.degrees(52.205), Longitude.degrees(0.119)); final Location location2 = new Location(Latitude.degrees(48.857), Longitude.degrees(2.351)); final Location midpoint = location1.midPoint(location2); Assert.assertEquals(50.5363269, midpoint.getLatitude().asDegrees(), DELTA); Assert.assertEquals(1.2746141, midpoint.getLongitude().asDegrees(), DELTA); }
@Override public Location backwardConvert(final Coordinate coordinate) { return new Location(Latitude.degrees(coordinate.y), Longitude.degrees(coordinate.x)); }