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, 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.1.tar.gz (874.7 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.1-cp313-cp313-win_amd64.whl (912.5 kB view details)

Uploaded CPython 3.13Windows x86-64

pypgl-0.2.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (738.0 kB view details)

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

pypgl-0.2.1-cp313-cp313-macosx_11_0_arm64.whl (767.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pypgl-0.2.1-cp312-cp312-win_amd64.whl (912.7 kB view details)

Uploaded CPython 3.12Windows x86-64

pypgl-0.2.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (738.1 kB view details)

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

pypgl-0.2.1-cp312-cp312-macosx_11_0_arm64.whl (767.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pypgl-0.2.1-cp311-cp311-win_amd64.whl (899.4 kB view details)

Uploaded CPython 3.11Windows x86-64

pypgl-0.2.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (734.9 kB view details)

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

pypgl-0.2.1-cp311-cp311-macosx_11_0_arm64.whl (769.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pypgl-0.2.1-cp310-cp310-win_amd64.whl (899.6 kB view details)

Uploaded CPython 3.10Windows x86-64

pypgl-0.2.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (735.3 kB view details)

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

pypgl-0.2.1-cp310-cp310-macosx_11_0_arm64.whl (769.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pypgl-0.2.1-cp39-cp39-win_amd64.whl (900.1 kB view details)

Uploaded CPython 3.9Windows x86-64

pypgl-0.2.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (735.5 kB view details)

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

pypgl-0.2.1-cp39-cp39-macosx_11_0_arm64.whl (769.9 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pypgl-0.2.1.tar.gz
  • Upload date:
  • Size: 874.7 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.1.tar.gz
Algorithm Hash digest
SHA256 40e558bc27376c55bd74bd978d5bb7c3ba942d7b4f2836f9ef3fc02cdd544d47
MD5 9faecd45cb17dfe146cd32a962f219c4
BLAKE2b-256 cc611361c59c0e82e63f2d4557cc9d65f6f0219f0a42e979ae32038d9da6235b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.2.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 912.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.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f6594da67881a1a19dcd35ab765851aa6102637d6ed4d76dafa9df8557d8ae0c
MD5 67740fa922c1bfb0cbe4ab5984247e29
BLAKE2b-256 bc20caa6c5496a986d290e1b9cc6dfc1d79aee7e82c0751e1670e33b501cae45

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ac517ebc146389facb85f122842fbfad9774d3bce64e24cf7870a9d6f2f24f34
MD5 d307abe58ea26c6e25638043d346fd9e
BLAKE2b-256 a15c16287124e2b40466685056ab6eabe518177ead9f00ad4376676ae69e4a9b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d283236d3dd7627b82a67be581d8fb066544c653bf73f35c9d185f4da13404de
MD5 6f7d05092551e3812d17fb227c01d7fb
BLAKE2b-256 60e2a7ea227262ceb30a5e409090f1d8abc3a3ba00ff5c5c1cbdf9ba64f3ebb3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.2.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 912.7 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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 febbe5228725b80131ca6d3aa95f25b6a759083fe985a2742522ac75b776cfd1
MD5 6ddb872fd939bc6a0373839dd69173a9
BLAKE2b-256 c270a3b98a58748909cd576589b1fb4b662b9b7397df4403f5755085ff943f92

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 748fa987b1e0c4790613b0b6e49d3d764af885c757ac6f542c3f1f957a460f4a
MD5 78e021672f6f838c09ca3dda98f66620
BLAKE2b-256 a9742f3197cb9316a81a7d89a809eb8211f072fdc3960a362a70a9ce8904f37d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f8253793fca079fd227c4bb4ea454992d19fc5d784e576552bbea66970486d4e
MD5 9aad7a2546636b92ba3488b032c577c9
BLAKE2b-256 24a2d09bee5d7c129b217d4ae23e56c3f6e2e02d6dd14794e39a9ff20cf9688a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.2.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 899.4 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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7c16dd2d9cded6495631d7eda69742ad4906e784cd20c5fb5e49e0dc90fce3c3
MD5 d653d8806cbd11a9310cf4c096fa7c76
BLAKE2b-256 4c36374a95b0d753756439bbd5d230653088379c574bed064b6f1ec4508e86c7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 59225382aff1c132fd5f3d7e3917183a0e7713c0a7e67ffc9430dc01aabbdcc7
MD5 f509201694eea9057204a7050067d15c
BLAKE2b-256 8de392ef7c0e811765bfd5cd0b29be828091f578027b89c9ed70f399601ece0c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 26eb57a4f9ff82a995d2f4a1ac6b2ca061f301700513f8b77fb11231361a4d75
MD5 5a518f7b1ca27f92593e8bcd850e8aad
BLAKE2b-256 b231f8da567ef6c5c12abf18e8db3de066a7e874a98a5c14edfbcd26ab38b9e2

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.2.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 899.6 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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 434d7e7efbf1155b07cb4c46dcea91a7abb5b4cefe42809a7bb09819d07927b5
MD5 02af51577dcfd3805510e86c0b2ab768
BLAKE2b-256 ed0f579e0680abe155211f9c3979b9c6b9bf443b2cc0aa6d5adde5d8a9a2ffac

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2015320a80d3f4cda8ae0a97ea1604443160589e28f0c871271e0deaccf64308
MD5 b612a41156e30b0b693f23bca9969fdf
BLAKE2b-256 51d4527849f6a53b228dccfc0adb732f58f2a173825c296deb53f7f384f378a1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f958afd06ed596aa5401891b5d640f474bba9d58ff48838c6bcd6aec6c571d12
MD5 aa65b2c6a79f53be037e34903bdaa9a4
BLAKE2b-256 7545e62ddd790879d70dae5cae3366751bd45421a825711cbef2d59309c57789

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.2.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 900.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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3231ff4c3aa53a5db0118c50f0f1e10f55e4fb7947ec899e4cd177c02ea7ec5d
MD5 854dec4e06598370d7fd0dd868064acf
BLAKE2b-256 e7f546f73fb9c0ff67ce829103d5c900ff9d610a3e145cd07620aab5bde9ca2c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.2.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 33105cc8ec10381a39117ef106b5e6e5c6a1a0b5e0ac2e3deda225238ac7b8ca
MD5 23db23214ad1965ae7aee4c0aa19ae67
BLAKE2b-256 782e4fe5af627291e24ba085ad621a3afa34b334452b11f3d6d6b2ac08ac5d85

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.2.1-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 769.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.2.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e1a0d84463b9b0468c75f8f55e4dc4dc1b09bcd5ea38f694bfed7db54ed3c97c
MD5 bd711105fbbb21345e32dde1edda68ea
BLAKE2b-256 c0557977a06688afe93f0c5fabd764537d96a9db3836d905d7d6cfc10e7e9892

See more details on using hashes here.

Provenance

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