/** * @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; }
/** * @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; }
protected Point2D asAwtPoint() { return new Point((int) getLongitude().asDm7(), (int) getLatitude().asDm7()); } }
/** * @return The surface of this polygon. Not valid if the polygon self-intersects, and/or * overlaps itself * @see "http://www.mathopenref.com/coordpolygonarea2.html" */ @Override public Surface surface() { long dm7Squared = 0L; final Iterator<Location> loopOnItself = loopOnItself().iterator(); if (!loopOnItself.hasNext()) { return Surface.forDm7Squared(0); } Location current = loopOnItself.next(); Location next = null; while (loopOnItself.hasNext()) { next = loopOnItself.next(); dm7Squared += (current.getLongitude().asDm7() + next.getLongitude().asDm7()) * (current.getLatitude().asDm7() - next.getLatitude().asDm7()); current = next; } return Surface.forDm7Squared(Math.abs(Math.round(dm7Squared / 2.0))); }
@Override public ProtoLocation backwardConvert(final Location location) { final ProtoLocation.Builder protoLocationBuilder = ProtoLocation.newBuilder(); protoLocationBuilder.setLatitude(Math.toIntExact(location.getLatitude().asDm7())); protoLocationBuilder.setLongitude(Math.toIntExact(location.getLongitude().asDm7())); return protoLocationBuilder.build(); }
private java.awt.Polygon awtPolygon() { if (this.awtPolygon == null) { final int size = size(); final int[] xArray = new int[size]; final int[] yArray = new int[size]; int index = 0; for (final Location location : this) { xArray[index] = (int) location.getLongitude().asDm7(); yArray[index] = (int) location.getLatitude().asDm7(); index++; } this.awtPolygon = new java.awt.Polygon(xArray, yArray, size); } return this.awtPolygon; }
final int longitude = (int) location.getLongitude().asDm7(); final int deltaLatitude = latitude - formerLatitude; final int deltaLongitude = longitude - formerLongitude;
/** * @return True if this {@link Polygon} is arranged clockwise, false otherwise. * @see <a href="http://stackoverflow.com/questions/1165647"></a> */ public boolean isClockwise() { long sum = 0; long lastLatitude = Long.MIN_VALUE; long lastLongitude = Long.MIN_VALUE; for (final Location point : this) { if (lastLongitude != Long.MIN_VALUE) { sum += (point.getLongitude().asDm7() - lastLongitude) * (point.getLatitude().asDm7() + lastLatitude); } lastLongitude = point.getLongitude().asDm7(); lastLatitude = point.getLatitude().asDm7(); } return sum >= 0; }
protected Rectangle2D asAwtRectangle() { final int xAxis = (int) this.upperLeft().getLongitude().asDm7(); final int yAxis = (int) this.upperLeft().getLatitude().asDm7(); final int width = (int) (this.upperRight().getLongitude().asDm7() - this.upperLeft().getLongitude().asDm7()); final int height = (int) (this.upperLeft().getLatitude().asDm7() - this.lowerLeft().getLatitude().asDm7()); return new java.awt.Rectangle(xAxis, yAxis, width, height); } }
tags.put("longitude", String.valueOf(location.getLongitude().asDm7()));
/** * @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)); }
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; }
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)),