h3Line method

  1. @override
List<BigInt> h3Line(
  1. BigInt origin,
  2. BigInt destination
)
override

Given two H3 indexes, return the line of indexes between them (inclusive).

This function may fail to find the line between two indexes, for example if they are very far apart. It may also fail when finding distances for indexes on opposite sides of a pentagon.

Notes:

  • The specific output of this function should not be considered stable across library versions. The only guarantees the library provides are that the line length will be h3Distance(start, end) + 1 and that every index in the line will be a neighbor of the preceding index.
  • Lines are drawn in grid space, and may not correspond exactly to either Cartesian lines or great arcs.

Implementation

@override
List<BigInt> h3Line(BigInt origin, BigInt destination) {
  final originInt = origin.toInt();
  final destinationInt = destination.toInt();
  return using((arena) {
    final size = _h3c.h3LineSize(originInt, destinationInt);
    if (size < 0) throw H3Exception('Line cannot be calculated');
    final out = arena<Uint64>(size);
    final resultCode = _h3c.h3Line(originInt, destinationInt, out);
    if (resultCode != 0) throw H3Exception('Line cannot be calculated');
    final list = out.asTypedList(size).toList();
    return list.where((e) => e != 0).map((e) => e.toBigInt()).toList();
  });
}