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

Upgrade to core v4.0.0-rc5 #151

Merged
merged 2 commits into from
Aug 17, 2022
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
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]
### Breaking changes
- Updated the core library to `v4.0.0-rc5`. (#151)

## [4.0.0-rc3] - 2022-08-11
### Fixed
- Fail package publish if there are library changes
- Fail package publish if there are library changes (#148)

## [4.0.0-rc2] - 2022-08-11
### Added
Expand Down
2 changes: 1 addition & 1 deletion H3_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.0-rc4
4.0.0-rc5
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const coordinates = h3.cellsToMultiPolygon(hexagons, true);
* [.localIjToCell(origin, coords)](#module_h3.localIjToCell) ⇒ <code>H3Index</code>
* [.greatCircleDistance(latLng1, latLng2, unit)](#module_h3.greatCircleDistance) ⇒ <code>number</code>
* [.cellArea(h3Index, unit)](#module_h3.cellArea) ⇒ <code>number</code>
* [.exactEdgeLength(edge, unit)](#module_h3.exactEdgeLength) ⇒ <code>number</code>
* [.edgeLength(edge, unit)](#module_h3.edgeLength) ⇒ <code>number</code>
* [.getHexagonAreaAvg(res, unit)](#module_h3.getHexagonAreaAvg) ⇒ <code>number</code>
* [.getHexagonEdgeLengthAvg(res, unit)](#module_h3.getHexagonEdgeLengthAvg) ⇒ <code>number</code>
* [.cellToVertex(h3Index, vertexNum)](#module_h3.cellToVertex) ⇒ <code>H3Index</code>
Expand Down Expand Up @@ -851,10 +851,10 @@ Exact area of a given cell

* * *

<a name="module_h3.exactEdgeLength"></a>
<a name="module_h3.edgeLength"></a>

### h3.exactEdgeLength(edge, unit) ⇒ <code>number</code>
Exact length of a given unidirectional edge
### h3.edgeLength(edge, unit) ⇒ <code>number</code>
Calculate length of a given unidirectional edge

**Returns**: <code>number</code> - Cell area
**Throws**:
Expand Down
6 changes: 3 additions & 3 deletions lib/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ export default [
['cellAreaM2', H3_ERROR, [H3_LOWER, H3_UPPER, POINTER]],
['cellAreaKm2', H3_ERROR, [H3_LOWER, H3_UPPER, POINTER]],
['cellAreaRads2', H3_ERROR, [H3_LOWER, H3_UPPER, POINTER]],
['exactEdgeLengthM', H3_ERROR, [H3_LOWER, H3_UPPER, POINTER]],
['exactEdgeLengthKm', H3_ERROR, [H3_LOWER, H3_UPPER, POINTER]],
['exactEdgeLengthRads', H3_ERROR, [H3_LOWER, H3_UPPER, POINTER]],
['edgeLengthM', H3_ERROR, [H3_LOWER, H3_UPPER, POINTER]],
['edgeLengthKm', H3_ERROR, [H3_LOWER, H3_UPPER, POINTER]],
['edgeLengthRads', H3_ERROR, [H3_LOWER, H3_UPPER, POINTER]],
['getNumCells', H3_ERROR, [RESOLUTION, POINTER]],
['getRes0Cells', H3_ERROR, [POINTER]],
['res0CellCount', NUMBER],
Expand Down
10 changes: 5 additions & 5 deletions lib/h3core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1384,26 +1384,26 @@ export function cellArea(h3Index, unit) {
}

/**
* Exact length of a given unidirectional edge
* Calculate length of a given unidirectional edge
* @static
* @param {H3Index} edge H3 index of the edge to measure
* @param {string} unit Distance unit (either UNITS.m, UNITS.km, or UNITS.rads)
* @return {number} Cell area
* @throws {H3Error} If the input is invalid
*/
export function exactEdgeLength(edge, unit) {
export function edgeLength(edge, unit) {
const [lower, upper] = h3IndexToSplitLong(edge);
const out = C._malloc(SZ_DBL);
try {
switch (unit) {
case UNITS.m:
throwIfError(H3.exactEdgeLengthM(lower, upper, out));
throwIfError(H3.edgeLengthM(lower, upper, out));
break;
case UNITS.km:
throwIfError(H3.exactEdgeLengthKm(lower, upper, out));
throwIfError(H3.edgeLengthKm(lower, upper, out));
break;
case UNITS.rads:
throwIfError(H3.exactEdgeLengthRads(lower, upper, out));
throwIfError(H3.edgeLengthRads(lower, upper, out));
break;
default:
throw JSBindingError(E_UNKNOWN_UNIT, unit);
Expand Down
2 changes: 1 addition & 1 deletion lib/legacy-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = {
experimentalLocalIjToH3: 'localIjToCell',
pointDist: 'greatCircleDistance',
cellArea: 'cellArea',
exactEdgeLength: 'exactEdgeLength',
exactEdgeLength: 'edgeLength',
hexArea: 'getHexagonAreaAvg',
edgeLength: 'getHexagonEdgeLengthAvg',
numHexagons: 'getNumCells',
Expand Down
2 changes: 1 addition & 1 deletion out/binding-functions
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ greatCircleDistance
getHexagonAreaAvg
cellArea
getHexagonEdgeLengthAvg
exactEdgeLength
edgeLength
getNumCells
getRes0Cells
getPentagons
Expand Down
6 changes: 3 additions & 3 deletions out/libh3.js

Large diffs are not rendered by default.

22 changes: 9 additions & 13 deletions test/h3core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1814,13 +1814,13 @@ test('cellArea - bad units', assert => {
assert.end();
});

test('exactEdgeLength', assert => {
test('edgeLength', assert => {
for (let res = 0; res < 16; res++) {
const h3Index = h3.latLngToCell(0, 0, res);
const edges = h3.originToDirectedEdges(h3Index);
for (let i = 0; i < edges.length; i++) {
const edge = edges[i];
const lengthKm = h3.exactEdgeLength(edge, h3.UNITS.km);
const lengthKm = h3.edgeLength(edge, h3.UNITS.km);
assert.ok(lengthKm > 0, 'Has some length');
assert.ok(
// res 0 has high distortion of average edge length due to high pentagon proportion
Expand All @@ -1829,7 +1829,7 @@ test('exactEdgeLength', assert => {
almostEqual(lengthKm, h3.getHexagonEdgeLengthAvg(res, h3.UNITS.km), 0.2),
`Edge length is close to average edge length at res ${res}, km`
);
const lengthM = h3.exactEdgeLength(edge, h3.UNITS.m);
const lengthM = h3.edgeLength(edge, h3.UNITS.m);
assert.ok(
// res 0 has high distortion of average edge length due to high pentagon proportion
res === 0 ||
Expand All @@ -1838,28 +1838,24 @@ test('exactEdgeLength', assert => {
`Edge length is close to average edge length at res ${res}, m`
);
assert.ok(lengthM > lengthKm, 'm > Km');
assert.ok(lengthKm > h3.exactEdgeLength(edge, h3.UNITS.rads), 'Km > rads');
assert.ok(lengthKm > h3.edgeLength(edge, h3.UNITS.rads), 'Km > rads');
}
}
assert.end();
});

test('exactEdgeLength - bad units', assert => {
test('edgeLength - bad units', assert => {
const h3Index = h3.latLngToCell(0, 0, 9);
const edge = h3.originToDirectedEdges(h3Index)[0];
assert.throws(() => h3.exactEdgeLength(edge), {code: E_UNKNOWN_UNIT}, 'throws on missing unit');
assert.throws(() => h3.edgeLength(edge), {code: E_UNKNOWN_UNIT}, 'throws on missing unit');
assert.throws(
() => h3.exactEdgeLength(edge, 'foo'),
() => h3.edgeLength(edge, 'foo'),
{code: E_UNKNOWN_UNIT},
'throws on unknown unit'
);
assert.throws(() => h3.edgeLength(edge, 42), {code: E_UNKNOWN_UNIT}, 'throws on unknown unit');
assert.throws(
() => h3.exactEdgeLength(edge, 42),
{code: E_UNKNOWN_UNIT},
'throws on unknown unit'
);
assert.throws(
() => h3.exactEdgeLength(edge, h3.UNITS.m2),
() => h3.edgeLength(edge, h3.UNITS.m2),
{code: E_UNKNOWN_UNIT},
'throws on invalid unit'
);
Expand Down