Robust planar predicates, dynamic R-tree and explainable region queries
moon version --all
moon check --target all --deny-warn
moon test --target wasm --deny-warn
moon test --target wasm-gc --deny-warn
moon test --target js --deny-warn
moon run cmd/main --target jsmoon add ZYK-ai-nb/moon-geo@0.1.1///|
test {
let a = @geo.Point::new(134217728.0, 134217729.0)
let b = @geo.Point::new(134217729.0, 134217730.0)
let c = @geo.Point::new(0.0, 0.0)
let result = @geo.orientation_report(a, b, c)
assert_eq(result.orientation, @geo.CW)
assert_eq(result.arithmetic, @geo.ExactDyadic)
}moon run examples/predicates --target js///|
test {
let polygon = @geo.Polygon::new([
@geo.Point::new(0.0, 0.0),
@geo.Point::new(1.0, 0.0),
@geo.Point::new(1.0, 1.0),
@geo.Point::new(0.0, 1.0),
])
assert_eq(polygon.locate(@geo.Point::new(0.5, 0.5)).location, @geo.Inside)
let boundary = polygon.locate(@geo.Point::new(1.0, 0.5))
assert_eq(boundary.location, @geo.OnBoundary)
guard boundary.boundary is Some(witness) else { fail("missing boundary") }
assert_eq(witness.ring, 0)
assert_eq(witness.edge, 1)
}moon run examples/regions --target jsmoon run examples/service_area --target js///|
test {
let tree = @geo.RTree::new(capacity=4)
tree.insert(101, @geo.BBox::new(0.0, 0.0, 2.0, 2.0))
tree.insert(102, @geo.BBox::new(10.0, 10.0, 12.0, 12.0))
let found = tree.query(@geo.BBox::new(1.0, 1.0, 3.0, 3.0))
assert_eq(found.entries.map(fn(e) { e.id }), [101])
assert_true(tree.remove(101))
assert_eq(tree.validate(), [])
}moon run examples/dynamic_index --target jspython scripts/generate_oracle.py --checkpub suberror GeoError {
InvalidCoordinate
InvalidBounds
InvalidRing(String)
InvalidPolygon(String)
InvalidCapacity
DuplicateId(Int)
} derive(Debug)pub(all) struct OrientationReport {
orientation : Orientation
arithmetic : ArithmeticPath
} derive(Eq, Debug)type RTreepub(all) struct RangeReport {
entries : Array[SpatialEntry]
nodes_visited : Int
entries_tested : Int
} derive(Debug)pub(all) struct RegionDecision {
id : Int
location : Location
component : Int?
boundary : BoundaryWitness?
} derive(Eq, Debug)type RegionIndexfn RegionIndex::insert_polygon(self : RegionIndex, id : Int, polygon : Polygon) -> Unit raise GeoErrorfn RegionIndex::query_point(self : RegionIndex, p : Point, include_boundary? : Bool, rule? : FillRule) -> RegionQueryReportpub(all) struct RegionQueryReport {
revision : Int
candidates : Int
nodes_visited : Int
entries_tested : Int
hits : Array[Int]
decisions : Array[RegionDecision]
} derive(Debug)Install
Download zipRobust planar predicates, dynamic R-tree and explainable region queries