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

H3 cell center

The center of an H3 (version 4) cell as H3's cellToLatLng computes it (the center of the cell's hexagon on its icosahedron face, projected back to the sphere), as {lat, lon} in 1e-7 degrees: each 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-lat-lng --lang rust
cd geo-h3-cell-to-lat-lng && 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-lat-lng.wit
package root:component;

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

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

    cell-to-lat-lng: func(cell: string) -> result<point-e7, string>;
  }
}
Test vectors21›
geo-h3-cell-to-lat-lng.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": "8928308280FFFFF"
    }
  },
  {
    "args": {
      "cell": "08928308280fffff"
    }
  },
  {
    "args": {
      "cell": ""
    }
  },
  {
    "args": {
      "cell": "8928308280ffff"
    }
  },
  {
    "args": {
      "cell": "8928308280fffffg"
    }
  },
  {
    "args": {
      "cell": "89283082807ffff"
    }
  },
  {
    "args": {
      "cell": "0"
    }
  },
  {
    "args": {
      "cell": "ffffffffffffffff"
    }
  },
  {
    "args": {
      "cell": "8f28308280fffff"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 21 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%.