Pure MoonBit implementation of H3 indexing, traversal, and spatial metrics.
moon add LC6543/h3@0.10.1///|
test {
let index = @h3.H3Index::parse("8928308280fffff").unwrap()
assert_eq(index.resolution(), 9)
assert_eq(index.base_cell(), 20)
assert_eq(index.parent(7).unwrap().to_string(), "872830828ffffff")
let center = index.to_lat_lng()
assert_true(center.latitude().is_close(37.77670234943567))
assert_true(center.longitude().is_close(-122.41845932318309))
let same_cell = @h3.H3Index::from_lat_lng(
37.77670234943567, -122.41845932318309, 9,
).unwrap()
assert_eq(same_cell.to_string(), "8928308280fffff")
assert_eq(index.grid_disk(1).unwrap().length(), 7)
let neighbor = @h3.H3Index::parse("89283082803ffff").unwrap()
assert_true(index.is_neighbor_of(neighbor))
assert_eq(index.grid_ring(1).unwrap().length(), 6)
assert_eq(index.grid_disk_distances(1).unwrap().length(), 7)
assert_eq(@h3.resolution_cell_count(9).unwrap(), 4842432842UL)
assert_true(index.great_circle_distance_km(neighbor).is_close(0.3547928245))
assert_eq(index.grid_distance_to(neighbor).unwrap(), 1)
assert_eq(index.to_string(), "8928308280fffff")
}match @h3.H3Index::parse("8928308280zzfff") {
Ok(index) => println(index.to_string())
Err(InvalidCharacter(ch)) => println("invalid character: \{ch}")
Err(_) => println("invalid H3 index")
}moon run examples/basicmoon check --target all
moon build --target all
moon test --target all
moon check --fmt
moon packagelet EARTH_RADIUS_KM : Doublelet MAX_GRID_DISK_RADIUS : Intlet NUM_BASE_CELLS : Intfn is_valid_index(value : UInt64) -> BoolInstall
Download zipPure MoonBit implementation of H3 indexing, traversal, and spatial metrics.