Polygons clipping based on algorithm by F. Martinez et al.
Project description
clipping
In what follows
pythonis an alias forpython3.5or any later version (python3.6and so on),pypyis an alias forpypy3.5or any later version (pypy3.6and so on).
Installation
Install the latest pip & setuptools packages versions:
- with
CPythonpython -m pip install --upgrade pip setuptools
- with
PyPypypy -m pip install --upgrade pip setuptools
User
Download and install the latest stable version from PyPI repository:
- with
CPythonpython -m pip install --upgrade clipping
- with
PyPypypy -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
CPythonpython -m pip install --force-reinstall -r requirements.txt
- with
PyPypypy -m pip install --force-reinstall -r requirements.txt
Install:
- with
CPythonpython setup.py install
- with
PyPypypy 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
CPythonpython -m pip install --force-reinstall -r requirements-tests.txt
- with
PyPypypy -m pip install --force-reinstall -r requirements-tests.txt
Plain
pytest
Inside Docker container:
- with
CPythondocker-compose --file docker-compose.cpython.yml up
- with
PyPydocker-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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clipping-0.7.1.tar.gz.
File metadata
- Download URL: clipping-0.7.1.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.5.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88cc8351465b4a6cbbae93899b300c37373d6f949891d07412703fe0b25958a0
|
|
| MD5 |
8a58d423bcf235bd0ca0373d4d471de4
|
|
| BLAKE2b-256 |
9b4adb84876f27cb230c2b512a8b5b1a5933a92f5d8de3d4cc123232c0da0257
|
File details
Details for the file clipping-0.7.1-py3-none-any.whl.
File metadata
- Download URL: clipping-0.7.1-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.5.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
341415aa2fb8329fb98838c2d97741fa891fc9d6d08e3a431573714a1de3926d
|
|
| MD5 |
aef55956ad9b58a018f36b2e39bc0c88
|
|
| BLAKE2b-256 |
caf23eb532d4a95edcf63cc03c9dabe8ef4790854be191134c544ad9e1320324
|