robust

    Robust geometric predicates in MoonBit: orient2d of robust-predicates 3.0.3 (Shewchuk's adaptive-precision arithmetic)

    robust-predicates
    orient2d
    geometry
    shewchuk
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0 AND Unlicense
    Last updated
    5 hours ago
    Downloads
    3

    No dependencies

    #robust

    Robust geometric predicates in MoonBit: orient2d of robust-predicates 3.0.3, after Jonathan Shewchuk's adaptive-precision arithmetic. The result is bit for bit the JavaScript library's, on every MoonBit backend (wasm, wasm-gc, js, native). No dependencies besides moonbitlang/core.

    Part of mbt-map, a WebGIS library, published on its own.

    moon add t-ujiie-g/robust

    test "orient2d" {
    // Twice the signed area of the triangle a, b, c; the sign is exact.
    assert_true(@robust.orient2d(0, 0, 1, 0, 0, 1) < 0) // counter-clockwise (y up)
    assert_true(@robust.orient2d(0, 0, 0, 1, 1, 0) > 0) // clockwise
    assert_true(@robust.orient2d(0, 0, 1, 1, 2, 2) == 0) // collinear
    }

    orient2d(ax, ay, bx, by, cx, cy) is positive when a, b, c turn clockwise in a y-up frame, negative when counter-clockwise and 0 when collinear, also where plain floating-point arithmetic would get the sign wrong. Only orient2d is ported (not orient3d, incircle or insphere).

    #License

    Apache-2.0 for the port; robust-predicates is under the Unlicense (see NOTICE).

    orient2d

    fn orient2d(ax : Double, ay : Double, bx : Double, by : Double, cx : Double, cy : Double) -> Double

    Twice the signed area of the triangle a, b, c, exact in sign: positive when clockwise in a y-up frame, negative counter-clockwise, 0 when collinear. Bit for bit robust-predicates 3.0.3's orient2d.

    Source Files