Skip to main content
Pangolin: Plane Geometry Library

License

⚠️ Work in Progress: This library is still under construction and contains bugs and missing features. Use in production environments is not recommended.

Pangolin (or pgl) is a C++ library for computational geometry in the plane and pypgl is the official python binding for it. It is designed to be pleasant to use and always exact. Calculations are exact using rational numbers (floating point is not accepted).

import pypgl as pgl

p = pgl.Point(1, 0)
q = pgl.Point(4, '15/2')
s = pgl.Segment(p, q)
t = pgl.Segment(0, 8, '7/3', 1)
if s.intersects(t):
    print(s, "intersects", t)
# Output: (1,0)--(4,15/2) intersects (0,8)--(7/3,1)

Shapes and Predicates

Family Shapes
0-dimensional Point
1-dimensional Segment, OrientedSegment, Line, OrientedLine, Ray, Polyline, MonotoneChain
2-dimensional Halfplane, Triangle, Rectangle, Disk, Convex, Polygon

The following predicates are implemented as methods of all shapes.

  • contains(Shape) Does it contain the other shape?
  • boundaryContains(Shape) Does its boundary contain the other shape?
  • interiorContains(Shape) Does it contain the other shape in the interior?
  • intersects(Shape) Do the two shapes intersect?
  • interiorsIntersect(Shape) Do the interiors of the two shapes intersect?
  • separates(Shape) Does one shape cut the other into two (or more) components?
  • crosses(Shape) Do both shapes separate each other?
import pypgl as pgl

o = pgl.Point()      # Point (0,0)
d = pgl.Disk(o, 10)  # Disk of radius 10 centered at (0,0)
if d.contains(o):
    print("Disk contains", o)
diam = d.diameter()
if d.contains(diam):
    print("Disk contains the diameter")
if not d.interiorContains(diam):
    print("Disk's interior does not contain the diameter")
# Output:
# Disk contains (0,0)
# Disk contains the diameter
# Disk's interior does not contain the diameter

Other Methods

Several other methods are supported by the shapes.

import pypgl as pgl

c = pgl.Convex([pgl.Point(0, 0), pgl.Point(1, 0), pgl.Point(1, 2), pgl.Point(0, 1)])
s = c.diameter()
print("The diameter of", c,
      "is defined by", s,
      "and has length", s.length())
# Output: The diameter of Convex[(0,0),(1,0),(1,2),(0,1)] is defined by (0,0)--(1,2) and has length 2.23607

Visualization

A Canvas class is provided for visualization, exporting to SVG, PDF, or Ipe:

import pypgl as pgl

canvas = pgl.Canvas()
canvas.draw(pgl.Point(0, 0))

tri = pgl.Triangle(-1, -1, 0, 2, 1, -2)
canvas.stroke("green")
canvas.draw(tri)
canvas.stroke("blue")
canvas.draw(2*tri)
canvas.writeSVG("example2.svg")

Algorithms and Data Structures

PGL includes fundamental algorithms and data structures such as:

  • Convex hull: convexHull / convexHullExtended, computed with Graham scan.
  • Line segment intersection: sweep-line and brute-force pair enumeration plus detection predicates, all using rational numbers.
  • Sort points: in place by angle (sortAround) or Hilbert order (hilbertSort).
  • Polyomino enumeration: hole-free free polyominoes as Polygon objects.
  • Kd-tree: for points and a generalization for other bounded shapes.
  • Triangulation: including Delaunay and constrained Delaunay triangulations for points and polygons.

Installation

pypgl requires Python 3.9 or newer.

From PyPI

pip install pypgl

Pre-built wheels are published for CPython 3.9–3.13 on Linux (manylinux_2_28, x86_64), macOS (Apple Silicon), and Windows, so most users need no compiler.

From source

Installing from a source tree or directly from GitHub builds the extension locally and therefore needs a C++20 compiler (GCC 12+, Clang 15+, or, on Windows, the LLVM/ClangCL toolset). The header-only pgl library is fetched automatically by CMake — nothing else to install.

pip install git+https://github.com/gfonsecabr/pypgl.git

Development install

Work on the bindings from a checkout with an editable, in-place build:

git clone https://github.com/gfonsecabr/pypgl.git
cd pypgl
python3 -m venv .venv
.venv/bin/pip install scikit-build-core nanobind pytest
.venv/bin/pip install -e . --no-build-isolation
.venv/bin/python -m pytest tests/ -q

--no-build-isolation lets CMake find the venv's nanobind. Re-run the pip install -e . step after editing any src/*.cpp, since the editable install is what rebuilds the extension. To build against a local pgl checkout instead of the pinned upstream commit:

.venv/bin/pip install -e . --no-build-isolation \
  -C cmake.define.PGL_INCLUDE_DIR=/path/to/pgl/include

More Information

Download files

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

Source Distribution

pypgl-0.3.0.tar.gz (887.5 kB view details)

Uploaded Source

Built Distributions

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

pypgl-0.3.0-cp313-cp313-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.13Windows x86-64

pypgl-0.3.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (968.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pypgl-0.3.0-cp313-cp313-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pypgl-0.3.0-cp312-cp312-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.12Windows x86-64

pypgl-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (968.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pypgl-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pypgl-0.3.0-cp311-cp311-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.11Windows x86-64

pypgl-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (965.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pypgl-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pypgl-0.3.0-cp310-cp310-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.10Windows x86-64

pypgl-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (966.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pypgl-0.3.0-cp310-cp310-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pypgl-0.3.0-cp39-cp39-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.9Windows x86-64

pypgl-0.3.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (966.5 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pypgl-0.3.0-cp39-cp39-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file pypgl-0.3.0.tar.gz.

File metadata

  • Download URL: pypgl-0.3.0.tar.gz
  • Upload date:
  • Size: 887.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pypgl-0.3.0.tar.gz
Algorithm Hash digest
SHA256 413d73faa7b4bea37e45045df3049f5bc8bba1f2556c2e518625e341d25c9f76
MD5 78c071731cb2410ca14d4ea7de2205d2
BLAKE2b-256 67ddd94f04ab74ee0b95122c665ab3b05febf72b9d4aad7f2498a1ab03bc9a6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0.tar.gz:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgl-0.3.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pypgl-0.3.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pypgl-0.3.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 16fa26d206fe89e9ebbd6473237425e15d161fed65e42b6642b6ae3b3380382e
MD5 1b9338d133471a7ee827ede57a94db3d
BLAKE2b-256 a41169a259c391cc41f439c38a015abe1b515951fabcfe6b71eefebaf00e3fe5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0-cp313-cp313-win_amd64.whl:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgl-0.3.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 da55c90fb04fa5f35b8e465c757cfd808e12240fc422923f6e1214a575eff7e3
MD5 fc8d767f6655a90ea67080e61540e092
BLAKE2b-256 b7d46207a8004b984a624b8ee74a32b4f92ef1e8beb9c2b60fd734413993d761

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgl-0.3.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b47964b827cb9560cfd77801fd3b1f7e1d479844f7cb677983ca538cb45ba458
MD5 6f9db160fd7f8915469821ebfb9b0b3f
BLAKE2b-256 c8313bf64a14da89e5df4cd781d2f6d6569f573d835691828eb4d34e485ac006

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgl-0.3.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pypgl-0.3.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pypgl-0.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a4a9f025c63809fabbb272e2ce0738bcd109bfb092dc042194fd2292815eb10d
MD5 82be29ed6780e4664055944cbc8bf208
BLAKE2b-256 366380da5308aedb247050e3ea5e9ff072a470f4da5f75763af37643fd7b5a2a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0-cp312-cp312-win_amd64.whl:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgl-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 252122ec0799e6120f399d10fc828fa345c79b3a1298d474093742397af89011
MD5 ee0061474649a46edc531fbeaa3e3625
BLAKE2b-256 7669c1bf76e43cb8f965f4806fed48d629be8324f3c3509cf7a2a78bc0654b5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgl-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 04f6b74a83c78c51eedd3eb6aa474c1eb9a07cbfa349d0cce89bf16d988c437b
MD5 bca558648920ec54e3f174eb2aa0c85b
BLAKE2b-256 44b949eb9e30a38d4fae5488b1971e5e8a0764b64058eaf812b0f6be471814dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgl-0.3.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pypgl-0.3.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pypgl-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 af33aa498835b328288c7ea7e5e172d43f2eed23d0689be33405bcbd523e229e
MD5 dd1ff89f51e71078a8da82d897edf8ca
BLAKE2b-256 d1d1df0fe3b561927f39a0b7b83ff363ae1a6fd9701ce86ef5f888b6d9c3941e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0-cp311-cp311-win_amd64.whl:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgl-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b5fd8e9e24f419f93a6f5d35b1cde399e4d1ba16dca17e10d6201e1a39b7631a
MD5 16ccb6a4be25340d250f80801ba4af98
BLAKE2b-256 a6e76892efb1b8e103a428e707e82ca569a3c286e0ffdba82280e4fd4c34c4f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgl-0.3.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 868cd71351739a438f8d260031254ccad0d49c898f575def94bb34fc02e4323c
MD5 291c829ea3fa0cf13493893b0a9cea7c
BLAKE2b-256 09cf932548d62bf73d3976382017505aaf0ffd25f9a47e8ac651ae8e935932b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgl-0.3.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pypgl-0.3.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pypgl-0.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 cf9d5c41e998f267aeb267d5820ee38de85cfd1d8a7710a5fd2c1515cb402139
MD5 af910053dacbfdd9ebb8409360529828
BLAKE2b-256 daf9496c5078b66c505ef988c08edd35d3dc5506f0a01d4ff1fe9555312dbb44

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0-cp310-cp310-win_amd64.whl:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgl-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 814abdfa9a135e11244d6af7aba3174f29ca4b860bd26578a3b44566b656472d
MD5 c768f6f175b99566244ef928e759a19e
BLAKE2b-256 6ccb5f73ff8f4566050e147fdc162805784daa34b190d66e06d0e2de2b2ef7ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgl-0.3.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 65f80ad4f36c31844a75555a6b9f7c65ffa127dd2ffaf01b1282fa3e893cd873
MD5 07d44a5dd1df1d7af70303cb314c9602
BLAKE2b-256 84920f51014c450121a992b0be71784be9523421c4589f787d3e1786946157db

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgl-0.3.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pypgl-0.3.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pypgl-0.3.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 2a74f0381b5a729ed7536f520f3ae8c6fd2ad7daa757cb410d9913ad91ef8140
MD5 1e87ec89dcf8f5b299111bc30b384a54
BLAKE2b-256 91a39cf45ee516f7db9c9ed409d208632620a6b89894d5cd6e796b1ea2996c6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0-cp39-cp39-win_amd64.whl:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgl-0.3.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 52854cb453d6ee56677eb97db7bd0c10bbd9ee2474e412c3e8b6a2ffc535b189
MD5 6c430b9f4ce6a06290227b4910bdf0a9
BLAKE2b-256 0af75ab7f1a809956d5d6885bc53b5d1bf6b7f07b1d7d5f4fdbb8fa429aef0b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypgl-0.3.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

  • Download URL: pypgl-0.3.0-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.9, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pypgl-0.3.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9602a5f09a79e9df811a27e9b2d104fb9359ac9fa9cc658bf9661b684e62e5ed
MD5 142e0ffaf18154424269efbcf5dac67e
BLAKE2b-256 84cebb612d9acf072e866f4719bc035114283981e081122e413421f84de359cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.0-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: wheels.yml on gfonsecabr/pypgl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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