# jcash/voronoi architecture

> Architecture diagram of the GitHub repository jcash/voronoi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jcash/voronoi
- Repository: https://github.com/jcash/voronoi

## Overview

jc_voronoi is a header-only C library for generating 2D Voronoi diagrams, with optional clipping and a JavaScript/WebAssembly API. The main user workflow is supplying sites and bounds, generating a diagram, then reading its edges, cells, and neighbors. The repository also includes a browser demo for editing and exporting diagrams, plus a C example that writes images or SVG. Some demo and C-example implementation details are unsampled; uncertain links are omitted or marked unverified.

Main entry points: [`site/app.js`](https://github.com/jcash/voronoi/blob/dev/site/app.js) (Interactive diagram editor), [`src/main.c`](https://github.com/jcash/voronoi/blob/dev/src/main.c) (CLI diagram example), [`src/jc_voronoi.h`](https://github.com/jcash/voronoi/blob/dev/src/jc_voronoi.h) (Voronoi generation), [`wasm/voronoi.js`](https://github.com/jcash/voronoi/blob/dev/wasm/voronoi.js) (JavaScript diagram API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_engine["Diagram engine"]
  node_engine["Voronoi generation<br/>[jc_voronoi.h]"]
  node_clip["Custom polygon clipping<br/>[jc_voronoi_clip.h]"]
end

subgraph group_wasm["WebAssembly API"]
  node_wasm_bridge["Wasm generation and packing<br/>[voronoi_wasm.c]"]
  node_js_api["JavaScript diagram API<br/>[voronoi.js]"]
  node_worker["One-shot worker<br/>[voronoi.worker.js]"]
end

subgraph group_demo["Browser demo"]
  node_demo_app["Interactive diagram editor<br/>[app.js]"]
  node_point_file["Point-file import<br/>[point_file.js]"]
  node_json_export["Diagram JSON export<br/>[diagram_json.js]"]
end

subgraph group_example["C example"]
  node_c_example["CLI diagram example<br/>[main.c]"]
  node_image_writer["Image writing<br/>[stb_image_write.h]"]
  node_image_wrapper["PNG wrapper<br/>[stb_wrapper.c]"]
end

node_user(("Library user"))
node_sites["Sites and bounds"]

node_user -->|"provides"| node_sites
node_sites -->|"supplies input"| node_engine
node_engine -.->|"uses optional clipper"| node_clip
node_user -->|"runs example"| node_c_example
node_c_example -->|"generates diagram"| node_engine
node_c_example -.->|"configures clipping"| node_clip
node_c_example -.->|"writes PNG"| node_image_wrapper
node_image_wrapper -->|"calls writer"| node_image_writer
node_user -->|"loads API"| node_js_api
node_js_api -->|"generates diagram"| node_wasm_bridge
node_wasm_bridge -->|"calls generator"| node_engine
node_user -->|"requests generation"| node_worker
node_worker -->|"loads API"| node_js_api
node_user -->|"edits sites"| node_demo_app
node_demo_app -->|"reads points"| node_point_file
node_demo_app -->|"generates diagram"| node_js_api
node_demo_app -->|"exports diagram"| node_json_export

click node_engine "https://github.com/jcash/voronoi/blob/dev/src/jc_voronoi.h"
click node_clip "https://github.com/jcash/voronoi/blob/dev/src/jc_voronoi_clip.h"
click node_c_example "https://github.com/jcash/voronoi/blob/dev/src/main.c"
click node_image_writer "https://github.com/jcash/voronoi/blob/dev/src/stb_image_write.h"
click node_image_wrapper "https://github.com/jcash/voronoi/blob/dev/src/stb_wrapper.c"
click node_wasm_bridge "https://github.com/jcash/voronoi/blob/dev/wasm/voronoi_wasm.c"
click node_js_api "https://github.com/jcash/voronoi/blob/dev/wasm/voronoi.js"
click node_worker "https://github.com/jcash/voronoi/blob/dev/wasm/voronoi.worker.js"
click node_demo_app "https://github.com/jcash/voronoi/blob/dev/site/app.js"
click node_point_file "https://github.com/jcash/voronoi/blob/dev/site/point_file.js"
click node_json_export "https://github.com/jcash/voronoi/blob/dev/site/diagram_json.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_engine,node_clip,node_user toneBlue
class node_wasm_bridge,node_js_api,node_worker toneAmber
class node_demo_app,node_point_file,node_json_export toneMint
class node_c_example,node_image_writer,node_image_wrapper toneRose
class node_sites toneIndigo
```

## Components

### Diagram engine

- [Voronoi generation](https://github.com/jcash/voronoi/blob/dev/src/jc_voronoi.h): `src/jc_voronoi.h`
- [Custom polygon clipping](https://github.com/jcash/voronoi/blob/dev/src/jc_voronoi_clip.h): `src/jc_voronoi_clip.h`

### WebAssembly API

- [Wasm generation and packing](https://github.com/jcash/voronoi/blob/dev/wasm/voronoi_wasm.c): `wasm/voronoi_wasm.c`
- [JavaScript diagram API](https://github.com/jcash/voronoi/blob/dev/wasm/voronoi.js): `wasm/voronoi.js`
- [One-shot worker](https://github.com/jcash/voronoi/blob/dev/wasm/voronoi.worker.js): `wasm/voronoi.worker.js`

### Browser demo

- [Interactive diagram editor](https://github.com/jcash/voronoi/blob/dev/site/app.js): `site/app.js`
- [Point-file import](https://github.com/jcash/voronoi/blob/dev/site/point_file.js): `site/point_file.js`
- [Diagram JSON export](https://github.com/jcash/voronoi/blob/dev/site/diagram_json.js): `site/diagram_json.js`

### C example

- [CLI diagram example](https://github.com/jcash/voronoi/blob/dev/src/main.c): `src/main.c`
- [Image writing](https://github.com/jcash/voronoi/blob/dev/src/stb_image_write.h): `src/stb_image_write.h`
- [PNG wrapper](https://github.com/jcash/voronoi/blob/dev/src/stb_wrapper.c): `src/stb_wrapper.c`

### Other components

- **Library user**
- **Sites and bounds**

## Connections

- Library user → Sites and bounds: provides (evidence: `README.md`)
- Sites and bounds → Voronoi generation: supplies input (evidence: `README.md`)
- Voronoi generation → Custom polygon clipping: uses optional clipper (evidence: `src/jc_voronoi_clip.h`)
- Library user → CLI diagram example: runs example (evidence: `README.md`)
- CLI diagram example → Voronoi generation: generates diagram (evidence: `src/main.c`)
- CLI diagram example → Custom polygon clipping: configures clipping (evidence: `src/main.c`)
- CLI diagram example → PNG wrapper: writes PNG
- PNG wrapper → Image writing: calls writer (evidence: `src/stb_wrapper.c`)
- Library user → JavaScript diagram API: loads API (evidence: `README.md`)
- JavaScript diagram API → Wasm generation and packing: generates diagram (evidence: `README.md`)
- Wasm generation and packing → Voronoi generation: calls generator (evidence: `wasm/voronoi_wasm.c`)
- Library user → One-shot worker: requests generation (evidence: `README.md`)
- One-shot worker → JavaScript diagram API: loads API (evidence: `wasm/voronoi.worker.js`)
- Library user → Interactive diagram editor: edits sites (evidence: `README.md`)
- Interactive diagram editor → Point-file import: reads points (evidence: `site/app.js`)
- Interactive diagram editor → JavaScript diagram API: generates diagram (evidence: `README.md`)
- Interactive diagram editor → Diagram JSON export: exports diagram (evidence: `site/app.js`)
