8000 Bump core library to 3.4.0, add getRes0Indexes by nrabinowitz · Pull Request #31 · uber/h3-js · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Bump core library to 3.4.0, add getRes0Indexes #31

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

Merged
merged 4 commits into from
Jan 25, 2019
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
3 changes: 3 additions & 0 deletions .build-emscripten.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pushd h3c
git pull origin master --tags
git checkout "v$(cat ../H3_VERSION)"

# Run cmake - necessary for building h3api.h
cmake .
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a downstream effect of uber/h3#173 - may be relevant to other bindings as well.


# Get canonical list of functions the lib should expose
./scripts/binding_functions.sh && cp binding-functions ../out

Expand Down
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ node_modules/
.*
build/
test/
*.sublime-project
*.sublime-workspace
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed that these files were getting picked up in the package when I published from my local machine.

5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
All notable changes to this project will be documented in this file. This library adheres to a versioning policy described in [the README](./README.md#versioning). The public API of this library consists of the functions exported in [h3core.js](./lib/h3core.js).

## [Unreleased]
- *None*
### Changed
- Updated the core library to v3.4.0 (#31)
### Added
- Added `getRes0Indexes` binding (#31)

## [3.3.0] - 2019-1-8
### Changed
Expand Down
2 changes: 1 addition & 1 deletion H3_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.0
3.4.0
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# h3-js

[![H3 Version](https://img.shields.io/badge/h3_api-v3.3.0-blue.svg)](https://github.com/uber/h3/releases/tag/v3.3.0) [![Build Status](https://travis-ci.org/uber/h3-js.svg?branch=master)](https://travis-ci.org/uber/h3-js) [![Coverage Status](https://coveralls.io/repos/github/uber/h3-js/badge.svg?branch=master)](https://coveralls.io/github/uber/h3-js?branch=master)
[![H3 Version](https://img.shields.io/badge/h3_api-v3.4.0-blue.svg)](https://github.com/uber/h3/releases/tag/v3.4.0) [![Build Status](https://travis-ci.org/uber/h3-js.svg?branch=master)](https://travis-ci.org/uber/h3-js) [![Coverage Status](https://coveralls.io/repos/github/uber/h3-js/badge.svg?branch=master)](https://coveralls.io/github/uber/h3-js?branch=master)

The `h3-js` library provides a pure-JavaScript version of the [H3 Core Library](https://github.com/uber/h3), a hexagon-based geographic grid system. It can be used either in Node >= 4 or in the browser. The core library is transpiled from C using [emscripten](http://kripken.github.io/emscripten-site), offering full parity with the C API and highly efficient operations.

Expand Down Expand Up @@ -99,6 +99,7 @@ const coordinates = h3.h3SetToMultiPolygon(hexagons, true);
* [.hexArea(res, unit)](#module_h3.hexArea) ⇒ <code>Number</code>
* [.edgeLength(res, unit)](#module_h3.edgeLength) ⇒ <code>Number</code>
* [.numHexagons(res)](#module_h3.numHexagons) ⇒ <code>Number</code>
* [.getRes0Indexes()](#module_h3.getRes0Indexes) ⇒ <code>Array.&lt;H3Index&gt;</code>
* [.degsToRads(deg)](#module_h3.degsToRads) ⇒ <code>Number</code>
* [.radsToDegs(rad)](#module_h3.radsToDegs) ⇒ <code>Number</code>

Expand Down Expand Up @@ -656,6 +657,17 @@ so consumers should use caution when applying further operations to the output.
| res | <code>Number</code> | Hexagon resolution |


* * *

<a name="module_h3.getRes0Indexes"></a>

### h3.getRes0Indexes() ⇒ <code>Array.&lt;H3Index&gt;</code>
Get all H3 indexes at resolution 0. As every index at every resolution > 0 is
the descendant of a res 0 index, this can be used with h3ToChildren to iterate
over H3 indexes at any resolution.

**Returns**: <code>Array.&lt;H3Index&gt;</code> - All H3 indexes at res 0

* * *

<a name="module_h3.degsToRads"></a>
Expand Down
4 changes: 3 additions & 1 deletion lib/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,7 @@ module.exports = [
['hexAreaKm2', NUMBER, [RESOLUTION]],
['edgeLengthM', NUMBER, [RESOLUTION]],
['edgeLengthKm', NUMBER, [RESOLUTION]],
['numHexagons', NUMBER, [RESOLUTION]]
['numHexagons', NUMBER, [RESOLUTION]],
['getRes0Indexes', null, [POINTER]],
['res0IndexCount', NUMBER]
];
17 changes: 17 additions & 0 deletions lib/h3core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,22 @@ function numHexagons(res) {
return upper * Math.pow(2, 32) + lower;
}

/**
* Get all H3 indexes at resolution 0. As every index at every resolution > 0 is
* the descendant of a res 0 index, this can be used with h3ToChildren to iterate
* over H3 indexes at any resolution.
* @static
* @return {H3Index[]} All H3 indexes at res 0
*/
function getRes0Indexes() {
const count = H3.res0IndexCount();
const hexagons = C._malloc(SZ_H3INDEX * count);
H3.getRes0Indexes(hexagons);
const out = readArrayOfHexagons(hexagons, count);
C._free(hexagons);
return out;
}

/**
* Convert degrees to radians
* @static
Expand Down Expand Up @@ -1138,6 +1154,7 @@ module.exports = {
hexArea,
edgeLength,
numHexagons,
getRes0Indexes,
degsToRads,
radsToDegs,
UNITS
Expand Down
1 change: 1 addition & 0 deletions out/binding-functions
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ radsToDegs
hexArea
edgeLength
numHexagons
getRes0Indexes
h3GetResolution
h3GetBaseCell
stringToH3
Expand Down
6 changes: 3 additions & 3 deletions out/libh3.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions test/h3core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1421,3 +1421,11 @@ test('numHexagons - bad resolution', assert => {

assert.end();
});

test('getRes0Indexes', assert => {
const indexes = h3core.getRes0Indexes();
assert.equal(indexes.length, 122, 'Got expected count');
assert.ok(indexes.every(h3core.h3IsValid), 'All indexes are valid');

assert.end();
});
0