UNPKG

5.19 kBJavaScriptView Raw
1'use strict';
2
3/*
4 * Copyright 2018-2019 Uber Technologies, Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19// Define the C bindings for the h3 library
20
21// Add some aliases to make the function definitions more intelligible
22const NUMBER = 'number';
23const BOOLEAN = NUMBER;
24const H3_LOWER = NUMBER;
25const H3_UPPER = NUMBER;
26const RESOLUTION = NUMBER;
27const POINTER = NUMBER;
28
29// Define the bindings to functions in the C lib. Functions are defined as
30// [name, return type, [arg types]]. You must run `npm run build-emscripten`
31// before new functions added here will be available.
32var BINDINGS = [
33 // The size functions are inserted via build/sizes.h
34 ['sizeOfH3Index', NUMBER],
35 ['sizeOfGeoCoord', NUMBER],
36 ['sizeOfGeoBoundary', NUMBER],
37 ['sizeOfGeoPolygon', NUMBER],
38 ['sizeOfGeofence', NUMBER],
39 ['sizeOfLinkedGeoPolygon', NUMBER],
40 ['sizeOfCoordIJ', NUMBER],
41 // The remaining functions are defined in the core lib in h3Api.h
42 ['h3IsValid', BOOLEAN, [H3_LOWER, H3_UPPER]],
43 ['geoToH3', H3_LOWER, [NUMBER, NUMBER, RESOLUTION]],
44 ['h3ToGeo', null, [H3_LOWER, H3_UPPER, POINTER]],
45 ['h3ToGeoBoundary', null, [H3_LOWER, H3_UPPER, POINTER]],
46 ['maxKringSize', NUMBER, [NUMBER]],
47 ['kRing', null, [H3_LOWER, H3_UPPER, NUMBER, POINTER]],
48 ['kRingDistances', null, [H3_LOWER, H3_UPPER, NUMBER, POINTER, POINTER]],
49 ['hexRing', null, [H3_LOWER, H3_UPPER, NUMBER, POINTER]],
50 ['maxPolyfillSize', NUMBER, [POINTER, RESOLUTION]],
51 ['polyfill', null, [POINTER, RESOLUTION, POINTER]],
52 ['h3SetToLinkedGeo', null, [POINTER, NUMBER, POINTER]],
53 ['destroyLinkedPolygon', null, [POINTER]],
54 ['compact', NUMBER, [POINTER, POINTER, NUMBER]],
55 ['uncompact', NUMBER, [POINTER, NUMBER, POINTER, NUMBER, RESOLUTION]],
56 ['maxUncompactSize', NUMBER, [POINTER, NUMBER, RESOLUTION]],
57 ['h3IsPentagon', BOOLEAN, [H3_LOWER, H3_UPPER]],
58 ['h3IsResClassIII', BOOLEAN, [H3_LOWER, H3_UPPER]],
59 ['h3GetBaseCell', NUMBER, [H3_LOWER, H3_UPPER]],
60 ['maxFaceCount', NUMBER, [H3_LOWER, H3_UPPER]],
61 ['h3GetFaces', null, [H3_LOWER, H3_UPPER, POINTER]],
62 ['h3ToParent', H3_LOWER, [H3_LOWER, H3_UPPER, RESOLUTION]],
63 ['h3ToChildren', null, [H3_LOWER, H3_UPPER, RESOLUTION, POINTER]],
64 ['h3ToCenterChild', H3_LOWER, [H3_LOWER, H3_UPPER, RESOLUTION]],
65 ['maxH3ToChildrenSize', NUMBER, [H3_LOWER, H3_UPPER, RESOLUTION]],
66 ['h3IndexesAreNeighbors', BOOLEAN, [H3_LOWER, H3_UPPER, H3_LOWER, H3_UPPER]],
67 ['getH3UnidirectionalEdge', H3_LOWER, [H3_LOWER, H3_UPPER, H3_LOWER, H3_UPPER]],
68 ['getOriginH3IndexFromUnidirectionalEdge', H3_LOWER, [H3_LOWER, H3_UPPER]],
69 ['getDestinationH3IndexFromUnidirectionalEdge', H3_LOWER, [H3_LOWER, H3_UPPER]],
70 ['h3UnidirectionalEdgeIsValid', BOOLEAN, [H3_LOWER, H3_UPPER]],
71 ['getH3IndexesFromUnidirectionalEdge', null, [H3_LOWER, H3_UPPER, POINTER]],
72 ['getH3UnidirectionalEdgesFromHexagon', null, [H3_LOWER, H3_UPPER, POINTER]],
73 ['getH3UnidirectionalEdgeBoundary', null, [H3_LOWER, H3_UPPER, POINTER]],
74 ['h3Distance', NUMBER, [H3_LOWER, H3_UPPER, H3_LOWER, H3_UPPER]],
75 ['h3Line', NUMBER, [H3_LOWER, H3_UPPER, H3_LOWER, H3_UPPER, POINTER]],
76 ['h3LineSize', NUMBER, [H3_LOWER, H3_UPPER, H3_LOWER, H3_UPPER]],
77 ['experimentalH3ToLocalIj', NUMBER, [H3_LOWER, H3_UPPER, H3_LOWER, H3_UPPER, POINTER]],
78 ['experimentalLocalIjToH3', NUMBER, [H3_LOWER, H3_UPPER, POINTER, POINTER]],
79 ['hexAreaM2', NUMBER, [RESOLUTION]],
80 ['hexAreaKm2', NUMBER, [RESOLUTION]],
81 ['edgeLengthM', NUMBER, [RESOLUTION]],
82 ['edgeLengthKm', NUMBER, [RESOLUTION]],
83 ['numHexagons', NUMBER, [RESOLUTION]],
84 ['getRes0Indexes', null, [POINTER]],
85 ['res0IndexCount', NUMBER],
86 ['getPentagonIndexes', null, [NUMBER, POINTER]],
87 ['pentagonIndexCount', NUMBER]
88];
89
90/*
91 * Copyright 2018-2019 Uber Technologies, Inc.
92 *
93 * Licensed under the Apache License, Version 2.0 (the "License");
94 * you may not use this file except in compliance with the License.
95 * You may obtain a copy of the License at
96 *
97 * http://www.apache.org/licenses/LICENSE-2.0
98 *
99 * Unless required by applicable law or agreed to in writing, software
100 * distributed under the License is distributed on an "AS IS" BASIS,
101 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
102 * See the License for the specific language governing permissions and
103 * limitations under the License.
104 */
105
106const bindingNames = BINDINGS
107 // The _ prefix here is required for references in the built code
108 .map(def => `_${def[0]}`)
109 // Add core C functions required by the lib
110 .concat(['_malloc', '_calloc']);
111
112console.log(JSON.stringify(bindingNames));