private Encoding(int numBytes) { assert numBytes >= 1 && numBytes <= MAX_NUM_BYTES; assert (numBytes & 1) == 0; // we don't support odd numBytes for the moment this.numBytes = numBytes; this.numBytesPerCoordinate = numBytes / 2; this.factor = Math.pow(2, -numBytesPerCoordinate * 8 + 9); assert (1L << (numBytesPerCoordinate * 8 - 1)) * factor > 180 && (1L << (numBytesPerCoordinate * 8 - 2)) * factor < 180 : numBytesPerCoordinate + " " + factor; if (numBytes == MAX_NUM_BYTES) { // no precision loss compared to a double precision = new DistanceUnit.Distance(0, DistanceUnit.DEFAULT); } else { precision = new DistanceUnit.Distance( GeoDistance.PLANE.calculate( 0, 0, factor / 2, factor / 2, DistanceUnit .DEFAULT), // factor/2 because we use Math.round instead of a cast to // convert the double to a long DistanceUnit.DEFAULT); } }
private static boolean contains(GeoPoint point, List<GeoPoint> set, Distance precision) { for (GeoPoint r : set) { final double distance = GeoDistance.PLANE.calculate( point.getLat(), point.getLon(), r.getLat(), r.getLon(), DistanceUnit.METERS); if (new Distance(distance, DistanceUnit.METERS).compareTo(precision) <= 0) { return true; } } return false; }