Cython wrapper for the C++ translation of the Angus Johnson's Clipper library (ver. 6.4.2)
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.4.2).
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:fonttools/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/fonttools/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.1.0
Updated embedded Clipper library to version 6.4.2.
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.3.0.post2-pp38-pypy38_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02c0cc19c932f15344d337b3d12735bb00b4e52c5560683f0bf08297f063d27c |
|
MD5 | 718ace6c92989d858555c67b1857a25c |
|
BLAKE2b-256 | 74d9d788c96eae824dc525d8ef4a46ad0948f4ea37282afa9653e8f83c9b8627 |
Hashes for pyclipper-1.3.0.post2-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfb5cf9e9e753ba92a6f326a52f88cba81ca2104990edf7b5ce7eb22c1cc47b6 |
|
MD5 | 8f04a41b4ef7a9dbf52f80c1d5f20d47 |
|
BLAKE2b-256 | 46a4e3ac992b3e3e14493c3b2a9dd6e85698a7c0bf2180cf939303f2b2ce8964 |
Hashes for pyclipper-1.3.0.post2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1525051ced1ab74e8d32282299c24c68f3e31cd4b64e0b368720b5da65aad67 |
|
MD5 | 45cedf1c9969ff94d0c8e2d1771310f4 |
|
BLAKE2b-256 | cad588a4afd913e1ea155ee423084880a81d268dd9f18c2117393e105e70587b |
Hashes for pyclipper-1.3.0.post2-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5960aaa012cb925ef44ecabe69528809564a3c95ceac874d95c6600f207138d3 |
|
MD5 | d626c8b97065afac2619882c18e2d267 |
|
BLAKE2b-256 | 0cf4bf509c3a869f107783ecd6251e8ace23113587cd8d802073207986e6b880 |
Hashes for pyclipper-1.3.0.post2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3954330c02a19f7566651a909ec4bc5733ba6c62a228ab26db4a90305748430 |
|
MD5 | e2f1c0f171cb1f228ab3bea688c9f327 |
|
BLAKE2b-256 | 78701a1ec26de7ef2a9b9a40e66f85e659e85cdad87b88f895dd6b08dcb471b0 |
Hashes for pyclipper-1.3.0.post2-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5175ee50772a7dcc0feaab19ccf5b979b6066f4753edb330700231cf70d0c918 |
|
MD5 | 8f2025903f90049d681edec30e8055d0 |
|
BLAKE2b-256 | e4c3b6dd84b6936696b82fee1a03d051ca5bb0de8c3d5705d419aef21f7c5a17 |
Hashes for pyclipper-1.3.0.post2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19a6809d9cbd535d0fe922e9315babb8d70b5c7dcd43e0f89740d09c406b40f8 |
|
MD5 | 5bfae05f7f771eb920bbb73446b3cec7 |
|
BLAKE2b-256 | 4b0fe381609f7dfcf174b512dd7fac5184e09077c4eeb75d1ae536baff82b8f5 |
Hashes for pyclipper-1.3.0.post2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c5d50498e335d7f969ca5ad5886e77c40088521dcabab4feb2f93727140251e |
|
MD5 | 9c09bc6b298aa2a5fc42948e37f9966f |
|
BLAKE2b-256 | 32937f239779b3b30d02e849d0b0c2cb6027d8199c56a4639949f537574619ed |
Hashes for pyclipper-1.3.0.post2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd4927ce76a0d48e4bf45c65b2063a2f0d7f6beac35043c451036c852697d5ff |
|
MD5 | a43fe6238e30c12aca20d229ea04cbe1 |
|
BLAKE2b-256 | 56c4e31ef1a2ddb3a5bc6042a7c3060cea3569c240076b87a3eec005224ad058 |
Hashes for pyclipper-1.3.0.post2-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 144fa2aa84355b29b8c2541f02a81cca4d851ef688a341a6220619d1486fb98e |
|
MD5 | 309b8e2a1dd696dd358f68ab012139f1 |
|
BLAKE2b-256 | 05146d9b5d3f2c54cbc4c6aa2b70dcfa2659757c81b3b9e9d61a5ab3ef7ebac7 |
Hashes for pyclipper-1.3.0.post2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 886267f79e9a44e0b9eebb42020d94a427be94b1854c0b654738f1a0d8e8e7f5 |
|
MD5 | 506d4c11d116df90ccd3a41f7067cc0c |
|
BLAKE2b-256 | 8b4ca203efefa61759866aa04575981f6b85eb357a59a8a5b093aa6a034b72c8 |
Hashes for pyclipper-1.3.0.post2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98d2c2afff29840c27f01f90e704730a5383de1261b93debca06306ca336a309 |
|
MD5 | 2bbcbfdf27daca42386fc748c9dbe277 |
|
BLAKE2b-256 | e0e1bd23017ebfc4718d94125cad0b83d2e6501229e4f269152933c195cda25e |
Hashes for pyclipper-1.3.0.post2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | baf129db1a28fac09c653f325ff9f9e3c65a807611670e7b3b8103188e242db8 |
|
MD5 | 629bac2daaeaf31baf047a3d8e56b1cd |
|
BLAKE2b-256 | 82684f9e12ec4d814f4cff7eede149d411c16b4673c6cee57852492cc647e95d |
Hashes for pyclipper-1.3.0.post2-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7904db52cc432cc4e18c786d3dd2d88e464c8ba0128a877bd5eda5900072b23 |
|
MD5 | 2f1d3fd73ade1e532b83b9c1c84960cf |
|
BLAKE2b-256 | 40b9e340b0e7b929063216f03dc2dcef4c8f25cdf0ac331d5b8897c424a58d88 |
Hashes for pyclipper-1.3.0.post2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dad4b42d33f3d7a197aa41215648617f892f776d9276eebd7519d076d57659ff |
|
MD5 | 6e1572de7da8f2b408760d8dd30660b3 |
|
BLAKE2b-256 | baab3a9f2b48af35fbf846107eb54bf09cf5b5f1cfae0bc30c76a78fa6e5cd2d |
Hashes for pyclipper-1.3.0.post2-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12bdfdaaa43c63a70530739850aa798549a956660980dbca6c3b5e5f5972087a |
|
MD5 | 29213e1c855087f65062b2659e1241b9 |
|
BLAKE2b-256 | add4a02aae05f5addb45fd64a8be4274213320467582f4db9baa5b137f72cf7a |
Hashes for pyclipper-1.3.0.post2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0d82c7f2cb49090679cdeddfca6807a36ed4986f7933678d541dc69c6d86503 |
|
MD5 | f2f1072081efc6588c81184bd7da198e |
|
BLAKE2b-256 | c8f6aeaa8528faca855ee48ad775facf205dd9bba36dba910f7e7eeb2b834ba8 |
Hashes for pyclipper-1.3.0.post2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88d1d1d04a92b8c78598d2733e2aae15d46cf4e4038869a2e7deea96a78252cc |
|
MD5 | aacc069883c5abbb04c7757c534b5481 |
|
BLAKE2b-256 | 793a33af411853fa8af180950f173e89e7a023949233fb7572ef22089ec8f2f2 |
Hashes for pyclipper-1.3.0.post2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae24dc6e4c1c02e1d0c9d525a5fa5c023b22088f0bfbcfe9006e3508ea9fa58a |
|
MD5 | 7de8c0b162f1a6bcbe670a78b37aa0cc |
|
BLAKE2b-256 | b55f2fb391c8495fc8a3334d54f3f8bb63bfe83ab8c6d48e016cd922e89eb9ac |
Hashes for pyclipper-1.3.0.post2-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2942a0fc4d9f1362d14a386c1851f673daa49e17f186b1fd9096d4a3ebe6007c |
|
MD5 | 42226736898345c6c8c758c6a0ba4630 |
|
BLAKE2b-256 | 2aea508aace55777289aa68558dfcff660bd4be030b5a0963ee0109da04bf36e |
Hashes for pyclipper-1.3.0.post2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b113d205dc5be0efb9f41ce38415ae60d4797c7152919b0c04acdd0e7cda5df |
|
MD5 | 85efb6e7e839342274377e326173df63 |
|
BLAKE2b-256 | fa14f845395d547409763d063cb43143d336909c1ae611ef75531e02bed65e80 |
Hashes for pyclipper-1.3.0.post2-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f01d8ee5598b1c0a5644927931f3c57672d0f1c5b5653cd15e32bfbe9324441 |
|
MD5 | f33c43cb04e34a75cc2e56a79fa87642 |
|
BLAKE2b-256 | f19e19988e4dce75e5a1d28d1e381c56b65422254baa5711263b5b37b00ee02a |
Hashes for pyclipper-1.3.0.post2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dca8ac14b329b02af117bc70688453e08940b0730376dcdc206cf590562654c6 |
|
MD5 | fa139de45f29386ec01aeb3ee5d49dba |
|
BLAKE2b-256 | 554ae2e5d77548a233b24ef730b64a61940da77cc0c2b8c0ebe9a56db39eeba0 |
Hashes for pyclipper-1.3.0.post2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f218bf40eea9ea5b03ce3ad58e652e82975a5948e01e742a4165fade0493532a |
|
MD5 | 20494e2176d710e5bc7e8ce2a45c9008 |
|
BLAKE2b-256 | c5fa2c294127e4f88967149a68ad5b3e43636e94e3721109572f8f17ab15b772 |
Hashes for pyclipper-1.3.0.post2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bbcdc9d49ad4cdd61ddce47d7b9bfb5170c16c71fffe4b9fabd1b648eec69d9 |
|
MD5 | d7c10e4244058dccca3c21400e88f225 |
|
BLAKE2b-256 | d57d65b0e92779b5688fc3b89b420b3767edf3677bac1c43b176a0dd897183d1 |
Hashes for pyclipper-1.3.0.post2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a1f957fdc3525bdc55a9fb803b3e711194f5da4b4a2f0693277a77ed0883a31 |
|
MD5 | 57e7f8547f2eb7f483d700c48285b3c1 |
|
BLAKE2b-256 | 5bfd7239f17d2de30bdc72b1709ffc38f1590dc2a1c1a1c06ab3b8dc04578b74 |
Hashes for pyclipper-1.3.0.post2-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b69ad30d8a09d1eb2ef7a67c5f94d5d9919b6af714dc8f010073bf7e85d60e22 |
|
MD5 | 685c09c3bb5ae197d2fc3c3729a63847 |
|
BLAKE2b-256 | b7fbc4b5e69cd4a0207a04e0a54194b08c0e0ff5d7831492c4527aa2f3be9c2d |
Hashes for pyclipper-1.3.0.post2-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8881c5f949b3cddc260ff8bf043f51cfd2eb1bfaf09362018263c44786314266 |
|
MD5 | 8f7ce9ade1d2e2186b82df84ba9a45ec |
|
BLAKE2b-256 | 7eebc507b94fb9e52a0e2e7631f4a24ea70d27fb2abb66ea781106aaa97d7508 |
Hashes for pyclipper-1.3.0.post2-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3684e6dbe3e656cfba0329033d3c31727a9bc8226aa2ec0ec36d5d5ded525166 |
|
MD5 | fa0df409d5b2eaead3c5fd125ae8aa43 |
|
BLAKE2b-256 | 9049c6252fb48b5a1a35d58851fcf876b118bd332b32bc9e44dcff5bbb99d0d9 |
Hashes for pyclipper-1.3.0.post2-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 010f457c7daa307a8e99f1c264676d293176a58cc67ac6d89172f4a99ada7957 |
|
MD5 | fa25b6be46529cb341e80671b0b0dbe3 |
|
BLAKE2b-256 | 832f30c65ffbc7f3c8cca86d5655dd7d7ae56a317072dd4fdf33199af2ef6043 |