Example usage for com.google.common.geometry S2CellId childPosition

List of usage examples for com.google.common.geometry S2CellId childPosition

Introduction

In this page you can find the example usage for com.google.common.geometry S2CellId childPosition.

Prototype

public int childPosition(int level) 

Source Link

Document

Return the child position (0..3) of this cell's ancestor at the given level, relative to its parent.

Usage

From source file:org.apache.lucene.spatial.prefix.tree.S2PrefixTreeCell.java

/**
 * Codify a {@link S2CellId} into its {@link BytesRef} representation.
 *
 * @param cellId The S2 Cell id to codify.
 * @param bref   The byteref representation.
 *///  ww  w.j  a  va 2 s.com
private void getBytesRefFromS2CellId(S2CellId cellId, BytesRef bref) {
    if (cellId == null) {//world cell
        bref.length = 0;
        return;
    }
    int length = getLevel() + 1;
    byte[] b = bref.bytes.length >= length ? bref.bytes : new byte[length];
    b[0] = TOKENS[cellId.face()];
    for (int i = 1; i < getLevel(); i++) {
        int offset = 0;
        int level = tree.arity * i;
        for (int j = 1; j < tree.arity; j++) {
            offset = 4 * offset + cellId.childPosition(level - tree.arity + j);
        }
        b[i] = TOKENS[4 * offset + cellId.childPosition(level)];
    }
    bref.bytes = b;
    bref.length = getLevel();
    bref.offset = 0;
}