JNIEXPORT void JNICALL Java_com_uber_h3core_NativeMethods_cellToLocalIj()

in src/main/c/h3-java/src/jniapi.c [468:494]


JNIEXPORT void JNICALL Java_com_uber_h3core_NativeMethods_cellToLocalIj(
    JNIEnv *env, jobject thiz, jlong origin, jlong h3, jintArray coords) {
    CoordIJ ij = {0};
    H3Error err = cellToLocalIj(origin, h3, 0, &ij);
    if (err) {
        ThrowH3Exception(env, err);
        return;
    }

    jsize sz = (**env).GetArrayLength(env, coords);
    jint *coordsElements = (**env).GetIntArrayElements(env, coords, 0);

    if (coordsElements != NULL) {
        // if sz is too small, we will fail to write all the elements
        if (sz >= 2) {
            coordsElements[0] = ij.i;
            coordsElements[1] = ij.j;
        }

        // 0 is the mode
        // reference
        // https://developer.android.com/training/articles/perf-jni.html
        (**env).ReleaseIntArrayElements(env, coords, coordsElements, 0);
    } else {
        ThrowOutOfMemoryError(env);
    }
}