Skip to main content

Python port of d3-delaunay (Delaunay triangulation and Voronoi diagrams)

Project description

pyd3js-delaunay

PyPI version Python versions License CI Security

Python port of d3-delaunay for Delaunay triangulation and Voronoi diagrams, aligned with the other pyd3js packages.

Tracked upstream: d3-delaunay@6.0.4 — see upstream_lock.json.

Requirements: Python 3.10+.

What is d3-delaunay?

d3-delaunay builds a Delaunay triangulation from planar points and derives a Voronoi diagram (clipped to a viewport). It is the standard geometric core D3 uses for mesh and Voronoi layouts.

This package gives you the same workflow in Python: construct a Delaunay, optionally call voronoi(bounds), and use render helpers that return SVG path strings (like upstream).

What you get

  • Delaunay and Voronoi matching the pinned upstream API (see compatibility matrix below).
  • Pure Python tests: upstream Mocha suites are ported to pytest (no Node.js / npm gate).
  • py.typed and type-checked public surface (see Development).

Quickstart (verified)

Flat coordinates match upstream new Delaunay(points):

from array import array
from pyd3js_delaunay import Delaunay

coords = array("d", [0, 0, 1, 0, 0, 1])
d = Delaunay(coords)
v = d.voronoi([0, 0, 1, 1])
print(list(d.hull), v.render_bounds())
[0, 2, 1] M0,0h1v1h-1Z

Point lists use Delaunay.from_points (same idea as JS Delaunay.from):

from pyd3js_delaunay import Delaunay

d = Delaunay.from_points([[0, 0], [1, 0], [0, 1]])
print(list(d.triangles))
[0, 2, 1]

If bounds is omitted, d.voronoi() uses the upstream default [0, 0, 960, 500].

Install

From PyPI:

pip install pyd3js-delaunay

This repo is a uv workspace. For local development:

uv sync --group dev

Dependencies

Triangulation topology (triangles, halfedges, hull) comes from dylaunator ==0.1.0 (Python port of mapbox/delaunator), which uses pyrobust-predicates for adaptive-precision orient2d — the same dependency chain as JavaScript (delaunatorrobust-predicates).

Compatibility matrix

Symbols match upstream exports listed in docs/UPSTREAM_API.md.

  • Delaunay — [implemented]
  • Voronoi — [implemented]

The Python package also exports __version__.

JavaScript naming

Methods are snake_case in Python. Voronoi additionally exposes camelCase aliases (renderCell, renderBounds, cellPolygon, cellPolygons). Internal Path / Polygon helpers use canvas-style names (moveTo, lineTo, closePath).

No Node / npm

Runtime and tests do not require Node.js, npm, or a JavaScript oracle.

Documentation

Development

uv run pytest packages/pyd3js-delaunay/package_tests -q
uv run ruff format packages/pyd3js-delaunay
uv run ruff check packages/pyd3js-delaunay
uv run ty check packages/pyd3js-delaunay

Coverage (optional)

uv run pytest packages/pyd3js-delaunay/package_tests --cov=pyd3js_delaunay --cov-report=term-missing

Build

uv build packages/pyd3js-delaunay

README and user guide Python snippets are checked by package_tests/test_delaunay_docs_examples.py.

Releasing (PyPI)

  1. Ensure dylaunator 0.1.0 is published (this package pins it exactly).
  2. From the monorepo root:
uv build packages/pyd3js-delaunay

Upload dist/pyd3js_delaunay-*.whl and dist/pyd3js_delaunay-*.tar.gz (for example with twine upload or uv publish). Bump version in pyproject.toml and add a section here before each new release.

License

ISC — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyd3js_delaunay-0.1.0.tar.gz (3.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyd3js_delaunay-0.1.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file pyd3js_delaunay-0.1.0.tar.gz.

File metadata

  • Download URL: pyd3js_delaunay-0.1.0.tar.gz
  • Upload date:
  • Size: 3.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for pyd3js_delaunay-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b934811ce8682ca7b100d86c5a54ac9a3617ea33bf35fb81e435fb6aa8917553
MD5 d6d3665725d27143dc9286d365b778f0
BLAKE2b-256 fd3ef6c5b0e77cc58f0fe615948884461246502ec8df03008776bf43c2b0fc72

See more details on using hashes here.

File details

Details for the file pyd3js_delaunay-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pyd3js_delaunay-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c3926fe1e4e8f37d774392e055a2b7d73885f219cf8d90ad50ede05e5f98a15
MD5 6bfce37b35eeccd38dbb5e8033267a61
BLAKE2b-256 69c30bd9dba5b9b34af220e93c1d3dcee183f5386e8b51203ba5bb0b6270a99e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page