packages feed

moonlight-triangulation-1.0.1.0: bindings/README.md

# Foreign bindings

`moonlight-triangulation.cabal` owns a private Haskell `ffi` sublibrary and the
`moonlight-triangulation-c` foreign library. Python, TypeScript, and Rust are
leaf bindings over that sole C ABI; none restates the engine or mesh.

From `compiler`, build and locate the shared library:

```bash
cabal build moonlight-triangulation:flib:moonlight-triangulation-c --enable-shared --project-file=cabal.project.triangulation-dev
cabal list-bin moonlight-triangulation:flib:moonlight-triangulation-c --enable-shared --project-file=cabal.project.triangulation-dev
```

Set `MOONLIGHT_TRIANGULATION_LIBRARY` to that `.dylib`, `.so`, or `.dll`; Rust
linking also reads its directory from `MOONLIGHT_TRIANGULATION_LIB_DIR`.

The ABI accepts interleaved binary64 coordinates and publishes opaque immutable
mesh handles. Set operations and batch insertion return new handles, leaving
inputs valid until freed. Dense vertices and triangles follow vertex-handle and
bounded-face-handle order. Every status-returning call accepts an optional
`ml_obstruction` distinguishing API misuse, capacity refusal, geometric
obstruction, and runtime failure, with retained index, value, coordinate, and
message witnesses. `UINT64_MAX` means no input index applies.

Batch related edits into one `insert_many` call; each call publishes a new mesh,
so repeated singleton calls pay repeated publication costs.

`ml_runtime_initialize` is idempotent and process-lifetime. There is no shutdown
call because GHC cannot reliably restart after its outermost `hs_exit`.

## Python

```python
from moonlight_triangulation import Moonlight
mesh = Moonlight().delaunay([(0, 0), (1, 0), (0, 1)])
print(mesh.vertices, mesh.triangles)
mesh.close()
```

## TypeScript

```typescript
import { Moonlight } from "@moonlight/triangulation";
const mesh = new Moonlight().delaunay([[0, 0], [1, 0], [0, 1]]);
console.log(mesh.vertices(), mesh.triangles());
mesh.close();
```

## Rust

```rust
use moonlight_triangulation::Moonlight;
let mesh = Moonlight::initialize()?.delaunay(&[[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]])?;
println!("{:?} {:?}", mesh.vertices()?, mesh.triangles()?);
```