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. The package is published on PyPI.
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
Clippers’ preprocessor directives
Clipper can be compiled with the following preprocessor directives: use_int32, use_xyz, use_lines and use_deprecated. Among these the use_int32 and use_lines can be used with Pyclipper.
use_int32 - when enabled 32bit ints are used instead of 64bit ints. This improve performance but coordinate values are limited to the range +/- 46340. In Pyclipper this directive is disabled by default.
use_lines - enables line clipping. Adds a very minor cost to performance. In Pyclipper this directive is enabled by default (since version 0.9.2b0).
In case you would want to change these settings, clone this repository and change the define_macros collection (setup.py, pyclipper extension definition). Add a set like ('use_int32', 1) to enable the directive, or remove the set to disable it. After that you need to rebuild the package.
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 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 clipping 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_SUBJECT, True)
solution = pc.Execute(pyclipper.CT_INTERSECTION, pyclipper.PFT_EVENODD, pyclipper.PFT_EVENODD)
# solution (a list of paths): [[[240, 200], [190, 200], [190, 150], [240, 150]], [[200, 190], [230, 190], [215, 160]]]
Basic offset example:
import pyclipper
subj = ((180, 200), (260, 200), (260, 150), (180, 150))
pco = pyclipper.PyclipperOffset()
pco.AddPath(subj, pyclipper.JT_ROUND, pyclipper.ET_CLOSEDPOLYGON)
solution = pco.Execute(-7.0)
# solution (a list of paths): [[[253, 193], [187, 193], [187, 157], [253, 157]]]
The Clipper library uses integers instead of floating point values to preserve numerical robustness. If you need to scale coordinates of your polygons, this library provides helper functions scale_to_clipper() and scale_from_clipper() to achieve that.
Migrating from Pyclipper 0.9.3b0
In previous version of Pyclipper (0.9.3b0) polygons could be automatically scaled using the SCALING_FACTOR variable. This was removed in version 1.0.0 due to inexact conversions related to floating point operations. This way the library now provides the original numerical robustness of the base library.
The SCALING_FACTOR removal breaks backward compatibility. For an explanation and help with migration, see https://github.com/greginvm/pyclipper/wiki/Deprecating-SCALING_FACTOR.
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.
Changelog
1.0.6
Added support for Python 3.6.
1.0.3
added Travis CI and Appveyor CI to build wheel packages (thanks to @anthrotype)
1.0.2
bug fix: sympy.Zero recognized as a collection (thanks to @jamiebull1)
1.0.0
(breaks backwards compatibility) removes SCALING_FACTOR (thanks to @Feuermurmel)
0.9.3b0
Applied SCALING_FACTOR to the relevant function parameters and class properties
Refactored tests
0.9.2b1
bug fix: Fix setting of the PyPolyNode.IsHole property
0.9.2b0
enable preprocessor directive use_lines by default,
bug fix: PyPolyNode.Contour that is now one path and not a list of paths as it was previously.
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 Distributions
Hashes for pyclipper-1.0.6-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 550a5994ad68e38cca43d75365bab4e9ebfa88425ba70290915fe0fc992ff71c |
|
MD5 | 4ea372b7de198d4fa1e579a44f2cd1a8 |
|
BLAKE2b-256 | fadc9fa005d9b29141ef28ee356362ea2812a49433165a2b01461a5efe83194d |
Hashes for pyclipper-1.0.6-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77899aef86f22a06bb21b8d87988722f3173bf0ae5c23a12325cdb277d1ee8d7 |
|
MD5 | 970c9123e3ff682942783638896328ec |
|
BLAKE2b-256 | 0df4a2243e9cfddc5a72b3f4c023f9a97b06d916d1db805871d7f933ae691e70 |
Hashes for pyclipper-1.0.6-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c692c9e30edfc79868451086a81177cd9ac193babae53cf17c860e84ae0ba55 |
|
MD5 | 78214f48ed743a94b3e0635309c49029 |
|
BLAKE2b-256 | c2b0fa8c06e893d7466f89a83456231f1ec3b6d68b94adefebb874676ac431c7 |
Hashes for pyclipper-1.0.6-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f597da43e84901715e173dca667d570966565aea5139fe7df48c67564cac453 |
|
MD5 | c05be2bf7ec258445421802814bc101e |
|
BLAKE2b-256 | 15b22036f554e039e37aecc948160598d2c999ca808192a5c4f26a806ebe6621 |
Hashes for pyclipper-1.0.6-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 395401641f075a42173566286bb3410603951b004241d3f5f2994d75bf89439d |
|
MD5 | c7d333c12f803e2dc00d46b3202ccd33 |
|
BLAKE2b-256 | 233d5b5595dee824fcc95b34520ba8c5e7da9c931158f48423228c194282d85b |
Hashes for pyclipper-1.0.6-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ece7dac088279fe2a916546899d33bc9a5a395f934cdbe24155cbab39dfcd31 |
|
MD5 | 1b49f10b610838730c01314a10dafd51 |
|
BLAKE2b-256 | c52947546f8741146867950a8af1ef491fe84bd733b93aebd17cfb1982aee7da |
Hashes for pyclipper-1.0.6-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a13ef8f2df2618e2d22c0c40b7a10b9e08a020bfd73b3e60890a79d0f523b146 |
|
MD5 | f5f6fed323ef14012db7239673b536e9 |
|
BLAKE2b-256 | 760de58f5a637090c767ee323835eeb2dab057616f7b076827c7891ccc8b1aec |
Hashes for pyclipper-1.0.6-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63959695a37c9312dc920db50eee97dacd2ee0585857db0e880fdf045977b3f0 |
|
MD5 | 7a7e8e1d7518768e83c250ef5d8b07eb |
|
BLAKE2b-256 | c8e7a5ee28388310d82015f60134f6f10c1087eba988e16640ac421853affb5a |
Hashes for pyclipper-1.0.6-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a1530a6645309cdc84b2e56a3a728959b0a092bd92ec0cfa57aa06d79be9a7a |
|
MD5 | 8328c37b62939037367762ab6d7382ac |
|
BLAKE2b-256 | 7c51a148ce790f0dc722668268ff408b2c47e92293a7354762be9f6a6a823fad |
Hashes for pyclipper-1.0.6-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 929318fa4aea60ca9571df4efe00346724429671a55836e1400955bbb4e32d8d |
|
MD5 | a882f24ca24f310b34abbead7815409f |
|
BLAKE2b-256 | e6a288e86c12e6bab48149003621608b824439bf3c1626f62a911d66438f60df |
Hashes for pyclipper-1.0.6-cp34-cp34m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5143a99f427766bf26066fd874b908b4914de7c684bcd7739aca262e65983e67 |
|
MD5 | 82fc3acb46c5ab86cedf954cc43e0886 |
|
BLAKE2b-256 | 6d5908b2d4afc32add33e7bb73f84045828c2b34107628fbc01ddc543447f7b4 |
Hashes for pyclipper-1.0.6-cp34-cp34m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb84adfee8e673b737edae0cd79196ef456409553d802ca5038096eac2b4e621 |
|
MD5 | 509277e06a7a9efcabee5fa8a0ff8cbb |
|
BLAKE2b-256 | f0e344d71a4d8fe673d5c6dcbcaf113ad4c4794436227b010263a9c92301d54f |
Hashes for pyclipper-1.0.6-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f617ee4efb10633ad4456b9c0a836de9d6ef4b9056358856a3af5d49fa46f226 |
|
MD5 | 0a6bf353c86a41fb5821c22463b8ba12 |
|
BLAKE2b-256 | 1a182f5e1372f44bf53673dc89386716ae0796d5b0e6c4e439e1a4208bf8c62f |
Hashes for pyclipper-1.0.6-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5563b5addb3215e0f5ffb3d8555fdd269e084d801be1a77d961d23e7a13c83d |
|
MD5 | 3e4160fb705556d5ee85395a806e3b5d |
|
BLAKE2b-256 | 952b3a72b116dc8f3e2f3394cd71ba560b2b335ad3fc90f717e3585451ad1581 |
Hashes for pyclipper-1.0.6-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ed3da6ed7395f8be7009cd9f70b7b3b9b51269d345ff85e4582bc7a8d8bb12a |
|
MD5 | ff39c84848926f4c64aa5ba9e6b98655 |
|
BLAKE2b-256 | 1d780c12cae32ee980e5c74925c3b95fca02822ff0a11e4704e495ac86fa7560 |
Hashes for pyclipper-1.0.6-cp33-cp33m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e62c48587081ebc30cb8ca39b2e727c09fa7ff42b8072b54c47d5b6311fad11f |
|
MD5 | 5dccad28ecb5bbd2722e583e691d4f20 |
|
BLAKE2b-256 | ec276f325eec909c40c60276bd2a4bce282aff43e6248ab0e977e916281d058a |
Hashes for pyclipper-1.0.6-cp33-cp33m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ceb6f1ab0a71239361702d745cae7ec3b68e263c2af992a2622108d85072f0d |
|
MD5 | a6295320d02695f9ff769877b2316f55 |
|
BLAKE2b-256 | 353ad17c9ab51b64d231aa964933f5ae9822595d463bbf08ad5376eceba4f3b4 |
Hashes for pyclipper-1.0.6-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86677c7414ff1030412259494d24e6fa2df25d6d0a245c18cf2fac291e6fafb5 |
|
MD5 | c6ab390823023dc450e2a69c80dfa2e5 |
|
BLAKE2b-256 | a8760491cf4f0a4466d856712a98a48971626f803b586cda76ab2faafd028c8b |
Hashes for pyclipper-1.0.6-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d6ee9c1003525a99c2e5a78e491c51fe36c73cb7dd0a9ec3c3406f392c88eb0 |
|
MD5 | 000bc4a382898d729dfb687c0576d04f |
|
BLAKE2b-256 | 0d3cfe23f0a32c36abff6bd97dafc7faaab7133198979a65270945a7050b483b |
Hashes for pyclipper-1.0.6-cp27-cp27m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b174f4de3e8f0a34bd12d5f06f5a6ac9764db589d25841a48200212396842a4f |
|
MD5 | e84ba79f0d6ac9be59d5703cd5f556f1 |
|
BLAKE2b-256 | c02b8eacd265c19b9170a826a30ac53d6f39e17629a89281bf7ae1225e214415 |
Hashes for pyclipper-1.0.6-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f872f5095985f54db3affe0bd41e4821db981783eb512c12423504c1c5f4e09 |
|
MD5 | 35ad203419021b7dca878babbdd7c2fc |
|
BLAKE2b-256 | 5f025f79000c6b2d3cffd472cda93ad5474189bc25a6f78797065a3578fbff3e |
Hashes for pyclipper-1.0.6-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74d94630444bb3012b0f6b26c134c6ef9b8b397fd4f2d630a0a8355f67e9fb26 |
|
MD5 | 8aa6ba07a700830b991baeeda9cc1bea |
|
BLAKE2b-256 | 107cc2fc1ba3d0d88d96ff003d260a5e1fbcbb06a41b8206d0bbbb72c976e2f9 |
Hashes for pyclipper-1.0.6-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 879728471e65b827c74eb6ac1f41be29bbb11c05d8422aff84b4df71e2c90925 |
|
MD5 | 449209701459695e00bbc3a575c01282 |
|
BLAKE2b-256 | 0f40fffa88703637a7d7fa3b00b7cb5143e0e644f41a798b0564ea048aeab04e |
Hashes for pyclipper-1.0.6-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6af81fedc30d58054356e4afbebdb32f06b14f4f89ad4b98c3c6a281ead3fe7 |
|
MD5 | 6d8b37b31fc8d20929ba472abbb52c14 |
|
BLAKE2b-256 | 73a7c1e6390984b91133badf2cb28427e20b3c6ec425eb6683ed0d79d3f25251 |