Example usage for org.apache.lucene.util BitUtil interleave

List of usage examples for org.apache.lucene.util BitUtil interleave

Introduction

In this page you can find the example usage for org.apache.lucene.util BitUtil interleave.

Prototype

public static long interleave(int even, int odd) 

Source Link

Document

Interleaves the first 32 bits of each long value Adapted from: http://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN

Usage

From source file:org.codelibs.elasticsearch.common.geo.GeoHashUtils.java

License:Apache License

/**
 * Computes the bounding box coordinates from a given geohash
 *
 * @param geohash Geohash of the defined cell
 * @return GeoRect rectangle defining the bounding box
 *//*from   www  .  j  av  a2  s .c  om*/
public static Rectangle bbox(final String geohash) {
    // bottom left is the coordinate
    GeoPoint bottomLeft = GeoPoint.fromGeohash(geohash);
    long ghLong = longEncode(geohash);
    // shift away the level
    ghLong >>>= 4;
    // deinterleave and add 1 to lat and lon to get topRight
    long lat = BitUtil.deinterleave(ghLong >>> 1) + 1;
    long lon = BitUtil.deinterleave(ghLong) + 1;
    GeoPoint topRight = GeoPoint.fromGeohash(BitUtil.interleave((int) lon, (int) lat) << 4 | geohash.length());

    return new Rectangle(bottomLeft.lat(), topRight.lat(), bottomLeft.lon(), topRight.lon());
}