Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept integers to h3GetResolution #113

Merged
merged 2 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default [
['h3IsPentagon', BOOLEAN, [H3_LOWER, H3_UPPER]],
['h3IsResClassIII', BOOLEAN, [H3_LOWER, H3_UPPER]],
['h3GetBaseCell', NUMBER, [H3_LOWER, H3_UPPER]],
['h3GetResolution', NUMBER, [H3_LOWER, H3_UPPER]],
['maxFaceCount', NUMBER, [H3_LOWER, H3_UPPER]],
['h3GetFaces', null, [H3_LOWER, H3_UPPER, POINTER]],
['h3ToParent', H3_LOWER, [H3_LOWER, H3_UPPER, RESOLUTION]],
Expand Down
10 changes: 6 additions & 4 deletions lib/h3core.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const INVALID_HEXIDECIMAL_CHAR = /[^0-9a-fA-F]/;
* @param {H3IndexInput} h3Index H3 index to check
* @return {number[]} A two-element array with 32 lower bits and 32 upper bits
*/
function h3IndexToSplitLong(h3Index) {
export function h3IndexToSplitLong(h3Index) {
if (
Array.isArray(h3Index) &&
h3Index.length === 2 &&
Expand Down Expand Up @@ -160,7 +160,7 @@ function hexFrom32Bit(num) {
* @param {number} upper Upper 32 bits
* @return {H3Index} H3 index
*/
function splitLongToh3Index(lower, upper) {
export function splitLongToh3Index(lower, upper) {
return hexFrom32Bit(upper) + zeroPad(8, hexFrom32Bit(lower));
}

Expand Down Expand Up @@ -580,10 +580,12 @@ export function h3GetFaces(h3Index) {
* @return {number} The number (0-15) resolution, or -1 if invalid
*/
export function h3GetResolution(h3Index) {
if (typeof h3Index !== 'string') {
const [lower, upper] = h3IndexToSplitLong(h3Index);
if (!H3.h3IsValid(lower, upper)) {
// Compatability with stated API
return -1;
}
return parseInt(h3Index.charAt(1), BASE_16);
return H3.h3GetResolution(lower, upper);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions out/libh3.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions test/h3core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,20 @@ test('h3GetResolution', assert => {
assert.end();
});

test('h3GetResolution - integers', assert => {
for (let res = 0; res < 16; res++) {
// Same as in h3GetResolution above
const h3Index = h3.geoToH3(37.3615593, -122.0553238, res);
const h3IndexInt = h3.h3IndexToSplitLong(h3Index);
assert.equal(
h3.h3GetResolution(h3IndexInt),
res,
'Got the expected resolution back for int'
);
}
assert.end();
});

test('h3ToGeo', assert => {
const latlng = h3.h3ToGeo('85283473fffffff');
assert.deepEqual(
Expand Down