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.1.tar.gz (887.8 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.1-cp313-cp313-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.13Windows x86-64

pypgl-0.3.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (967.8 kB view details)

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

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

pypgl-0.3.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (967.8 kB view details)

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

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

pypgl-0.3.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (965.7 kB view details)

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

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

pypgl-0.3.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (966.0 kB view details)

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

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.9Windows x86-64

pypgl-0.3.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (966.4 kB view details)

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

pypgl-0.3.1-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.1.tar.gz.

File metadata

  • Download URL: pypgl-0.3.1.tar.gz
  • Upload date:
  • Size: 887.8 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.1.tar.gz
Algorithm Hash digest
SHA256 e9a6b5f17ae0e84a9dcfc0c5afa9b41300e8968602d950a3046fa02560d779f1
MD5 13105709e5826ce821fed8b5b52482d6
BLAKE2b-256 19dd13eaae9ff0b6856bdb37c2693bb93c2330a2be2fba212dade2786d7ab77c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1.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.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pypgl-0.3.1-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.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 89f905243f37c3c03686a31cfe6235ff026dcd946747470702e3c0d0a821836a
MD5 685311f12c0dc3b074adf1937f4ef311
BLAKE2b-256 f34bf4e6f48ffc2f9d864877df8b69433682c6659f01e006d8d7b75aa3893663

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1-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.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 108c45b0524d1bb60e3ddfd976674e269977d9002cd72ddb6edd356e3d083dba
MD5 7796e5d885a27ad097c7e65fc0839815
BLAKE2b-256 f6264a89120cb81e2f665ac80faf704ac54d6456d1c26a3ce4a4f44ba20a4e0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1-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.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 df3f0a392f461e5adb5bf6a79a9010929010df4efad456e494f732c71c831b3d
MD5 2adabd0eda32c19cca46be1f3b98bb98
BLAKE2b-256 954588cbe80fa6d95fb6d8b8815f908938e66c8b5b9cada68cc1c6863bd99fd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1-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.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pypgl-0.3.1-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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 89f2c062d2d8c79a5a9ab04b155b5f5da23c1072ad0053c3729374a13a5ab340
MD5 3050d9ae5e7a76ba905c570e6fa09d60
BLAKE2b-256 9d25002b9954575ad767c7a4a75e07785a1bf2df03998daffb5221c81e8f2f94

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1-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.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ce784d31694736ae02ee033c3cd62e49f31e8023756ab759ecbfd218460e93fe
MD5 9eb0c6bdaad6a5f37013b7df64b6e39c
BLAKE2b-256 279cb145503ca5147e7c4b069ede6f601059d97ce069e100c89468df7bd4ecfe

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1-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.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1bd184183a81967eba6670d768565957d52024386ab169f51468d991e9ebbde2
MD5 c8598dff5a24f3f52ad00ec392ab6e86
BLAKE2b-256 09122a63b3e8ed58d4da526ea239ecfd0d754b2781673575cf4ff7dda425890f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1-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.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pypgl-0.3.1-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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 108fc4a3cd4c673227f0697c95bd21ed82840279b68f079035ea45dddd36231a
MD5 b1339b98d7f9b98025eef7f65a16060e
BLAKE2b-256 f4ac25ae3f6ca3e556e76e8e8d480f7f3ec372818858051d37f1de350676f19c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1-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.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ebc53df080627b85188fa0a0c9c5f4da223b4ded571eb2fd774efe5fa472d07e
MD5 5c6a677d215f1874af8c841920507783
BLAKE2b-256 369f893e196ba7a42d277cb1830d3170d92eb2fbd227230fcf0ee14f28ccd2a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1-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.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6bc8de62454f16744260717063be74978bfa05e2d4c57bb3212ce267f36d6783
MD5 483376454e26713c02e7d1d99852af5e
BLAKE2b-256 905f3cea46cac08d210873703f362ec69dff3e773e7164197367cf5093fed5bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1-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.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pypgl-0.3.1-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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f791825543b12180ada9212175a0622765a8c38e67a099ca17f2ec490ae0126a
MD5 a79aa2709b01440ae01b35d63f94dcf4
BLAKE2b-256 d87c2c126705f4e81bf36dc83c6e3fbc611cd0c423b43b3a35baba687024aa7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1-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.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 47642514f0823a0a6230fa1ad270ee12735d33dd1a06bb8a22aab998b02a1e02
MD5 832cf3af01aea57cf23523a89180a64c
BLAKE2b-256 64e0f335e24f2c807b6fc119c338f3caa6fbde3bd804726f8eb2f2ad5a56efa1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1-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.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e507f01db2751d7e590d41209ff91bd1ec605a29a1dd4042b508176c80929fb7
MD5 503780a875f965ac23a086063b1506e2
BLAKE2b-256 e2964f9e9ee3accb5ab886e7e218a3f72895169c98f333b17807fcc7cb92369d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1-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.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pypgl-0.3.1-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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 828ff363983c5f951959cadefd61d1d1271872807af70dc64b162f3c086c737d
MD5 d2f362ad7e0aa000ab7b6fb2db98a2ae
BLAKE2b-256 02bafff98f1979d54d8bc21d9fdb1b74f1dc66b69625c41d9a028678a694f57f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1-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.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pypgl-0.3.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 536970ea52692653eddaf704d6be363ac556676c1cbb1d4ae0f6389eef4e8ad1
MD5 79b436e29d615e01bfe847c89e98e812
BLAKE2b-256 dc7581a4713363686825ce413c87900829c75aa7e2a624bfbcbcdfa0f65d7369

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1-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.1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

  • Download URL: pypgl-0.3.1-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.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 805acad322d87fb9dc0482bfc072e99d70a504ba6134bc047424cf9db39ba0cc
MD5 2689e3cb52cbd3606564d8dc16cf5c9a
BLAKE2b-256 36862cda989177e4d20353b95d04e0fa745e9beb80b16dedc07badd01ab5dd9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.3.1-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