Skip to content

Commit

Permalink
Merge pull request #31 from nrabinowitz/bump-3.4.0
Browse files Browse the repository at this point in the history
Bump core library to 3.4.0, add getRes0Indexes
  • Loading branch information
nrabinowitz authored Jan 25, 2019
2 parents afb24f8 + 66e4900 commit 5b50f55
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 7 deletions.
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 .

# 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
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 comments on commit 5b50f55

Please sign in to comment.