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. It accepts integer and rational coordinates, but rejects floating point numbers.

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, PolyFunction
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 SVG visualization:

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: computed with Graham scan.
  • Line segment intersection: Bentley-Ottmann sweep line using rational numbers.
  • Sort points: by angle or Hilbert order.
  • 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.1.1.tar.gz (863.2 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.1.1-cp313-cp313-win_amd64.whl (647.8 kB view details)

Uploaded CPython 3.13Windows x86-64

pypgl-0.1.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (501.2 kB view details)

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

pypgl-0.1.1-cp313-cp313-macosx_11_0_arm64.whl (531.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pypgl-0.1.1-cp312-cp312-win_amd64.whl (647.9 kB view details)

Uploaded CPython 3.12Windows x86-64

pypgl-0.1.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (501.3 kB view details)

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

pypgl-0.1.1-cp312-cp312-macosx_11_0_arm64.whl (531.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pypgl-0.1.1-cp311-cp311-win_amd64.whl (638.3 kB view details)

Uploaded CPython 3.11Windows x86-64

pypgl-0.1.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (499.4 kB view details)

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

pypgl-0.1.1-cp311-cp311-macosx_11_0_arm64.whl (533.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pypgl-0.1.1-cp310-cp310-win_amd64.whl (638.4 kB view details)

Uploaded CPython 3.10Windows x86-64

pypgl-0.1.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (499.6 kB view details)

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

pypgl-0.1.1-cp310-cp310-macosx_11_0_arm64.whl (533.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pypgl-0.1.1-cp39-cp39-win_amd64.whl (638.7 kB view details)

Uploaded CPython 3.9Windows x86-64

pypgl-0.1.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (500.0 kB view details)

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

pypgl-0.1.1-cp39-cp39-macosx_11_0_arm64.whl (533.9 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for pypgl-0.1.1.tar.gz
Algorithm Hash digest
SHA256 04838026750a0b30fa7db83bfe105c8d7974b022a65ae4a543c6798809c17339
MD5 28eefc30af57aeb10a85b51c6dbfdcb5
BLAKE2b-256 4729efb16b7adab0f68bd3be5bce2fc0e067ef310f2b1205245bfe964f800374

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.1.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 647.8 kB
  • 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.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 38c2298dea63ad504af0df5c492fc52ecbd345a1964bedd54692c6e0449f5ccc
MD5 19590c291aac105e898fbac07319f3d2
BLAKE2b-256 b8d786ab11db3ea2fd6c5258d53ec6d5416411617d2117b4144aa4c052bf8833

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 db118449e10c182b4e176e089528674f594f647c688e6aa057fb799d0daf1b0c
MD5 84cd7cc58c06e4f65df123e2a45c2651
BLAKE2b-256 61a4b4f9264eb0fcae63552a84520be1bf8c0875149c02c29e7042ceada4a39e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a530548e7758a2c9ef58b76ba83ee56f644e78ffe9f114327f038f63d9b41000
MD5 7d8e93217ae41951b1aed8e9fa2b3f3d
BLAKE2b-256 4054cbd358aba748d7b2980050815d10d96f8171bc99b9b6eb997ef705a41683

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.1.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 647.9 kB
  • 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.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1b0324634b5c81bc2532dbd48d256b328426a260d88dd1d4429cc93e7ed6ea28
MD5 99ba1ba3df4d83fda92a13492106b3a8
BLAKE2b-256 e8bbf75410a28d047dc9461d8603cb52b6ca608062a29bbcc21a2c1c325e56a6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e9b074ea4f0686129c575e029b01222d48546db42228e6faf678ef67f63421a7
MD5 e922ee497d1db2858e2ac77e61840d4d
BLAKE2b-256 a80ff208d5b07e66658d26e479d7ce73720a7def9dc2bd2d4a6a3cc61e2a893c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a58310e50dd07c032da43846227192d454cd7783a25adf748da4d0d2972fab7c
MD5 4f1d09a59adf2da5db90786d2a1f247f
BLAKE2b-256 f8a75b81322813b1316a5bcf1f45885bcf229f98edfc7f17b6d250477109fbf7

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.1.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 638.3 kB
  • 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.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0de6105c91905d09dc86a2312a1c52fe38639cf571ac25b024619a22b1df3192
MD5 9406715387226dc086ac544b7d10eccb
BLAKE2b-256 9281efe0a381993e50e94254bff6bd9b7305be4e4be932bdd924b35c2e6355e0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7e4b30e8fe0f18ee63409bb88cbd9c8159d63e27fbb7aa35ab33375f81377783
MD5 feb6ac93f84a826880183d70bd6c49d6
BLAKE2b-256 c012b1965363974619e34aa574fc9b7870021540296d8221617748d63ac9d13f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a20de7cd9a18c25276e7da6061b2f395511e7019414568a0c5de0a955fb4ee3d
MD5 6e35646683d7556b7d3d6ea52a34c837
BLAKE2b-256 7b59cadb8594c808c7c4b1d04262486f3993fbaa099e8093255a69cccbdc195f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.1.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 638.4 kB
  • 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.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ed2e4a82d18ea24ef1b0834cd85cff173a444ce0f3a77cdf5517c6e3a46d5c37
MD5 4a049c31b56f74cf52065b2363f0a5d0
BLAKE2b-256 fafcfd025010438b53f28480a89d9ded379d8aac3f8c1fddbcb3d98ca7e394b9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ad44d1703b07ad6a3f1e60fa7b390f9baab050ee4784e2e01730d3138061dd21
MD5 93f95f674b516c92edd2e25f39c1d1ca
BLAKE2b-256 add51a860edc4781e176413588f0ac23a4f45a7bd53d6ff022b039469f45ae9c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 869b280dd3399107ac5edb266cb36ffec5b480bb54ed680713f54af715921cc4
MD5 f0c895d8efa41101913a6f4f7198be40
BLAKE2b-256 9975801339d7374ff286b9cb03e7e87cd38e11fa75a312447c30662ebde6882a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.1.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 638.7 kB
  • 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.1.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 699626b95c637914e3c6fbaae8fd3276aaa3b58906a1ddeccae2ce9d1ca132fc
MD5 a03afe2c3bb6c28954ba6b8fbff9767d
BLAKE2b-256 aeef9b6a03c2869822005c6bf26650c6a1e210a717392eac3263ef5fc88218fc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 46a05e8170580311529c067035c7ebec80dcf1ece4ba0848efa10e064d7ad4fc
MD5 9c4b83b222b2c69ffdb0f6e151bae1d8
BLAKE2b-256 242a8516b77df62ca685ee451e5b2d527d54d956addccfa0a97a07651cb8dcdd

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.1.1-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 533.9 kB
  • 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.1.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6fa47809d76de0029eab3f6fc5880bd7447a1dfaa321b11b7e26f074a96ac800
MD5 f50ec60e06b7d8623175b2b6994f2aef
BLAKE2b-256 0d399bc9ef4d95bc6c6ee651a01df5da66f9619152ce3dda174d795b738fc184

See more details on using hashes here.

Provenance

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