Skip to main content

Python bindings for the Pangolin (pgl) exact geometry library

Project description

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.

ℹ️ The first PyPI release is not out yet. Until then, install from source as shown below.

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

Project details


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.0.tar.gz (855.3 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.0-cp313-cp313-win_amd64.whl (486.7 kB view details)

Uploaded CPython 3.13Windows x86-64

pypgl-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (384.5 kB view details)

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

pypgl-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (387.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pypgl-0.1.0-cp312-cp312-win_amd64.whl (486.9 kB view details)

Uploaded CPython 3.12Windows x86-64

pypgl-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (384.6 kB view details)

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

pypgl-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (387.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pypgl-0.1.0-cp311-cp311-win_amd64.whl (479.6 kB view details)

Uploaded CPython 3.11Windows x86-64

pypgl-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (383.2 kB view details)

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

pypgl-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (389.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pypgl-0.1.0-cp310-cp310-win_amd64.whl (479.9 kB view details)

Uploaded CPython 3.10Windows x86-64

pypgl-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (383.5 kB view details)

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

pypgl-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (389.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pypgl-0.1.0-cp39-cp39-win_amd64.whl (480.1 kB view details)

Uploaded CPython 3.9Windows x86-64

pypgl-0.1.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (383.9 kB view details)

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

pypgl-0.1.0-cp39-cp39-macosx_11_0_arm64.whl (389.8 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pypgl-0.1.0.tar.gz
  • Upload date:
  • Size: 855.3 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.0.tar.gz
Algorithm Hash digest
SHA256 69cd26cd5b18a281fe563c6a0949f176ee5bc357f12f55b84576cb2ed15c68dc
MD5 c8f3965888036873a9d7b49667a7bcc4
BLAKE2b-256 29896f8ce1381d256a4864eed339bdf07f321be8e95df8007c757a82778a2804

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 486.7 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.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 94bf313058a97757d4cc2f32c3ed8b89760ce6bf8f77fac8176fec1a2ece31a3
MD5 5d3783f5184632b177583f747257eae2
BLAKE2b-256 e96766a6b4593b91744ab59e8d4f21efea47ebc278079b0c7ee29f9abd8c0adf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a09f729d21a9ca8acce3476f3dd2ea3b3df777be4210cc50e9b00dae10a85e58
MD5 7ddd67102042fe81bf8d020949f1a6b9
BLAKE2b-256 db1f091236cfe3e0272ccc92d411e0fd3eb78d7fdd7e32e87388068562fc0f8f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6b40179850b2d8422ee76d3d19a022d90872fe9c5d4118dabfc9d69c255821b8
MD5 6342302bd1f12b515ce0c5f35fbaceb6
BLAKE2b-256 d7d5d7428da8834d21068757b95363dfa234f041e24e2fff3b18eefea8e3461c

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 486.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.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8c2adb56337809917415dfad40be8e94ac3c0d1a8a6135235cd6748e671a7f1f
MD5 ab10e50c6454ec41a2b295d1654b5c1b
BLAKE2b-256 438e9dde0bff885496ef9fdb4cbbe465f83d09627d9be2c3a6ce95018205d65b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2d335e20a9ca5fcbc67e35889119d36cca61c9049f1f45ff64ab2790bdcae0f4
MD5 6deebf25351920051f3818f576fe320c
BLAKE2b-256 14441150f08d4f5e81af6d25ac0e1914370fe05cddd6fa045c1a275e68da2f54

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2dfdd372e7a6aa17f12f28ef3da733b6067f9d567a599808b8f21770098b5438
MD5 071ddd3849a70e30143737955ef74c3e
BLAKE2b-256 61cae5e16102752e21ef5acf5e99fbdc3f1a035969df89b4a90e30f22d42ea29

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 479.6 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.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 39c8e5f934156a8f4851aa7cf0f296de91ac7ae98aafb4bcdcea9bc8654ff0cc
MD5 ab832ea0f9c198efdc175645bcb14565
BLAKE2b-256 23033699f6d13b141ea0af8ffc9b462b366d70748f5de602e6a362e2cc7d887c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6b3f3ee78c9da799817ee62d7315eb9231f21937d9e68c5c5fb324a0061cb1fc
MD5 41b1257fd936da5b728eb46957dcbb7c
BLAKE2b-256 8800b94b92bc9faeed727a498497768d342c9a4e1a031d1834fc26e98804ffb8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ebc3780dd9492f444fe51dcd48ea89a1ffc5a979f443e98c8f7dfc96df502712
MD5 15238dd4269e887e2847c52e232ec91d
BLAKE2b-256 b61c629768c549012fe45b6f526dff19d76333c5ccc317c6759cdce50e02c297

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 479.9 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.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 cef91ecca5cb2b2fe2f6be165b615bce105222c1ab22da6fb7e55ce2236dc642
MD5 5de3afcbc125af413772852daeab5ee2
BLAKE2b-256 794b99b9c170cf23d2544f48597304809791266f48beb301f13a023f221bc86c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 439b16fdb7aed74266a4b8bc3a061bddda5b5f9cf378cc06e1e268a83abb1935
MD5 25ad3706c7e8d6f990fd616233e9f82b
BLAKE2b-256 94f62ca2a423f8aa9a8bbd63cd5e92421b168123813677658022fbcb4f670d3b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a2473a7ba43dbb6b47a5329f1abe0bb06da3cd8e84ee1371d3568e2bfafcb900
MD5 fbec99bc3c83a1dc40b5268eae5fd515
BLAKE2b-256 409e44f5e0304f302175264ba2b48508828abe6a66d73fc7e81bb06931e14991

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 480.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.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e97bb3ab3839e295a2a5c0391d48d006e2b816e8a729af0f5bbe9a70196b93e9
MD5 7c5d4daf5d45ebe3e104e9c8e986d25f
BLAKE2b-256 c26faa54f6da764ff1ffbe81c11725569cf2755ccd81f9012f3f1f9a73dea83b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pypgl-0.1.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cdea06f776316b74c4cf9eeb350d450464cf65e32835ede595266ca5a88a61f8
MD5 0fb51843a5e82362510b942a0b6bf0e6
BLAKE2b-256 b18b30154508466b375120660b01cb48a072e4bbe30c90005d0fa2ff9e39c4ed

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pypgl-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 389.8 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.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aa874bf4bbe0da0ae69c83d587e4c08b50ff83330fe63f45afdc711c0808b124
MD5 b4249afe4cbeb79f09bc6d8cdfcac3cd
BLAKE2b-256 9629a44fc8814b338781f40c9cad0164fbb094873201fa6a753bc086acdaa64a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypgl-0.1.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 Pingdom Monitoring Sentry Error logging StatusPage Status page