Robust 2D geometry and observable spatial indexing for MoonBit.
///|
test {
let index = GridSpatialIndex::new(Bounds::new(0.0, 0.0, 100.0, 100.0), 10, 10)
ignore(
index.insert_many([
SpatialItem::new(1, Bounds::new(10.0, 10.0, 14.0, 14.0)),
SpatialItem::new(2, Bounds::new(40.0, 40.0, 42.0, 42.0)),
]),
)
match index.query_nearest(Point::new(16.0, 12.0), 10.0) {
Some(item) => assert_eq(item.id, 1)
None => fail("expected an item")
}
}moon fmt --check
moon check --deny-warn --target all
moon info && git diff --exit-code -- '*.mbti'
moon test --deny-warn --target all
moon run cmd/main --target js
moon run cmd/bench --target jsfn GeometrySummary::new(points : Int, segments : Int, polygons : Int, bounds : Bounds) -> GeometrySummaryfn GridSpatialIndex::query_nearest(self : GridSpatialIndex, point : Point, max_distance : Double) -> SpatialItem?pub(all) struct SpatialQueryResult {
items : Array[SpatialItem]
candidates_scanned : Int
buckets_visited : Int
} derive(Debug)Robust 2D geometry and observable spatial indexing for MoonBit.