Skip to content

Commit

Permalink
Introduce H3 min resolution constant (#165)
Browse files Browse the repository at this point in the history
H3 version 1 has 16 resolutions, numbered 0 through 15.
Introduced a constant to represent min value, similar
to max value.

Signed-off-by: Vijayan Balasubramanian <[email protected]>
  • Loading branch information
VijayanB authored Oct 13, 2022
1 parent dc6da90 commit a2eaf96
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ final class Constants {
*/
public static double M_SQRT3_2 = 0.8660254037844386467637231707529361834714;
/**
* max H3 resolution; H3 version 1 has 16 resolutions, numbered 0 through 15
* H3 version 1 has 16 resolutions, numbered 0 through 15
* min H3 resolution
*/
public static int MIN_H3_RES = 0;
/**
* max H3 resolution;
*/
public static int MAX_H3_RES = 15;
/**
Expand Down
3 changes: 2 additions & 1 deletion libs/h3/src/main/java/org/opensearch/geospatial/h3/H3.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*/
public final class H3 {

public static int MIN_H3_RES = Constants.MIN_H3_RES;
public static int MAX_H3_RES = Constants.MAX_H3_RES;

/**
Expand Down Expand Up @@ -82,7 +83,7 @@ public static boolean h3IsValid(long h3) {
}

int res = H3Index.H3_get_resolution(h3);
if (res < 0 || res > Constants.MAX_H3_RES) { // LCOV_EXCL_BR_LINE
if (res < Constants.MIN_H3_RES || res > Constants.MAX_H3_RES) { // LCOV_EXCL_BR_LINE
// Resolutions less than zero can not be represented in an index
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void testParentChild() {
}
h3Addresses = H3.h3ToChildren(h3Address);
h3Address = RandomPicks.randomFrom(random(), h3Addresses);
for (int i = H3.MAX_H3_RES - 1; i >= 0; i--) {
for (int i = H3.MAX_H3_RES - 1; i >= H3.MIN_H3_RES; i--) {
h3Address = H3.h3ToParent(h3Address);
assertEquals(values[i], h3Address);
}
Expand Down

0 comments on commit a2eaf96

Please sign in to comment.