Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
geo / geo-h3-cell-to-boundaryOpenRuns on Liberas

H3 cell boundary

The boundary of an H3 (version 4) cell as H3's cellToBoundary gives it: its vertices counter-clockwise, in H3's order and starting vertex, as {lat, lon} in 1e-7 degrees. A hexagon has 6 vertices and a pentagon 5; at odd (Class III) resolutions an edge that crosses an icosahedron edge gets an extra distortion vertex there, so a cell has up to 10. Each vertex is round(radians × (180 ÷ π) × 1e7), half away from zero, and a lon of 1,800,000,000 becomes −1,800,000,000. A cell is written as its 64-bit index in lowercase hexadecimal, 15 digits (every cell index lies in 2^59 … 2^60 − 1). A cell argument is 1 to 16 hex digits in either case and must be a valid H3 cell index (H3's isValidCell: high bit 0, mode 1, resolution 0 … 15, a valid base cell, digits 0 … 6 up to the resolution and 7 after it, no deleted subsequence of a pentagon), else an error. The reference is the h3o crate 0.11.0, which agrees with the H3 C library 4.x. The answer is rounded to integers, so any correct H3 v4 implementation matches except within a hair of a rounding boundary.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init geo-h3-cell-to-boundary --lang rust
cd geo-h3-cell-to-boundary && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)21 lines›
geo-h3-cell-to-boundary.wit
package root:component;

world root {
  import liberas:geo/types@0.1.0;

  export liberas:geo/h3-cell-to-boundary@0.1.0;
}
package liberas:geo@0.1.0 {
  interface types {
    record point-e7 {
      lat: s32,
      lon: s32,
    }
  }
  interface h3-cell-to-boundary {
    use types.{point-e7};

    cell-to-boundary: func(cell: string) -> result<list<point-e7>, string>;
  }
}
Test vectors18›
geo-h3-cell-to-boundary.cases.json
[
  {
    "args": {
      "cell": "8928308280fffff"
    }
  },
  {
    "args": {
      "cell": "8730e1d8cffffff"
    }
  },
  {
    "args": {
      "cell": "8c195da49a2d9ff"
    }
  },
  {
    "args": {
      "cell": "8075fffffffffff"
    }
  },
  {
    "args": {
      "cell": "8fbe0e35cbad0a8"
    }
  },
  {
    "args": {
      "cell": "850d5a97fffffff"
    }
  },
  {
    "args": {
      "cell": "83f293fffffffff"
    }
  },
  {
    "args": {
      "cell": "8403263ffffffff"
    }
  },
  {
    "args": {
      "cell": "8a2a1072b59ffff"
    }
  },
  {
    "args": {
      "cell": "8009fffffffffff"
    }
  },
  {
    "args": {
      "cell": "821c07fffffffff"
    }
  },
  {
    "args": {
      "cell": "85283473fffffff"
    }
  },
  {
    "args": {
      "cell": "81083ffffffffff"
    }
  },
  {
    "args": {
      "cell": "8f28308280FFFFF"
    }
  },
  {
    "args": {
      "cell": ""
    }
  },
  {
    "args": {
      "cell": "8928308280ffff"
    }
  },
  {
    "args": {
      "cell": "89283082807ffff"
    }
  },
  {
    "args": {
      "cell": "ffffffffffffffff"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 18 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 1,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.