1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
//! The `h3o` library implements the H3 geospatial indexing system.
//!
//! H3 is a geospatial indexing system using a hexagonal grid that can be
//! (approximately) subdivided into finer and finer hexagonal grids, combining
//! the benefits of a hexagonal grid with S2's hierarchical subdivisions.
//!
//! ## Crate features
//!
//! * **std** -
//! When enabled, this will cause `h3o` to use the standard library. In terms of
//! APIs, `std` causes error types to implement the `std::error::Error` trait.
//! Enabling `std` will also result in performance optimizations.
//!
//! * **geo** -
//! When enabled, you'll be able to convert lists of H3 cell indexes from and
//! into geometric shapes. Also enables the `GeoJSON` support. Requires `std`.
//!
//! * **serde** -
//! When enabled, H3 index types (cell, vertex and edge) derive serde traits.
//!
//! ## H3 to H3O mapping
//!
//! For people used to the H3 API, here is the mapping to H3O.
//!
//! ### Indexing functions
//!
//! | H3 | H3O |
//! | :--------------- | :------------------------- |
//! | `latLngToCell` | [`LatLng::to_cell`] |
//! | `cellToLatLng` | [`LatLng::from`](./struct.LatLng.html#impl-From<CellIndex>-for-LatLng) |
//! | `cellToBoundary` | [`CellIndex::boundary`] |
//!
//! ### Index inspection functions
//!
//! | H3 | H3O |
//! | :-------------------- | :------------------------------- |
//! | `getResolution` | [`CellIndex::resolution`] |
//! | `getBaseCellNumber` | [`CellIndex::base_cell`] |
//! | `getIndexDigit` | [`CellIndex::direction_at`] |
//! | `stringToH3` | [`str::parse`] |
//! | `h3ToString` | [`ToString::to_string`] |
//! | `isValidCell` | [`CellIndex::try_from`](./struct.CellIndex.html#impl-TryFrom<u64>-for-CellIndex) |
//! | `isResClassIII` | [`Resolution::is_class3`] |
//! | `isPentagon` | [`CellIndex::is_pentagon`] |
//! | `getIcosahedronFaces` | [`CellIndex::icosahedron_faces`] |
//! | `maxFaceCount` | [`CellIndex::max_face_count`] |
//!
//! ### Grid traversal functions
//!
//! | H3 | H3O |
//! | :------------------------ | :-------------------------------------- |
//! | `gridDisk` | [`CellIndex::grid_disk`] |
//! | `maxGridDiskSize` | [`max_grid_disk_size`] |
//! | `maxGridRingSize` | [`max_grid_ring_size`] |
//! | `gridDiskDistances` | [`CellIndex::grid_disk_distances`] |
//! | `gridDiskUnsafe` | [`CellIndex::grid_disk_fast`] |
//! | `gridDiskDistancesUnsafe` | [`CellIndex::grid_disk_distances_fast`] |
//! | `gridDiskDistancesSafe` | [`CellIndex::grid_disk_distances_safe`] |
//! | `gridDisksUnsafe` | [`CellIndex::grid_disks_fast`] |
//! | `gridRingUnsafe` | [`CellIndex::grid_ring_fast`] |
//! | `gridRing` | [`CellIndex::grid_ring`] |
//! | `gridPathCells` | [`CellIndex::grid_path_cells`] |
//! | `gridPathCellsSize` | [`CellIndex::grid_path_cells_size`] |
//! | `gridDistance` | [`CellIndex::grid_distance`] |
//! | `cellToLocalIj` | [`CellIndex::to_local_ij`] |
//! | `localIjToCell` | [`CellIndex::try_from`](./struct.CellIndex.html#impl-TryFrom<LocalIJ>-for-CellIndex) |
//!
//! ### Hierarchical grid functions
//!
//! | H3 | H3O |
//! | :---------------------- | :---------------------------- |
//! | `cellToParent` | [`CellIndex::parent`] |
//! | `cellToChildren` | [`CellIndex::children`] |
//! | `cellToChildrenSize` | [`CellIndex::children_count`] |
//! | `cellToCenterChild` | [`CellIndex::center_child`] |
//! | `cellToChildPos` | [`CellIndex::child_position`] |
//! | `childPosToCell` | [`CellIndex::child_at`] |
//! | `compactCells` | [`CellIndex::compact`] |
//! | `uncompactCells` | [`CellIndex::uncompact`] |
//! | `uncompactCellsSize` | [`CellIndex::uncompact_size`] |
//!
//! ### Region functions
//!
//! | H3 | H3O |
//! | :---------------------- | :--------------------------------- |
//! | `polygonToCells` | [`geom::Tiler::into_coverage`] |
//! | `maxPolygonToCellsSize` | [`geom::Tiler::coverage_size_hint`] |
//! | `h3SetToLinkedGeo` | [`geom::Solvent::dissolve`] |
//! | `destroyLinkedPolygon` | N/A |
//!
//! ### Directed edge functions
//!
//! | H3 | H3O |
//! | :--------------------------- | :--------------------------------- |
//! | `areNeighborCells` | [`CellIndex::is_neighbor_with`] |
//! | `cellsToDirectedEdge` | [`CellIndex::edge`] |
//! | `isValidDirectedEdge` | [`DirectedEdgeIndex::try_from`](./struct.DirectedEdgeIndex.html#impl-TryFrom<u64>-for-DirectedEdgeIndex) |
//! | `getDirectedEdgeOrigin` | [`DirectedEdgeIndex::origin`] |
//! | `getDirectedEdgeDestination` | [`DirectedEdgeIndex::destination`] |
//! | `directedEdgeToCells` | [`DirectedEdgeIndex::cells`] |
//! | `originToDirectedEdges` | [`CellIndex::edges`] |
//! | `directedEdgeToBoundary` | [`DirectedEdgeIndex::boundary`] |
//!
//! ### Vertex functions
//!
//! | H3 | H3O |
//! | :--------------- | :------------------------ |
//! | `cellToVertex` | [`CellIndex::vertex`] |
//! | `cellToVertexes` | [`CellIndex::vertexes`] |
//! | `vertexToLatLng` | [`LatLng::from`](./struct.LatLng.html#impl-From<VertexIndex>-for-LatLng) |
//! | `isValidVertex` | [`VertexIndex::try_from`](./struct.VertexIndex.html#impl-TryFrom<u64>-for-VertexIndex) |
//!
//! ### Miscellaneous H3 functions
//!
//! | H3 | H3O |
//! | :-------------------------- | :--------------------------------- |
//! | `degsToRads` | [`f64::to_radians`] |
//! | `radsToDegs` | [`f64::to_degrees`] |
//! | `getHexagonAreaAvgKm2` | [`Resolution::area_km2`] |
//! | `getHexagonAreaAvgM2` | [`Resolution::area_m2`] |
//! | `cellAreaKm2` | [`CellIndex::area_km2`] |
//! | `cellAreaM2` | [`CellIndex::area_m2`] |
//! | `cellAreaRads2` | [`CellIndex::area_rads2`] |
//! | `getHexagonEdgeLengthAvgKm` | [`Resolution::edge_length_km`] |
//! | `getHexagonEdgeLengthAvgM` | [`Resolution::edge_length_m`] |
//! | `edgeLengthKm` | [`DirectedEdgeIndex::length_km`] |
//! | `edgeLengthM` | [`DirectedEdgeIndex::length_m`] |
//! | `edgeLengthRads` | [`DirectedEdgeIndex::length_rads`] |
//! | `getNumCells` | [`Resolution::cell_count`] |
//! | `getRes0Cells` | [`CellIndex::base_cells`] |
//! | `res0CellCount` | [`BaseCell::count`] |
//! | `getPentagons` | [`Resolution::pentagons`] |
//! | `pentagonCount` | [`Resolution::pentagon_count`] |
//! | `greatCircleDistanceKm` | [`LatLng::distance_km`] |
//! | `greatCircleDistanceM` | [`LatLng::distance_m`] |
//! | `greatCircleDistanceRads` | [`LatLng::distance_rads`] |
// Lints {{{
// }}}
extern crate alloc;
pub use BaseCell;
pub use Boundary;
pub use ;
pub use Direction;
pub use ;
pub use ;
pub use Resolution;
use ExtendedResolution;
// -----------------------------------------------------------------------------
/// An icosahedron has 20 faces.
const NUM_ICOSA_FACES: usize = 20;
// The number of vertices in a hexagon.
const NUM_HEX_VERTS: u8 = 6;
// The number of vertices in a pentagon.
const NUM_PENT_VERTS: u8 = 5;
/// Direction: counterclockwise
const CCW: bool = true;
/// Direction: clockwise
const CW: bool = false;
/// Earth radius in kilometers using WGS84 authalic radius.
pub const EARTH_RADIUS_KM: f64 = 6371.007180918475_f64;
/// Number of pentagon per resolution.
const NUM_PENTAGONS: u8 = 12;
/// Default cell index (resolution 0, base cell 0).
const DEFAULT_CELL_INDEX: u64 = 0x0800_1fff_ffff_ffff;
// 2π
const TWO_PI: f64 = 2. * PI;
// -----------------------------------------------------------------------------
/// Maximum number of indices produced by the grid disk algorithm with the given
/// `k`.
///
/// # Example
///
/// ```
/// let count = h3o::max_grid_disk_size(3);
/// ```
pub const
/// Maximum number of cells that result from the `gridRing` algorithm with
/// the given `k`.
/// # Example
///
/// ```
/// let count = h3o::max_grid_ring_size(3);
/// ```
pub const