experimentalH3ToLocalIj method

  1. @override
CoordIJ experimentalH3ToLocalIj(
  1. BigInt origin,
  2. BigInt destination
)
override

Produces IJ coordinates for an H3 index anchored by an origin.

  • The coordinate space used by this function may have deleted regions or warping due to pentagonal distortion.
  • Coordinates are only comparable if they come from the same origin index.
  • Failure may occur if the index is too far away from the origin or if the index is on the other side of a pentagon.
  • This function is experimental, and its output is not guaranteed to be compatible across different versions of H3.

Implementation

@override
CoordIJ experimentalH3ToLocalIj(BigInt origin, BigInt destination) {
  return using((arena) {
    final out = arena<c.CoordIJ>();
    final resultCode = _h3c.experimentalH3ToLocalIj(
      origin.toInt(),
      destination.toInt(),
      out,
    );

    // Switch statement and error codes cribbed from h3-js's implementation.
    switch (resultCode) {
      case 0:
        return out.ref.toPure();
      case 1:
        throw H3Exception('Incompatible origin and index.');
      case 2:
        throw H3Exception(
            'Local IJ coordinates undefined for this origin and index pair. '
            'The index may be too far from the origin.');
      case 3:
      case 4:
      case 5:
        throw H3Exception('Encountered possible pentagon distortion');
      default:
        throw H3Exception(
            'Local IJ coordinates undefined for this origin and index pair. '
            'The index may be too far from the origin.');
    }
  });
}