Skip to main content

pdan

Summary

pdan is a Python library that implements the algorithm of Skorobogatov, G. et al., 2021 for convex polygon decomposition into separate parts depending on the area requirements.


In what follows, python is an alias for python3.11 or any later version.

Installation

Install the latest pip & setuptools packages versions

python -m pip install --upgrade pip setuptools

User

Download and install the latest stable version from PyPI repository

python -m pip install --upgrade pdan

Developer

Download the latest version from GitHub repository

git clone https://github.com/GeorgySk/pdan.git
cd pdan

Install

poetry install

Usage

>>> from fractions import Fraction
>>> from pdan import minimizing_split, Contour, Point, Polygon
>>> contour = Contour([Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1)])
>>> part, other = minimizing_split(contour, Fraction(1, 2),
...                                key=lambda x, y: x.length)
>>> Polygon(part).area == Polygon(other).area == Fraction(1, 2)
True

All computations are exact. Integer and float inputs are converted to Fractions, floats to the exact binary value they store: 0.1 becomes 3602879701896397/36028797018963968, not 1/10. To work with exact decimal values, pass Fractions, for example Fraction("0.1"):

>>> part, _ = minimizing_split(contour, 0.1, key=lambda x, y: x.length)
>>> Polygon(part).area == 0.1
True
>>> Polygon(part).area == Fraction(1, 10)
False
>>> part, _ = minimizing_split(contour, Fraction("0.1"),
...                           key=lambda x, y: x.length)
>>> Polygon(part).area == Fraction(1, 10)
True

Development

Bumping version

Preparation

Install bump-my-version.

Pre-release

Choose which version number category to bump following semver specification.

Test bumping version

bump-my-version bump --dry-run --verbose $CATEGORY

where $CATEGORY is the target version number category name, possible values are patch/minor/major.

Bump version

bump-my-version bump --verbose $CATEGORY

This will set version to major.minor.patch-alpha.

Release

Test bumping version

bump-my-version bump --dry-run --verbose release

Bump version

bump-my-version bump --verbose release

This will set version to major.minor.patch.

Continuous integration

To save CI minutes, the checks (linting, tests, docs and package build) don't run on every push:

  • Pull requests: every check, with the tests on the oldest and newest supported Python. Draft pull requests run nothing, so open a pull request as a draft while working on it and mark it ready for review to run CI. On GitHub, a new push cancels the run for the previous one.
  • The default branch: only the tests on the oldest Python, for the coverage report and the badges. The merged changes were checked in their pull request.
  • Final release tags vX.Y.Z: every check, with the tests on every supported Python, then publishing (see below). Pre-release tags vX.Y.Z-alpha run nothing.

Every job has a timeout, so a hanging test can't use up the minutes. Dependabot opens its pull requests monthly, one per ecosystem (major updates of Python dependencies apart).

Since a merge is followed by only some of the tests, don't merge a pull request unless its last commit passed CI. On GitHub, enforce this with a ruleset (Settings → Rules → Rulesets → New branch ruleset) that targets the default branch and has "Require status checks to pass" with the ci-passed check, the job that passes only when every other check did. Leave "Require branches to be up to date before merging" off: it reruns CI every time the default branch moves. Rulesets are available for public repositories on every plan, but for private ones only on paid plans (GitHub Pro, Team or Enterprise).

Publishing

Pushing a final release tag vX.Y.Z runs the CI publish jobs, which upload the package to PyPI and push the prod Docker image to the GitHub container registry (GHCR). Pre-release tags such as vX.Y.Z-alpha are not published. Alongside them, once the checks pass, the release job creates a GitHub release for the tag, with the version's section of CHANGES.rst as its notes, so add the changelog entries before bumping. It doesn't wait for the publish jobs: if one fails, fix the cause and re-run that job (not the whole pipeline, since a version can be uploaded to PyPI only once).

Release from the default branch once the changes are merged, so that what is published has been reviewed and tested. bump-my-version bump release commits and tags the release, so push both:

git push --follow-tags

A plain git push doesn't push tags. To make it push the tags of the commits it pushes, run once

git config --global push.followTags true

One-time setup:

  • GitHub: on PyPI, add a Trusted Publisher for this repository with workflow ci.yml and environment pypi.
  • GitHub: add a CODECOV_TOKEN repository secret from Codecov.

Linting, formatting and type checking

Ruff is used for linting (installed with the dev dependency group).

Check code

ruff check .

Fix automatically fixable issues

ruff check --fix .

mypy checks types in strict mode (configured in pyproject.toml)

mypy .

The package ships a py.typed marker, so projects that use it get its type hints too.

To run these checks (Ruff and mypy) automatically on each commit, install the pre-commit hooks (once, after the repository has been initialized with git init)

pre-commit install

Running tests

Install the project with the dev dependency group (pytest, pytest-cov, Hypothesis)

poetry install --with dev

Run the tests

poetry run pytest

Run the tests with a coverage report, as CI does

poetry run pytest --cov --cov-report=term

Inside the dev container, dependencies are already installed into the container's Python, so poetry run can be dropped: pytest.

Inside a Docker container (the default IMAGE_TYPE=dev image includes the dev group)

docker compose run --rm --entrypoint pytest pdan

Updating from the template

This project was generated from the copier-pypackage template. To pull in a newer release of the template (CI, tooling and configuration fixes), commit your changes, then run

poetry run copier update --defaults

Copier is in the dev dependency group, so there is nothing else to install (in an environment where Poetry installs into the active Python, such as the dev container, plain copier update --defaults works too). Copier merges the template's changes into the project and keeps yours. Review them with git diff, resolve any conflict markers and commit. CHANGES.rst and pdan/__init__.py are never touched by updates, and .copier-answers.yml must not be edited by hand.

The Template update workflow (.github/workflows/template-update.yml) does this every Monday and opens a pull request when there is a new template release (run it by hand from the Actions tab). Conflicting changes are committed with conflict markers in a draft pull request: resolve them on its branch. There is one pull request per release, so closing one skips that release. The template must be at a URL GitHub can clone (the _src_path in .copier-answers.yml).

With the default GITHUB_TOKEN, enable "Allow GitHub Actions to create and approve pull requests" (Settings → Actions → General). Even then the pull request doesn't run CI, and updates that change .github/workflows can't be pushed. To avoid both, add a TEMPLATE_UPDATE_TOKEN repository secret: a fine-grained personal access token for this repository with read and write access to Contents, Pull requests and Workflows.

Metadata

Release files for pdan 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pdan 0.2.5
File Size Uploaded Provenance Actions
pdan-0.2.5.tar.gz 18.0 kB With provenance Details for pdan-0.2.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pdan 0.2.5
File Interpreter ABI Platform Actions
pdan-0.2.5-py3-none-any.whl Python 3 none any Details for pdan-0.2.5-py3-none-any.whl

Total release size: 31.2 kB

Release files / pdan-0.2.5.tar.gz

Download URL pdan-0.2.5.tar.gz
Size 18.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3f99274080ca4e242f28a66c458b29186441cc8bf9bbc95d24599ddd54c85ceb
BLAKE2b-256 checksum
How to use checksums
cc2dd24b63ef3a1d2eb4291750d3e304546c0ef941d0a4c84f5b01e6b84e79e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / pdan-0.2.5-py3-none-any.whl

Download URL pdan-0.2.5-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b29efd2932e8df16c408d137a1cb59ae834fa3095e46e7b39c2a02fa31070c0
BLAKE2b-256 checksum
How to use checksums
ab3c77e4130dd9bfab92f9b46af47eeff3fd608a38c21a93b657c555b0eb8802
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for pdan 0.2.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pdan-0.2.5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page