• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uber / h3-java / #405

11 Aug 2024 08:49PM CUT coverage: 98.805%. Remained the same
#405

push

github

web-flow
update pom.xml to a valid email address (#145)

496 of 502 relevant lines covered (98.8%)

0.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.91
/src/main/java/com/uber/h3core/H3CoreV3.java
1
/*
2
 * Copyright 2017-2019, 2022 Uber Technologies, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *         http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.uber.h3core;
17

18
import com.uber.h3core.util.CoordIJ;
19
import com.uber.h3core.util.LatLng;
20
import java.io.IOException;
21
import java.util.ArrayList;
22
import java.util.Collection;
23
import java.util.Collections;
24
import java.util.List;
25

26
/**
27
 * H3CoreV3 provides all functions of the H3 API with backwards compatible naming for the V3 API.
28
 *
29
 * <p>This class is thread safe and can be used as a singleton. It is implemented on top of {@link
30
 * H3Core}.
31
 *
32
 * <p>Specific exceptions thrown may not be the same as V3.
33
 *
34
 * <p>This class will be removed in a future version of H3-Java.
35
 */
36
public class H3CoreV3 {
37
  /** Native implementation of the H3 library. */
38
  private final H3Core h3Api;
39

40
  /**
41
   * Create by unpacking the H3 native library to disk and loading it. The library will attempt to
42
   * detect the correct operating system and architecture of native library to unpack.
43
   *
44
   * @throws SecurityException Loading the library was not allowed by the SecurityManager.
45
   * @throws UnsatisfiedLinkError The library could not be loaded
46
   * @throws IOException The library could not be extracted to disk.
47
   */
48
  public static H3CoreV3 newInstance() throws IOException {
49
    return new H3CoreV3(H3Core.newInstance());
1✔
50
  }
51

52
  /**
53
   * Create by unpacking the H3 native library to disk and loading it. The library will attempt to
54
   * extract the native library matching the given arguments to disk.
55
   *
56
   * @throws SecurityException Loading the library was not allowed by the SecurityManager.
57
   * @throws UnsatisfiedLinkError The library could not be loaded
58
   * @throws IOException The library could not be extracted to disk.
59
   */
60
  public static H3CoreV3 newInstance(H3CoreLoader.OperatingSystem os, String arch)
61
      throws IOException {
62
    return new H3CoreV3(H3Core.newInstance(os, arch));
1✔
63
  }
64

65
  /**
66
   * Create by using the H3 native library already installed on the system.
67
   *
68
   * @throws SecurityException The library could not be loaded
69
   * @throws UnsatisfiedLinkError The library could not be loaded
70
   */
71
  public static H3CoreV3 newSystemInstance() {
72
    return new H3CoreV3(H3Core.newSystemInstance());
1✔
73
  }
74

75
  /** Construct with the given NativeMethods, from {@link H3CoreLoader}. */
76
  private H3CoreV3(H3Core h3Api) {
1✔
77
    this.h3Api = h3Api;
1✔
78
  }
1✔
79

80
  /** Returns true if this is a valid H3 index. */
81
  public boolean h3IsValid(long h3) {
82
    return h3Api.isValidCell(h3);
1✔
83
  }
84

85
  /** Returns true if this is a valid H3 index. */
86
  public boolean h3IsValid(String h3Address) {
87
    return h3Api.isValidCell(h3Address);
1✔
88
  }
89

90
  /** Returns the base cell number for this index. */
91
  public int h3GetBaseCell(long h3) {
92
    return h3Api.getBaseCellNumber(h3);
1✔
93
  }
94

95
  /** Returns the base cell number for this index. */
96
  public int h3GetBaseCell(String h3Address) {
97
    return h3Api.getBaseCellNumber(h3Address);
1✔
98
  }
99

100
  /** Returns <code>true</code> if this index is one of twelve pentagons per resolution. */
101
  public boolean h3IsPentagon(long h3) {
102
    return h3Api.isPentagon(h3);
1✔
103
  }
104

105
  /** Returns <code>true</code> if this index is one of twelve pentagons per resolution. */
106
  public boolean h3IsPentagon(String h3Address) {
107
    return h3Api.isPentagon(h3Address);
1✔
108
  }
109

110
  /**
111
   * Find the H3 index of the resolution <code>res</code> cell containing the lat/lon (in degrees)
112
   *
113
   * @param lat Latitude in degrees.
114
   * @param lng Longitude in degrees.
115
   * @param res Resolution, 0 &lt;= res &lt;= 15
116
   * @return The H3 index.
117
   */
118
  public long geoToH3(double lat, double lng, int res) {
119
    return h3Api.latLngToCell(lat, lng, res);
1✔
120
  }
121

122
  /**
123
   * Find the H3 index of the resolution <code>res</code> cell containing the lat/lon (in degrees)
124
   *
125
   * @param lat Latitude in degrees.
126
   * @param lng Longitude in degrees.
127
   * @param res Resolution, 0 &lt;= res &lt;= 15
128
   * @return The H3 index.
129
   */
130
  public String geoToH3Address(double lat, double lng, int res) {
131
    return h3Api.latLngToCellAddress(lat, lng, res);
1✔
132
  }
133

134
  /** Find the latitude, longitude (both in degrees) center point of the cell. */
135
  public LatLng h3ToGeo(long h3) {
136
    return h3Api.cellToLatLng(h3);
1✔
137
  }
138

139
  /** Find the latitude, longitude (degrees) center point of the cell. */
140
  public LatLng h3ToGeo(String h3Address) {
141
    return h3Api.cellToLatLng(h3Address);
1✔
142
  }
143

144
  /** Find the cell boundary in latitude, longitude (degrees) coordinates for the cell */
145
  public List<LatLng> h3ToGeoBoundary(long h3) {
146
    return h3Api.cellToBoundary(h3);
1✔
147
  }
148

149
  /** Find the cell boundary in latitude, longitude (degrees) coordinates for the cell */
150
  public List<LatLng> h3ToGeoBoundary(String h3Address) {
151
    return h3Api.cellToBoundary(h3Address);
1✔
152
  }
153

154
  /**
155
   * Neighboring indexes in all directions.
156
   *
157
   * @param h3Address Origin index
158
   * @param k Number of rings around the origin
159
   */
160
  public List<String> kRing(String h3Address, int k) {
161
    return h3Api.gridDisk(h3Address, k);
1✔
162
  }
163

164
  /**
165
   * Neighboring indexes in all directions.
166
   *
167
   * @param h3Address Origin index
168
   * @param k Number of rings around the origin
169
   * @return List of {@link #kRing(String, int)} results.
170
   */
171
  public List<List<String>> kRings(String h3Address, int k) {
172
    List<List<String>> result = new ArrayList<>(k + 1);
1✔
173
    result.add(Collections.singletonList(h3Address));
1✔
174
    for (int i = 1; i <= k; ++i) {
1✔
175
      result.add(kRing(h3Address, i));
1✔
176
    }
177
    return result;
1✔
178
  }
179

180
  /**
181
   * Neighboring indexes in all directions.
182
   *
183
   * @param h3 Origin index
184
   * @param k Number of rings around the origin
185
   */
186
  public List<Long> kRing(long h3, int k) {
187
    return h3Api.gridDisk(h3, k);
1✔
188
  }
189

190
  /**
191
   * Neighboring indexes in all directions, ordered by distance from the origin index.
192
   *
193
   * @param h3Address Origin index
194
   * @param k Number of rings around the origin
195
   * @return A list of rings, each of which is a list of addresses. The rings are in order from
196
   *     closest to origin to farthest.
197
   */
198
  public List<List<String>> kRingDistances(String h3Address, int k) {
199
    return h3Api.gridDiskDistances(h3Address, k);
1✔
200
  }
201

202
  /**
203
   * Neighboring indexes in all directions, ordered by distance from the origin index.
204
   *
205
   * @param h3 Origin index
206
   * @param k Number of rings around the origin
207
   * @return A list of rings, each of which is a list of addresses. The rings are in order from
208
   *     closest to origin to farthest.
209
   */
210
  public List<List<Long>> kRingDistances(long h3, int k) {
211
    return h3Api.gridDiskDistances(h3, k);
1✔
212
  }
213

214
  /**
215
   * Returns in order neighbor traversal.
216
   *
217
   * @param h3Address Origin hexagon index
218
   * @param k Number of rings around the origin
219
   * @return A list of rings, each of which is a list of addresses. The rings are in order from
220
   *     closest to origin to farthest.
221
   */
222
  public List<List<String>> hexRange(String h3Address, int k) {
223
    return h3Api.gridDiskUnsafe(h3Address, k);
1✔
224
  }
225

226
  /**
227
   * Returns in order neighbor traversal.
228
   *
229
   * @param h3 Origin hexagon index
230
   * @param k Number of rings around the origin
231
   * @return A list of rings, each of which is a list of addresses. The rings are in order from
232
   *     closest to origin to farthest.
233
   */
234
  public List<List<Long>> hexRange(long h3, int k) {
235
    return h3Api.gridDiskUnsafe(h3, k);
1✔
236
  }
237

238
  /**
239
   * Returns in order neighbor traversal, of indexes with distance of <code>k</code>.
240
   *
241
   * @param h3Address Origin index
242
   * @param k Number of rings around the origin
243
   * @return All indexes <code>k</code> away from the origin
244
   */
245
  public List<String> hexRing(String h3Address, int k) {
246
    return h3Api.gridRingUnsafe(h3Address, k);
1✔
247
  }
248

249
  /**
250
   * Returns in order neighbor traversal, of indexes with distance of <code>k</code>.
251
   *
252
   * @param h3 Origin index
253
   * @param k Number of rings around the origin
254
   * @return All indexes <code>k</code> away from the origin
255
   */
256
  public List<Long> hexRing(long h3, int k) {
257
    return h3Api.gridRingUnsafe(h3, k);
1✔
258
  }
259

260
  /**
261
   * Returns the distance between <code>a</code> and <code>b</code>. This is the grid distance, or
262
   * distance expressed in number of H3 cells.
263
   *
264
   * <p>In some cases H3 cannot compute the distance between two indexes. This can happen because:
265
   *
266
   * <ul>
267
   *   <li>The indexes are not comparable (difference resolutions, etc)
268
   *   <li>The distance is greater than the H3 core library supports
269
   *   <li>The H3 library does not support finding the distance between the two cells, because of
270
   *       pentagonal distortion.
271
   * </ul>
272
   *
273
   * @param a An H3 index
274
   * @param b Another H3 index
275
   * @return Distance between the two in grid cells
276
   */
277
  public int h3Distance(String a, String b) {
278
    return longToIntDistance(h3Api.gridDistance(a, b));
1✔
279
  }
280

281
  /**
282
   * Returns the distance between <code>a</code> and <code>b</code>. This is the grid distance, or
283
   * distance expressed in number of H3 cells.
284
   *
285
   * <p>In some cases H3 cannot compute the distance between two indexes. This can happen because:
286
   *
287
   * <ul>
288
   *   <li>The indexes are not comparable (difference resolutions, etc)
289
   *   <li>The distance is greater than the H3 core library supports
290
   *   <li>The H3 library does not support finding the distance between the two cells, because of
291
   *       pentagonal distortion.
292
   * </ul>
293
   *
294
   * @param a An H3 index
295
   * @param b Another H3 index
296
   * @return Distance between the two in grid cells
297
   */
298
  public int h3Distance(long a, long b) {
299
    return longToIntDistance(h3Api.gridDistance(a, b));
1✔
300
  }
301

302
  /**
303
   * Converts <code>h3</code> to IJ coordinates in a local coordinate space defined by <code>origin
304
   * </code>.
305
   *
306
   * <p>The local IJ coordinate space may have deleted regions and warping due to pentagon
307
   * distortion. IJ coordinates are only comparable if they came from the same origin.
308
   *
309
   * <p>This function is experimental, and its output is not guaranteed to be compatible across
310
   * different versions of H3.
311
   *
312
   * @param origin Anchoring index for the local coordinate space.
313
   * @param h3 Index to find the coordinates of.
314
   * @return Coordinates for <code>h3</code> in the local coordinate space.
315
   */
316
  public CoordIJ experimentalH3ToLocalIj(long origin, long h3) {
317
    return h3Api.cellToLocalIj(origin, h3);
1✔
318
  }
319

320
  /**
321
   * Converts <code>h3Address</code> to IJ coordinates in a local coordinate space defined by <code>
322
   * originAddress</code>.
323
   *
324
   * <p>The local IJ coordinate space may have deleted regions and warping due to pentagon
325
   * distortion. IJ coordinates are only comparable if they came from the same origin.
326
   *
327
   * <p>This function is experimental, and its output is not guaranteed to be compatible across
328
   * different versions of H3.
329
   *
330
   * @param originAddress Anchoring index for the local coordinate space.
331
   * @param h3Address Index to find the coordinates of.
332
   * @return Coordinates for <code>h3</code> in the local coordinate space.
333
   */
334
  public CoordIJ experimentalH3ToLocalIj(String originAddress, String h3Address) {
335
    return h3Api.cellToLocalIj(originAddress, h3Address);
1✔
336
  }
337

338
  /**
339
   * Converts the IJ coordinates to an index, using a local IJ coordinate space anchored by <code>
340
   * origin</code>.
341
   *
342
   * <p>The local IJ coordinate space may have deleted regions and warping due to pentagon
343
   * distortion. IJ coordinates are only comparable if they came from the same origin.
344
   *
345
   * <p>This function is experimental, and its output is not guaranteed to be compatible across
346
   * different versions of H3.
347
   *
348
   * @param origin Anchoring index for the local coordinate space.
349
   * @param ij Coordinates in the local IJ coordinate space.
350
   * @return Index represented by <code>ij</code>
351
   */
352
  public long experimentalLocalIjToH3(long origin, CoordIJ ij) {
353
    return h3Api.localIjToCell(origin, ij);
1✔
354
  }
355

356
  /**
357
   * Converts the IJ coordinates to an index, using a local IJ coordinate space anchored by <code>
358
   * origin</code>.
359
   *
360
   * <p>The local IJ coordinate space may have deleted regions and warping due to pentagon
361
   * distortion. IJ coordinates are only comparable if they came from the same origin.
362
   *
363
   * <p>This function is experimental, and its output is not guaranteed to be compatible across
364
   * different versions of H3.
365
   *
366
   * @param originAddress Anchoring index for the local coordinate space.
367
   * @param ij Coordinates in the local IJ coordinate space.
368
   * @return Index represented by <code>ij</code>
369
   */
370
  public String experimentalLocalIjToH3(String originAddress, CoordIJ ij) {
371
    return h3Api.localIjToCell(originAddress, ij);
1✔
372
  }
373

374
  /**
375
   * Given two H3 indexes, return the line of indexes between them (inclusive of endpoints).
376
   *
377
   * <p>This function may fail to find the line between two indexes, for example if they are very
378
   * far apart. It may also fail when finding distances for indexes on opposite sides of a pentagon.
379
   *
380
   * <p>Notes:
381
   *
382
   * <ul>
383
   *   <li>The specific output of this function should not be considered stable across library
384
   *       versions. The only guarantees the library provides are that the line length will be
385
   *       `h3Distance(start, end) + 1` and that every index in the line will be a neighbor of the
386
   *       preceding index.
387
   *   <li>Lines are drawn in grid space, and may not correspond exactly to either Cartesian lines
388
   *       or great arcs.
389
   * </ul>
390
   *
391
   * @param startAddress Start index of the line
392
   * @param endAddress End index of the line
393
   * @return Indexes making up the line.
394
   */
395
  public List<String> h3Line(String startAddress, String endAddress) {
396
    return h3Api.gridPathCells(startAddress, endAddress);
1✔
397
  }
398

399
  /**
400
   * Given two H3 indexes, return the line of indexes between them (inclusive of endpoints).
401
   *
402
   * <p>This function may fail to find the line between two indexes, for example if they are very
403
   * far apart. It may also fail when finding distances for indexes on opposite sides of a pentagon.
404
   *
405
   * <p>Notes:
406
   *
407
   * <ul>
408
   *   <li>The specific output of this function should not be considered stable across library
409
   *       versions. The only guarantees the library provides are that the line length will be
410
   *       `h3Distance(start, end) + 1` and that every index in the line will be a neighbor of the
411
   *       preceding index.
412
   *   <li>Lines are drawn in grid space, and may not correspond exactly to either Cartesian lines
413
   *       or great arcs.
414
   * </ul>
415
   *
416
   * @param start Start index of the line
417
   * @param end End index of the line
418
   * @return Indexes making up the line.
419
   */
420
  public List<Long> h3Line(long start, long end) {
421
    return h3Api.gridPathCells(start, end);
1✔
422
  }
423

424
  /**
425
   * Finds indexes within the given geofence.
426
   *
427
   * @param points Outline geofence
428
   * @param holes Geofences of any internal holes
429
   * @param res Resolution of the desired indexes
430
   */
431
  public List<String> polyfillAddress(List<LatLng> points, List<List<LatLng>> holes, int res) {
432
    return h3Api.polygonToCellAddresses(points, holes, res);
1✔
433
  }
434

435
  /**
436
   * Finds indexes within the given geofence.
437
   *
438
   * @param points Outline geofence
439
   * @param holes Geofences of any internal holes
440
   * @param res Resolution of the desired indexes
441
   */
442
  public List<Long> polyfill(List<LatLng> points, List<List<LatLng>> holes, int res) {
443
    return h3Api.polygonToCells(points, holes, res);
1✔
444
  }
445

446
  /** Create polygons from a set of contiguous indexes */
447
  public List<List<List<LatLng>>> h3AddressSetToMultiPolygon(
448
      Collection<String> h3Addresses, boolean geoJson) {
449
    return h3Api.cellAddressesToMultiPolygon(h3Addresses, geoJson);
1✔
450
  }
451

452
  /** Create polygons from a set of contiguous indexes */
453
  public List<List<List<LatLng>>> h3SetToMultiPolygon(Collection<Long> h3, boolean geoJson) {
454
    return h3Api.cellsToMultiPolygon(h3, geoJson);
1✔
455
  }
456

457
  /** Returns the resolution of the provided index */
458
  public int h3GetResolution(String h3Address) {
459
    return h3Api.getResolution(h3Address);
1✔
460
  }
461

462
  /** Returns the resolution of the provided index */
463
  public int h3GetResolution(long h3) {
464
    return h3Api.getResolution(h3);
1✔
465
  }
466

467
  /**
468
   * Returns the parent of the index at the given resolution.
469
   *
470
   * @param h3 H3 index.
471
   * @param res Resolution of the parent, <code>0 &lt;= res &lt;= h3GetResolution(h3)</code>
472
   * @throws IllegalArgumentException <code>res</code> is not between 0 and the resolution of <code>
473
   *     h3</code>, inclusive.
474
   */
475
  public long h3ToParent(long h3, int res) {
476
    return h3Api.cellToParent(h3, res);
1✔
477
  }
478

479
  /**
480
   * Returns the parent of the index at the given resolution.
481
   *
482
   * @param h3Address H3 index.
483
   * @param res Resolution of the parent, <code>0 &lt;= res &lt;= h3GetResolution(h3)</code>
484
   */
485
  public String h3ToParentAddress(String h3Address, int res) {
486
    return h3Api.cellToParentAddress(h3Address, res);
1✔
487
  }
488

489
  /**
490
   * Provides the children of the index at the given resolution.
491
   *
492
   * @param childRes Resolution of the children
493
   */
494
  public List<String> h3ToChildren(String h3Address, int childRes) {
495
    return h3Api.cellToChildren(h3Address, childRes);
1✔
496
  }
497

498
  /**
499
   * Provides the children of the index at the given resolution.
500
   *
501
   * @param h3 H3 index.
502
   * @param childRes Resolution of the children
503
   * @throws IllegalArgumentException Invalid resolution
504
   */
505
  public List<Long> h3ToChildren(long h3, int childRes) {
506
    return h3Api.cellToChildren(h3, childRes);
1✔
507
  }
508

509
  /**
510
   * Returns the center child at the given resolution.
511
   *
512
   * @param h3 Parent H3 index
513
   * @param childRes Resolution of the child
514
   */
515
  public String h3ToCenterChild(String h3, int childRes) {
516
    return h3Api.cellToCenterChild(h3, childRes);
1✔
517
  }
518

519
  /**
520
   * Returns the center child at the given resolution.
521
   *
522
   * @param h3 Parent H3 index
523
   * @param childRes Resolution of the child
524
   */
525
  public long h3ToCenterChild(long h3, int childRes) {
526
    return h3Api.cellToCenterChild(h3, childRes);
1✔
527
  }
528

529
  /**
530
   * Determines if an index is Class III or Class II.
531
   *
532
   * @return <code>true</code> if the index is Class III
533
   */
534
  public boolean h3IsResClassIII(String h3Address) {
535
    return h3Api.isResClassIII(h3Address);
1✔
536
  }
537

538
  /**
539
   * Determines if an index is Class III or Class II.
540
   *
541
   * @param h3 H3 index.
542
   * @return <code>true</code> if the index is Class III
543
   */
544
  public boolean h3IsResClassIII(long h3) {
545
    return h3Api.isResClassIII(h3);
1✔
546
  }
547

548
  /** Returns a compacted set of indexes, at possibly coarser resolutions. */
549
  public List<String> compactAddress(Collection<String> h3Addresses) {
550
    return h3Api.compactCellAddresses(h3Addresses);
1✔
551
  }
552

553
  /** Returns a compacted set of indexes, at possibly coarser resolutions. */
554
  public List<Long> compact(Collection<Long> h3) {
555
    return h3Api.compactCells(h3);
1✔
556
  }
557

558
  /** Uncompacts all the given indexes to resolution <code>res</code>. */
559
  public List<String> uncompactAddress(Collection<String> h3Addresses, int res) {
560
    return h3Api.uncompactCellAddresses(h3Addresses, res);
1✔
561
  }
562

563
  /** Uncompacts all the given indexes to resolution <code>res</code>. */
564
  public List<Long> uncompact(Collection<Long> h3, int res) {
565
    return h3Api.uncompactCells(h3, res);
1✔
566
  }
567

568
  /**
569
   * Converts from <code>long</code> representation of an index to <code>String</code>
570
   * representation.
571
   */
572
  public String h3ToString(long h3) {
573
    return Long.toHexString(h3);
1✔
574
  }
575

576
  /**
577
   * Converts from <code>String</code> representation of an index to <code>long</code>
578
   * representation.
579
   */
580
  public long stringToH3(String h3Address) {
581
    return Long.parseUnsignedLong(h3Address, 16);
1✔
582
  }
583

584
  /**
585
   * Calculates the area of the given H3 cell.
586
   *
587
   * @param h3Address Cell to find the area of.
588
   * @param unit Unit to calculate the area in.
589
   * @return Cell area in the given units.
590
   */
591
  public double cellArea(String h3Address, AreaUnit unit) {
592
    return h3Api.cellArea(h3Address, unit);
1✔
593
  }
594

595
  /**
596
   * Calculates the area of the given H3 cell.
597
   *
598
   * @param h3 Cell to find the area of.
599
   * @param unit Unit to calculate the area in.
600
   * @return Cell area in the given units.
601
   */
602
  public double cellArea(long h3, AreaUnit unit) {
603
    return h3Api.cellArea(h3, unit);
1✔
604
  }
605

606
  /**
607
   * Return the distance along the sphere between two points.
608
   *
609
   * @param a First point
610
   * @param b Second point
611
   * @param unit Unit to return the distance in.
612
   * @return Distance from point <code>a</code> to point <code>b</code>
613
   */
614
  public double pointDist(LatLng a, LatLng b, LengthUnit unit) {
615
    return h3Api.greatCircleDistance(a, b, unit);
1✔
616
  }
617

618
  /**
619
   * Calculate the edge length of the given H3 edge.
620
   *
621
   * @param edgeAddress Edge to find the edge length of.
622
   * @param unit Unit of measure to use.
623
   * @return Length of the given edge.
624
   */
625
  public double exactEdgeLength(String edgeAddress, LengthUnit unit) {
626
    return h3Api.edgeLength(edgeAddress, unit);
1✔
627
  }
628

629
  /**
630
   * Calculate the edge length of the given H3 edge.
631
   *
632
   * @param edge Edge to find the edge length of.
633
   * @param unit Unit of measure to use.
634
   * @return Length of the given edge.
635
   */
636
  public double exactEdgeLength(long edge, LengthUnit unit) {
637
    return h3Api.edgeLength(edge, unit);
1✔
638
  }
639

640
  /**
641
   * Returns the average area in <code>unit</code> for indexes at resolution <code>res</code>.
642
   *
643
   * @throws IllegalArgumentException Invalid parameter value
644
   */
645
  public double hexArea(int res, AreaUnit unit) {
646
    return h3Api.getHexagonAreaAvg(res, unit);
1✔
647
  }
648

649
  /**
650
   * Returns the average edge length in <code>unit</code> for indexes at resolution <code>res</code>
651
   * .
652
   *
653
   * @throws IllegalArgumentException Invalid parameter value
654
   */
655
  public double edgeLength(int res, LengthUnit unit) {
656
    return h3Api.getHexagonEdgeLengthAvg(res, unit);
1✔
657
  }
658

659
  /** Returns the number of unique H3 indexes at resolution <code>res</code>. */
660
  public long numHexagons(int res) {
661
    return h3Api.getNumCells(res);
1✔
662
  }
663

664
  /** Returns a collection of all base cells (H3 indexes are resolution 0). */
665
  public Collection<String> getRes0IndexesAddresses() {
666
    return h3Api.getRes0CellAddresses();
1✔
667
  }
668

669
  /** Returns a collection of all base cells (H3 indexes are resolution 0). */
670
  public Collection<Long> getRes0Indexes() {
671
    return h3Api.getRes0Cells();
1✔
672
  }
673

674
  /** Returns a collection of all topologically pentagonal cells at the given resolution. */
675
  public Collection<String> getPentagonIndexesAddresses(int res) {
676
    return h3Api.getPentagonAddresses(res);
1✔
677
  }
678

679
  /** Returns a collection of all topologically pentagonal cells at the given resolution. */
680
  public Collection<Long> getPentagonIndexes(int res) {
681
    return h3Api.getPentagons(res);
1✔
682
  }
683

684
  /** Returns <code>true</code> if the two indexes are neighbors. */
685
  public boolean h3IndexesAreNeighbors(long a, long b) {
686
    return h3Api.areNeighborCells(a, b);
1✔
687
  }
688

689
  /** Returns <code>true</code> if the two indexes are neighbors. */
690
  public boolean h3IndexesAreNeighbors(String a, String b) {
691
    return h3Api.areNeighborCells(a, b);
1✔
692
  }
693

694
  /** Returns a unidirectional edge index representing <code>a</code> towards <code>b</code>. */
695
  public long getH3UnidirectionalEdge(long a, long b) {
696
    return h3Api.cellsToDirectedEdge(a, b);
1✔
697
  }
698

699
  /** Returns a unidirectional edge index representing <code>a</code> towards <code>b</code>. */
700
  public String getH3UnidirectionalEdge(String a, String b) {
701
    return h3Api.cellsToDirectedEdge(a, b);
1✔
702
  }
703

704
  /** Returns <code>true</code> if the given index is a valid unidirectional edge. */
705
  public boolean h3UnidirectionalEdgeIsValid(long h3) {
706
    return h3Api.isValidDirectedEdge(h3);
1✔
707
  }
708

709
  /** Returns <code>true</code> if the given index is a valid unidirectional edge. */
710
  public boolean h3UnidirectionalEdgeIsValid(String h3) {
711
    return h3Api.isValidDirectedEdge(h3);
1✔
712
  }
713

714
  /** Returns the origin index of the given unidirectional edge. */
715
  public long getOriginH3IndexFromUnidirectionalEdge(long h3) {
716
    return h3Api.getDirectedEdgeOrigin(h3);
1✔
717
  }
718

719
  /** Returns the origin index of the given unidirectional edge. */
720
  public String getOriginH3IndexFromUnidirectionalEdge(String h3) {
721
    return h3Api.getDirectedEdgeOrigin(h3);
1✔
722
  }
723

724
  /** Returns the destination index of the given unidirectional edge. */
725
  public long getDestinationH3IndexFromUnidirectionalEdge(long h3) {
726
    return h3Api.getDirectedEdgeDestination(h3);
1✔
727
  }
728

729
  /** Returns the destination index of the given unidirectional edge. */
730
  public String getDestinationH3IndexFromUnidirectionalEdge(String h3) {
731
    return h3Api.getDirectedEdgeDestination(h3);
1✔
732
  }
733

734
  /**
735
   * Returns the origin and destination indexes (in that order) of the given unidirectional edge.
736
   */
737
  public List<Long> getH3IndexesFromUnidirectionalEdge(long h3) {
738
    return h3Api.directedEdgeToCells(h3);
1✔
739
  }
740

741
  /**
742
   * Returns the origin and destination indexes (in that order) of the given unidirectional edge.
743
   */
744
  public List<String> getH3IndexesFromUnidirectionalEdge(String h3) {
745
    return h3Api.directedEdgeToCells(h3);
1✔
746
  }
747

748
  /** Returns all unidirectional edges originating from the given index. */
749
  public List<Long> getH3UnidirectionalEdgesFromHexagon(long h3) {
750
    return h3Api.originToDirectedEdges(h3);
1✔
751
  }
752

753
  /** Returns all unidirectional edges originating from the given index. */
754
  public List<String> getH3UnidirectionalEdgesFromHexagon(String h3) {
755
    return h3Api.originToDirectedEdges(h3);
1✔
756
  }
757

758
  /** Returns a list of coordinates representing the given edge. */
759
  public List<LatLng> getH3UnidirectionalEdgeBoundary(long h3) {
760
    return h3Api.directedEdgeToBoundary(h3);
1✔
761
  }
762

763
  /** Returns a list of coordinates representing the given edge. */
764
  public List<LatLng> getH3UnidirectionalEdgeBoundary(String h3) {
765
    return h3Api.directedEdgeToBoundary(h3);
1✔
766
  }
767

768
  /**
769
   * Find all icosahedron faces intersected by a given H3 index, represented as integers from 0-19.
770
   *
771
   * @param h3 Index to find icosahedron faces for.
772
   * @return A collection of faces intersected by the index.
773
   */
774
  public Collection<Integer> h3GetFaces(String h3) {
775
    return h3Api.getIcosahedronFaces(h3);
1✔
776
  }
777

778
  /**
779
   * Find all icosahedron faces intersected by a given H3 index, represented as integers from 0-19.
780
   *
781
   * @param h3 Index to find icosahedron faces for.
782
   * @return A collection of faces intersected by the index.
783
   */
784
  public Collection<Integer> h3GetFaces(long h3) {
785
    return h3Api.getIcosahedronFaces(h3);
1✔
786
  }
787

788
  /**
789
   * @throws IllegalArgumentException <code>sz</code> cannot be losslessly cast to an <code>int
790
   *     </code>
791
   */
792
  private static int longToIntDistance(long sz) {
793
    if (sz < 0 || sz > Integer.MAX_VALUE) {
1✔
794
      throw new IllegalArgumentException(String.format("Distance %d is out of range", sz));
×
795
    }
796
    return (int) sz;
1✔
797
  }
798
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc