Cython wrapper for the C++ translation of the Angus Johnson's Clipper library (ver. 6.2.1)
Project description
About
Pyclipper is a Cython wrapper exposing public functions and classes of the C++ translation of the Angus Johnson’s Clipper library (ver. 6.2.1).
Pyclipper releases were tested with Python 2.7 and 3.4 on Linux (Ubuntu 14.04, x64) and Windows (8.1, x64).
Source code is available on GitHub.
About Clipper
Clipper - an open source freeware library for clipping and offsetting lines and polygons.
The Clipper library performs line & polygon clipping - intersection, union, difference & exclusive-or, and line & polygon offsetting. The library is based on Vatti’s clipping algorithm.
Install
Dependencies
Cython dependency is optional. Cpp sources generated with Cython are available in releases.
Note on using the setup.py:
setup.py operates in 2 modes that are based on the presence of the dev file in the root of the project.
When dev is present, Cython will be used to compile the .pyx sources. This is the development mode (as you get it in the git repository).
When dev is absent, C/C++ compiler will be used to compile the .cpp sources (that were prepared in in the development mode). This is the distribution mode (as you get it on PyPI).
This way the package can be used without or with an incompatible version of Cython.
The idea comes from Matt Shannon’s bandmat library.
From PyPI
Cython not required.
pip install pyclipper
From source
Cython required.
Clone the repository:
git clone git@github.com:greginvm/pyclipper.git
Install:
python setup.py install
After every modification of .pyx files compile with Cython:
python setup.py build_ext --inplace
How to use
This wrapper library tries to follow naming conventions of the original library.
ClipperLib namespace is represented by the pyclipper module,
classes Clipper and ClipperOffset -> Pyclipper and Pyclipper and PyclipperOffset,
when Clipper is overloading functions with different number of parameters or different types (eg. Clipper.Execute, one function fills a list of paths the other PolyTree) that becomes Pyclipper.Execute and Pyclipper.Execute2.
Basic example (based on Angus Johnson’s Clipper library):
import pyclipper
subj = (
((180, 200), (260, 200), (260, 150), (180, 150)),
((215, 160), (230, 190), (200, 190))
)
clip = ((190, 210), (240, 210), (240, 130), (190, 130))
pc = pyclipper.Pyclipper()
pc.AddPath(clip, pyclipper.PT_CLIP, True)
pc.AddPaths(subj, pyclipper.PT_SUBJ, True)
solution = pc.Execute(pyclipper.CT_INTERSECTION, pyclipper.PFT_EVENODD, pyclipper.PFT_EVENODD)
The Clipper library uses integers instead of floating point values to preserve numerical robustness. You can use pyclipper.SCALING_FACTOR to scale your values to preserve the desired presision. The default value is 1, which disables scaling. This setting only scales coordinates of polygon vertices, properties like miterLimit, roundPrecision etc. are not scaled.
For more examples of use see tests/test_pyclipper.py and Clipper documentation.
License
Pyclipper is available under MIT license.
The core Clipper library is available under Boost Software License. Freeware for both open source and commercial applications.
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
File details
Details for the file pyclipper-0.9.1b0.tar.gz
.
File metadata
- Download URL: pyclipper-0.9.1b0.tar.gz
- Upload date:
- Size: 93.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ef099b0cfefc22e09d61a694af30462feb6c3c410983c28c8e672221c239dc5 |
|
MD5 | 1b89ee015c789a086fa26e90ae418668 |
|
BLAKE2b-256 | 7665d5458029f9abc2e4f9a587a290691928a3374ddac3fae45c220bd7a2604f |