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.2.0.tar.gz (869.4 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.2.0-cp313-cp313-win_amd64.whl (810.5 kB view details)

Uploaded CPython 3.13Windows x86-64

pypgl-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (646.8 kB view details)

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

pypgl-0.2.0-cp313-cp313-macosx_11_0_arm64.whl (689.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pypgl-0.2.0-cp312-cp312-win_amd64.whl (810.6 kB view details)

Uploaded CPython 3.12Windows x86-64

pypgl-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (646.9 kB view details)

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

pypgl-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (689.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pypgl-0.2.0-cp311-cp311-win_amd64.whl (801.5 kB view details)

Uploaded CPython 3.11Windows x86-64

pypgl-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (644.5 kB view details)

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

pypgl-0.2.0-cp311-cp311-macosx_11_0_arm64.whl (691.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pypgl-0.2.0-cp310-cp310-win_amd64.whl (801.7 kB view details)

Uploaded CPython 3.10Windows x86-64

pypgl-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (644.8 kB view details)

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

pypgl-0.2.0-cp310-cp310-macosx_11_0_arm64.whl (691.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pypgl-0.2.0-cp39-cp39-win_amd64.whl (802.1 kB view details)

Uploaded CPython 3.9Windows x86-64

pypgl-0.2.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (645.2 kB view details)

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

pypgl-0.2.0-cp39-cp39-macosx_11_0_arm64.whl (691.5 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for pypgl-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c3dadffa926a886f0df76d14f4787162f3088cafcb1ab7a2a6a00ba72ebe3383
MD5 ecfa3b8d01b73acba9f83d4ccf439a91
BLAKE2b-256 ebfb4428a1145ff0905c21ae35266d130af2fded5e79f8abaf1dcce154c8ccd7

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.2.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 810.5 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.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 0e61ddd401ceeaa2c3ca862c03f4807060728cccdfd9bbd7ad2babe5c34ad533
MD5 fb2a417fe2403be04b6166ce9794e1dc
BLAKE2b-256 4af5cb43231485fc437cd55b0323a7a8213abfb3670f9bdac726f8fd925875b5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c4f323adf56072c565a07412b2979160a4e69191b7a1759ae236688def666099
MD5 84c2fb02170ddabd778a2645f6bcd463
BLAKE2b-256 a08a8ee248109d3fffab73dd16fa12a81bf99402d56cbc50e4657bb67172d027

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 24f6c9ccc8b8aeb23ffae73cbdeb72d9e20e228780797cf67453a86bbbe61de1
MD5 885fa8e6b899673c23375500badd5f4f
BLAKE2b-256 7b03207f5c8e060ab6b4cd3914a7f2ba4a2cd40f6dbfd70f21c57682545a97ba

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 810.6 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.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3fdbe83ca8810c0ac1309834cb1417d9e2c4a67d438a7e0c2a58b000a674ce33
MD5 e54adb200d60d3b445b90effae08b96c
BLAKE2b-256 2005bdc10c46b1afd343f9e871cdd45da34a1da76dfa9fc0b19342ad89ce602b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 755c2c2f940ff8da0b5074312e7f0af403707f6955ba8240829511474a84faa9
MD5 76a882b1008d56cc8616ff2481cf0f4f
BLAKE2b-256 e5d1812a9e376266b551c3c766dabd790a4b59401ef2196b937011d012812369

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c461c79dbea615995f162c113e46d440da41730fcd4196d8eb07e01e042a81fd
MD5 5912606202a77e07f0b849b0f1caf375
BLAKE2b-256 de1b0fd7ada578d41129eacf595be3c6f9afd36de7b6c986f90752558c3b1120

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 801.5 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.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d9a55020a43dc6ecec1c8f4bda813cc84fd6f379c0529f9738ffa346308b57d4
MD5 caa6e68aabb047ef1d30bf4f7f523645
BLAKE2b-256 7350c3f2836113ae60a566a05ce188bc88628055d1c844a5623adb791ae845a8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4cade3d902515627267c413892a456e74895e1dcf770a0b623eafac560de0b4b
MD5 decb736cf6db19f1ea3420b317342a27
BLAKE2b-256 afdde8606e28ae0f080cb22cad32ad66ec4dc53a389a09a476a05054d4a5ebdd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b3e3bf7687f36189a42357edd8d7d31e4b705b7b8fdfc845a675b210a1a8e303
MD5 410e86261fa8f8da5deb8a7b46b7c305
BLAKE2b-256 5bf21ef76a0ef084a1e876339d14c150ad4734a90523768ff80ade92121ccb19

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 801.7 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.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2482c92708d483b78049cbd5e413116a8bf18b1f991fbf45fc18be8de7260860
MD5 61a6a3d87b7be9bb801c1dd5e96a1dfd
BLAKE2b-256 2f11bcce4ed180de5d9fe80b434b0f63b66564ced67d7cd8e880498d69743307

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3a8fb226a6f5c4d933a5daf0b3a5fe64aab20325d32b721b806bce56f1d7c234
MD5 c278688c7d2a1cddc8f2d8a2ded116ab
BLAKE2b-256 d37970228fe99ecbb48568435fe830c04d95df612ab2ec7af1488af77a42bc70

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 12b71d0393c0ed6c15dce7594c8cb2431a66fcf756b892e26de9c63d32fc2aa4
MD5 a79a894217a338d232b2bf1e7c2dedbd
BLAKE2b-256 f02be69272bcd5ccff5711d7d033fa225d58a851b1d82da3624815b3ce24cabc

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.2.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 802.1 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.2.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 1fb1ce9344c8a80991e0e91347c2cc6963f94b55eaf4eb5b0ce7bf86145189ae
MD5 d9668d4775d93377dffea6f0cee9054a
BLAKE2b-256 b8ad47fdaaf512ec5ddae189c414d389ac5d87d216ead025be639305338b0c97

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 42de1d23979a6e127eb94e1e3388393dea4ab2069e238ccb9dc88e2530cbe1cd
MD5 8720ce14fdfc8a0498bff0ec4f37a450
BLAKE2b-256 f3028e99347e98cb9c49d8b4cd52aab205f895d93c081ede6fc1c7ce62b610fb

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.2.0-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 691.5 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.2.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ad2118cafae31a2d2621563a2572c6023071d3cff23599bc5bb75a5f1455a074
MD5 23a9873a0d0e9ed7bba8726b5f305cd3
BLAKE2b-256 e00055d91728ce4d423b08e67da622049ef993c4dacf5844bc8c2667e8612542

See more details on using hashes here.

Provenance

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