Skip to main content

Polygons clipping based on algorithm by F. Martinez et al.

Project description

clipping

In what follows

  • python is an alias for python3.5 or any later version (python3.6 and so on),
  • pypy is an alias for pypy3.5 or any later version (pypy3.6 and so on).

Installation

Install the latest pip & setuptools packages versions:

  • with CPython
    python -m pip install --upgrade pip setuptools
    
  • with PyPy
    pypy -m pip install --upgrade pip setuptools
    

User

Download and install the latest stable version from PyPI repository:

  • with CPython
    python -m pip install --upgrade clipping
    
  • with PyPy
    pypy -m pip install --upgrade clipping
    

Developer

Download the latest version from GitHub repository

git clone https://github.com/lycantropos/clipping.git
cd clipping

Install dependencies:

  • with CPython
    python -m pip install --force-reinstall -r requirements.txt
    
  • with PyPy
    pypy -m pip install --force-reinstall -r requirements.txt
    

Install:

  • with CPython
    python setup.py install
    
  • with PyPy
    pypy setup.py install
    

Usage

>>> left_edge = ((0, 0), (0, 1))
>>> right_edge = ((1, 0), (1, 1))
>>> bottom_edge = ((0, 0), (1, 0))
>>> top_edge = ((0, 1), (1, 1))
>>> main_diagonal = ((0, 0), (1, 1))
>>> trident = [left_edge, main_diagonal, bottom_edge]
>>> square_edges = [bottom_edge, right_edge, top_edge, left_edge]
>>> from clipping.planar import intersect_multisegments
>>> (intersect_multisegments(trident, square_edges)
...  == intersect_multisegments(square_edges, trident)
...  == [left_edge, bottom_edge])
True
>>> from clipping.planar import complete_intersect_multisegments
>>> (complete_intersect_multisegments(trident, square_edges)
...  == complete_intersect_multisegments(square_edges, trident)
...  == ([(1, 1)], intersect_multisegments(trident, square_edges), []))
True
>>> from clipping.planar import unite_multisegments
>>> (unite_multisegments(trident, square_edges)
...  == unite_multisegments(square_edges, trident)
...  == [left_edge, bottom_edge, main_diagonal, top_edge, right_edge])
True
>>> from clipping.planar import subtract_multisegments
>>> subtract_multisegments(trident, square_edges) == [main_diagonal]
True
>>> subtract_multisegments(square_edges, trident) == [top_edge, right_edge]
True
>>> from clipping.planar import symmetric_subtract_multisegments
>>> (symmetric_subtract_multisegments(trident, square_edges)
...  == symmetric_subtract_multisegments(square_edges, trident)
...  == [main_diagonal, top_edge, right_edge])
True
>>> left_triangle = [([(0, 0), (1, 0), (0, 1)], [])]
>>> right_triangle = [([(0, 1), (1, 0), (1, 1)], [])]
>>> square = [([(0, 0), (1, 0), (1, 1), (0, 1)], [])]
>>> from clipping.planar import intersect_multipolygons
>>> all(intersect_multipolygons(square, triangle)
...     == intersect_multipolygons(triangle, square) == triangle
...     for triangle in (left_triangle, right_triangle))
True
>>> intersect_multipolygons(left_triangle, right_triangle) == []
True
>>> from clipping.planar import complete_intersect_multipolygons
>>> all(complete_intersect_multipolygons(square, triangle)
...     == ([], [], intersect_multipolygons(square, triangle))
...     for triangle in (left_triangle, right_triangle))
True
>>> (complete_intersect_multipolygons(left_triangle, right_triangle)
...  == ([], [((0, 1), (1, 0))], []))
True
>>> from clipping.planar import unite_multipolygons
>>> all(unite_multipolygons(square, triangle)
...     == unite_multipolygons(triangle, square)
...     == square
...     for triangle in (left_triangle, right_triangle))
True
>>> (unite_multipolygons(left_triangle, right_triangle)
...  == unite_multipolygons(right_triangle, left_triangle)
...  == square)
True
>>> from clipping.planar import subtract_multipolygons
>>> all(subtract_multipolygons(triangle, square) == []
...     for triangle in (left_triangle, right_triangle))
True
>>> subtract_multipolygons(square, left_triangle) == right_triangle
True
>>> subtract_multipolygons(square, right_triangle) == left_triangle
True
>>> from clipping.planar import symmetric_subtract_multipolygons
>>> symmetric_subtract_multipolygons(left_triangle, right_triangle) == square
True
>>> symmetric_subtract_multipolygons(square, left_triangle) == right_triangle
True
>>> symmetric_subtract_multipolygons(square, right_triangle) == left_triangle
True

Development

Bumping version

Preparation

Install bump2version.

Pre-release

Choose which version number category to bump following semver specification.

Test bumping version

bump2version --dry-run --verbose $CATEGORY

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

Bump version

bump2version --verbose $CATEGORY

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

Release

Test bumping version

bump2version --dry-run --verbose release

Bump version

bump2version --verbose release

This will set version to major.minor.patch.

Running tests

Install dependencies:

  • with CPython
    python -m pip install --force-reinstall -r requirements-tests.txt
    
  • with PyPy
    pypy -m pip install --force-reinstall -r requirements-tests.txt
    

Plain

pytest

Inside Docker container:

  • with CPython
    docker-compose --file docker-compose.cpython.yml up
    
  • with PyPy
    docker-compose --file docker-compose.pypy.yml up
    

Bash script (e.g. can be used in Git hooks):

  • with CPython

    ./run-tests.sh
    

    or

    ./run-tests.sh cpython
    
  • with PyPy

    ./run-tests.sh pypy
    

PowerShell script (e.g. can be used in Git hooks):

  • with CPython
    .\run-tests.ps1
    
    or
    .\run-tests.ps1 cpython
    
  • with PyPy
    .\run-tests.ps1 pypy
    

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

clipping-0.10.4.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clipping-0.10.4-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file clipping-0.10.4.tar.gz.

File metadata

  • Download URL: clipping-0.10.4.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.5.6

File hashes

Hashes for clipping-0.10.4.tar.gz
Algorithm Hash digest
SHA256 7ba28c2a804afa89d81ac861a8f7ea66b6c36f47c843105a44226559563a11fe
MD5 85822974c4774e6ce06bd69dc553d157
BLAKE2b-256 c4520a341b21db30304a7ee71a4eed7200bb2dac76664be6b67184147ef159ec

See more details on using hashes here.

File details

Details for the file clipping-0.10.4-py3-none-any.whl.

File metadata

  • Download URL: clipping-0.10.4-py3-none-any.whl
  • Upload date:
  • Size: 24.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.5.6

File hashes

Hashes for clipping-0.10.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1283dfece8a1bec7438a1051efc45c9273b9b96a3757754cf0ac7e45b3ad6678
MD5 51cd12b54876e2568fbed98179d0ccb2
BLAKE2b-256 90d9783b2d8e52ac98ac6a37c1f5432451adac113e0a8da9a7c2f3359a408a5c

See more details on using hashes here.

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