Skip to content

Commit 8f4555c

Browse files
authored
Upgrade h3 v4.2.0 (#163)
* fix build on arm64 * begin upgrade to h3 v4.2.0 * upgrade to h3 v4.2.0 * fix build
1 parent 83a7822 commit 8f4555c

File tree

10 files changed

+270
-13
lines changed

10 files changed

+270
-13
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Coverage Status](https://coveralls.io/repos/github/uber/h3-java/badge.svg?branch=master)](https://coveralls.io/github/uber/h3-java?branch=master)
77
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
88
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.uber/h3/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.uber/h3)
9-
[![H3 Version](https://img.shields.io/badge/h3-v4.1.0-blue.svg)](https://github.com/uber/h3/releases/tag/v4.1.0)
9+
[![H3 Version](https://img.shields.io/badge/h3-v4.2.0-blue.svg)](https://github.com/uber/h3/releases/tag/v4.2.0)
1010

1111
This library provides Java bindings for the [H3 Core Library](https://github.com/uber/h3). For API reference, please see the [H3 Documentation](https://h3geo.org/).
1212

@@ -18,14 +18,14 @@ Add it to your pom.xml:
1818
<dependency>
1919
<groupId>com.uber</groupId>
2020
<artifactId>h3</artifactId>
21-
<version>4.1.2</version>
21+
<version>4.2.0</version>
2222
</dependency>
2323
```
2424

2525
Or, using Gradle:
2626

2727
```gradle
28-
compile("com.uber:h3:4.1.2")
28+
compile("com.uber:h3:4.2.0")
2929
```
3030

3131
Encode a location into a hexagon address:

h3version.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
h3.git.reference=v4.1.0
1+
h3.git.reference=v4.2.0

src/main/c/h3-java/build-h3-docker.sh

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ BUILD_ROOT=$1
2929
UPGRADE_CMAKE=$2
3030
CMAKE_ROOT=$3
3131

32+
# TODO: This may no longer be necessary
3233
if $UPGRADE_CMAKE; then
3334
pushd "$CMAKE_ROOT"
3435
if ! [ -e cmake-3.23.2-linux-x86_64.sh ]; then
@@ -51,6 +52,7 @@ mkdir -p build
5152
pushd build
5253

5354
cmake -DBUILD_SHARED_LIBS=OFF \
55+
-DENABLE_WARNINGS=OFF \
5456
-DCMAKE_C_STANDARD_REQUIRED=ON \
5557
-DCMAKE_C_STANDARD=99 \
5658
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \

src/main/c/h3-java/build-h3.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ CMAKE_ROOT=target/cmake-3.23.2-linux-x86_64
184184
mkdir -p $CMAKE_ROOT
185185

186186
DOCKCROSS_IMAGES="android-arm android-arm64 linux-arm64 linux-armv5 linux-armv7 linux-s390x linux-ppc64le linux-x64 linux-x86 windows-static-x64 windows-static-x86"
187-
if ! $DOCKCROSS_ONLY; then
187+
if ! [ -z $DOCKCROSS_ONLY ]; then
188188
DOCKCROSS_IMAGES=$DOCKCROSS_ONLY
189189
echo Building only: $DOCKCROSS_IMAGES
190190
fi

src/main/c/h3-java/src/jniapi.c

+61-1
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,32 @@ Java_com_uber_h3core_NativeMethods_maxPolygonToCellsSize(
571571
return numHexagons;
572572
}
573573

574+
/*
575+
* Class: com_uber_h3core_NativeMethods
576+
* Method: maxPolygonToCellsSizeExperimental
577+
* Signature: ([D[I[DII)J
578+
*/
579+
JNIEXPORT jlong JNICALL
580+
Java_com_uber_h3core_NativeMethods_maxPolygonToCellsSizeExperimental(
581+
JNIEnv *env, jobject thiz, jdoubleArray verts, jintArray holeSizes,
582+
jdoubleArray holeVerts, jint res, jint flags) {
583+
GeoPolygon polygon;
584+
if (CreateGeoPolygon(env, verts, holeSizes, holeVerts, &polygon)) {
585+
return -1;
586+
}
587+
588+
jlong numHexagons;
589+
H3Error err =
590+
maxPolygonToCellsSizeExperimental(&polygon, res, flags, &numHexagons);
591+
592+
DestroyGeoPolygon(env, verts, holeSizes, holeVerts, &polygon);
593+
594+
if (err) {
595+
ThrowH3Exception(env, err);
596+
}
597+
return numHexagons;
598+
}
599+
574600
/*
575601
* Class: com_uber_h3core_NativeMethods
576602
* Method: getRes0Cells
@@ -657,6 +683,40 @@ JNIEXPORT void JNICALL Java_com_uber_h3core_NativeMethods_polygonToCells(
657683
}
658684
}
659685

686+
/*
687+
* Class: com_uber_h3core_NativeMethods
688+
* Method: polygonToCellsExperimental
689+
* Signature: ([D[I[DII[J)V
690+
*/
691+
JNIEXPORT void JNICALL
692+
Java_com_uber_h3core_NativeMethods_polygonToCellsExperimental(
693+
JNIEnv *env, jobject thiz, jdoubleArray verts, jintArray holeSizes,
694+
jdoubleArray holeVerts, jint res, jint flags, jlongArray results) {
695+
GeoPolygon polygon;
696+
if (CreateGeoPolygon(env, verts, holeSizes, holeVerts, &polygon)) {
697+
return;
698+
}
699+
700+
jlong *resultsElements = (**env).GetLongArrayElements(env, results, 0);
701+
jsize resultsSize = (**env).GetArrayLength(env, results);
702+
703+
H3Error err;
704+
if (resultsElements != NULL) {
705+
err = polygonToCellsExperimental(&polygon, res, flags, resultsSize,
706+
resultsElements);
707+
708+
(**env).ReleaseLongArrayElements(env, results, resultsElements, 0);
709+
} else {
710+
ThrowOutOfMemoryError(env);
711+
}
712+
713+
DestroyGeoPolygon(env, verts, holeSizes, holeVerts, &polygon);
714+
715+
if (err) {
716+
ThrowH3Exception(env, err);
717+
}
718+
}
719+
660720
/**
661721
* Converts the given polygon to managed objects
662722
* (ArrayList<ArrayList<ArrayList<LatLng>>>)
@@ -1337,7 +1397,7 @@ JNIEXPORT jlong JNICALL Java_com_uber_h3core_NativeMethods_cellToVertex(
13371397
JNIEXPORT void JNICALL Java_com_uber_h3core_NativeMethods_cellToVertexes(
13381398
JNIEnv *env, jobject thiz, jlong h3, jlongArray vertexes) {
13391399
jsize sz = (**env).GetArrayLength(env, vertexes);
1340-
jint *vertexesElements = (**env).GetLongArrayElements(env, vertexes, 0);
1400+
jlong *vertexesElements = (**env).GetLongArrayElements(env, vertexes, 0);
13411401

13421402
if (vertexesElements != NULL && sz >= 6) {
13431403
H3Error err = cellToVertexes(h3, vertexesElements);

src/main/java/com/uber/h3core/H3Core.java

+64-6
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,68 @@ public List<Long> gridPathCells(long start, long end) {
518518
}
519519

520520
/**
521-
* Finds indexes within the given geofence.
521+
* Finds indexes within the given geopolygon.
522522
*
523-
* @param points Outline geofence
524-
* @param holes Geofences of any internal holes
523+
* @param points Outline geopolygon
524+
* @param holes Geopolygons of any internal holes
525+
* @param res Resolution of the desired indexes
526+
*/
527+
public List<String> polygonToCellAddressesExperimental(
528+
List<LatLng> points, List<List<LatLng>> holes, PolygonToCellsFlags flags, int res) {
529+
return h3ToStringList(polygonToCellsExperimental(points, holes, flags, res));
530+
}
531+
532+
/**
533+
* Finds indexes within the given geopolygon.
534+
*
535+
* @param points Outline geopolygon
536+
* @param holes Geopolygon of any internal holes
537+
* @param res Resolution of the desired indexes
538+
* @throws IllegalArgumentException Invalid resolution
539+
*/
540+
public List<Long> polygonToCellsExperimental(
541+
List<LatLng> points, List<List<LatLng>> holes, PolygonToCellsFlags flags, int res) {
542+
checkResolution(res);
543+
544+
// pack the data for use by the polyfill JNI call
545+
double[] verts = new double[points.size() * 2];
546+
packGeofenceVertices(verts, points, 0);
547+
int[] holeSizes = new int[0];
548+
double[] holeVerts = new double[0];
549+
if (holes != null) {
550+
int holesSize = holes.size();
551+
holeSizes = new int[holesSize];
552+
int totalSize = 0;
553+
for (int i = 0; i < holesSize; i++) {
554+
int holeSize = holes.get(i).size() * 2;
555+
totalSize += holeSize;
556+
// Note we are storing the number of doubles
557+
holeSizes[i] = holeSize;
558+
}
559+
holeVerts = new double[totalSize];
560+
int offset = 0;
561+
for (int i = 0; i < holesSize; i++) {
562+
offset = packGeofenceVertices(holeVerts, holes.get(i), offset);
563+
}
564+
}
565+
566+
int flagsInt = flags.toInt();
567+
int sz =
568+
longToIntSize(
569+
h3Api.maxPolygonToCellsSizeExperimental(verts, holeSizes, holeVerts, res, flagsInt));
570+
571+
long[] results = new long[sz];
572+
573+
h3Api.polygonToCellsExperimental(verts, holeSizes, holeVerts, res, flagsInt, results);
574+
575+
return nonZeroLongArrayToList(results);
576+
}
577+
578+
/**
579+
* Finds indexes within the given geopolygon.
580+
*
581+
* @param points Outline geopolygon
582+
* @param holes Geopolygons of any internal holes
525583
* @param res Resolution of the desired indexes
526584
*/
527585
public List<String> polygonToCellAddresses(
@@ -530,10 +588,10 @@ public List<String> polygonToCellAddresses(
530588
}
531589

532590
/**
533-
* Finds indexes within the given geofence.
591+
* Finds indexes within the given geopolygon.
534592
*
535-
* @param points Outline geofence
536-
* @param holes Geofences of any internal holes
593+
* @param points Outline geopolygon
594+
* @param holes Geopolygon of any internal holes
537595
* @param res Resolution of the desired indexes
538596
* @throws IllegalArgumentException Invalid resolution
539597
*/

src/main/java/com/uber/h3core/NativeMethods.java

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ final class NativeMethods {
6666

6767
native void gridPathCells(long start, long end, long[] results);
6868

69+
native long maxPolygonToCellsSizeExperimental(
70+
double[] verts, int[] holeSizes, double[] holeVerts, int res, int flags);
71+
72+
native void polygonToCellsExperimental(
73+
double[] verts, int[] holeSizes, double[] holeVerts, int res, int flags, long[] results);
74+
6975
native long maxPolygonToCellsSize(
7076
double[] verts, int[] holeSizes, double[] holeVerts, int res, int flags);
7177

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2024 Uber Technologies, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.uber.h3core;
17+
18+
/** Flags for polygonToCellsExperimental */
19+
public enum PolygonToCellsFlags {
20+
/** Cell center is contained in the shape */
21+
containment_center(0),
22+
/** Cell is fully contained in the shape */
23+
containment_full(1),
24+
/** Cell overlaps the shape at any point */
25+
containment_overlapping(2),
26+
/** Cell bounding box overlaps shape */
27+
containment_overlapping_bbox(3);
28+
29+
private final int value;
30+
31+
PolygonToCellsFlags(int value) {
32+
this.value = value;
33+
}
34+
35+
public int toInt() {
36+
return this.value;
37+
}
38+
}

src/test/java/com/uber/h3core/TestBindingCompleteness.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ class TestBindingCompleteness {
3333
private static final Set<String> WHITELIST =
3434
ImmutableSet.of(
3535
// These are provided by the Java library (java.lang.Math)
36-
"degsToRads", "radsToDegs");
36+
"degsToRads",
37+
"radsToDegs",
38+
// Handled by H3Exception
39+
"describeH3Error");
3740

3841
@Test
3942
@DisabledInNativeImage

src/test/java/com/uber/h3core/TestRegion.java

+90
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,96 @@
2929

3030
/** Tests for region (polyfill, h3SetToMultiPolygon) functions. */
3131
class TestRegion extends BaseTestH3Core {
32+
@Test
33+
void polyfillExperimentalCenter() {
34+
List<Long> hexagons =
35+
h3.polygonToCellsExperimental(
36+
ImmutableList.of(
37+
new LatLng(37.813318999983238, -122.4089866999972145),
38+
new LatLng(37.7866302000007224, -122.3805436999997056),
39+
new LatLng(37.7198061999978478, -122.3544736999993603),
40+
new LatLng(37.7076131999975672, -122.5123436999983966),
41+
new LatLng(37.7835871999971715, -122.5247187000021967),
42+
new LatLng(37.8151571999998453, -122.4798767000009008)),
43+
null,
44+
PolygonToCellsFlags.containment_center,
45+
9);
46+
47+
assertTrue(hexagons.size() > 1000);
48+
}
49+
50+
@Test
51+
void polyfillExperimentalFull() {
52+
List<Long> hexagons =
53+
h3.polygonToCellsExperimental(
54+
ImmutableList.of(
55+
new LatLng(37.813318999983238, -122.4089866999972145),
56+
new LatLng(37.7866302000007224, -122.3805436999997056),
57+
new LatLng(37.7198061999978478, -122.3544736999993603),
58+
new LatLng(37.7076131999975672, -122.5123436999983966),
59+
new LatLng(37.7835871999971715, -122.5247187000021967),
60+
new LatLng(37.8151571999998453, -122.4798767000009008)),
61+
null,
62+
PolygonToCellsFlags.containment_full,
63+
9);
64+
65+
assertTrue(hexagons.size() > 1000);
66+
}
67+
68+
@Test
69+
void polyfillExperimentalOverlapping() {
70+
List<Long> hexagons =
71+
h3.polygonToCellsExperimental(
72+
ImmutableList.of(
73+
new LatLng(37.813318999983238, -122.4089866999972145),
74+
new LatLng(37.7866302000007224, -122.3805436999997056),
75+
new LatLng(37.7198061999978478, -122.3544736999993603),
76+
new LatLng(37.7076131999975672, -122.5123436999983966),
77+
new LatLng(37.7835871999971715, -122.5247187000021967),
78+
new LatLng(37.8151571999998453, -122.4798767000009008)),
79+
null,
80+
PolygonToCellsFlags.containment_overlapping,
81+
9);
82+
83+
assertTrue(hexagons.size() > 1000);
84+
}
85+
86+
@Test
87+
void polyfillExperimentalOverlappingBbox() {
88+
List<Long> hexagons =
89+
h3.polygonToCellsExperimental(
90+
ImmutableList.of(
91+
new LatLng(37.813318999983238, -122.4089866999972145),
92+
new LatLng(37.7866302000007224, -122.3805436999997056),
93+
new LatLng(37.7198061999978478, -122.3544736999993603),
94+
new LatLng(37.7076131999975672, -122.5123436999983966),
95+
new LatLng(37.7835871999971715, -122.5247187000021967),
96+
new LatLng(37.8151571999998453, -122.4798767000009008)),
97+
null,
98+
PolygonToCellsFlags.containment_overlapping_bbox,
99+
9);
100+
101+
assertTrue(hexagons.size() > 1000);
102+
}
103+
104+
@Test
105+
void polyfillExperimental() {
106+
List<Long> hexagons =
107+
h3.polygonToCellsExperimental(
108+
ImmutableList.of(
109+
new LatLng(37.813318999983238, -122.4089866999972145),
110+
new LatLng(37.7866302000007224, -122.3805436999997056),
111+
new LatLng(37.7198061999978478, -122.3544736999993603),
112+
new LatLng(37.7076131999975672, -122.5123436999983966),
113+
new LatLng(37.7835871999971715, -122.5247187000021967),
114+
new LatLng(37.8151571999998453, -122.4798767000009008)),
115+
null,
116+
PolygonToCellsFlags.containment_center,
117+
9);
118+
119+
assertTrue(hexagons.size() > 1000);
120+
}
121+
32122
@Test
33123
void polyfill() {
34124
List<Long> hexagons =

0 commit comments

Comments
 (0)