Package: pyclipper
AboutPyclipper is a Cython wrapper exposing public functions and classes of
the C++ translation of theAngus 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 onGitHub. The package is published onPyPI.About ClipperClipper - 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.Angus Johnson’s Clipper
libraryInstallDependenciesCython dependency is optional. Cpp sources generated with Cython are
available in releases.Note on using thesetup.py:setup.pyoperates in 2 modes that are based on the presence of thedevfile in the root of the project.Whendevispresent, Cython will be used to compile the.pyxsources. This is thedevelopment mode(as you get it in the git
repository).Whendevisabsent, C/C++ compiler will be used to compile the.cppsources (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 fromMatt Shannon’s bandmat
library.From PyPICython not required.pip install pyclipperFrom sourceCython required.Clone the repository:git clone git@github.com:fonttools/pyclipper.gitInstall:python setup.py installAfter every modification of.pyxfiles compile with Cython:python setup.py build_ext --inplaceClippers’ preprocessor directivesClipper can be compiled with the following preprocessor directives:use_int32,use_xyz,use_linesanduse_deprecated.
Among these theuse_int32anduse_linescan 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 isdisabledby default.use_lines- enables line clipping. Adds a very minor cost to performance. In Pyclipper this directive isenabledby default (since version 0.9.2b0).In case you would want to change these settings, clone this repository and change thedefine_macroscollection (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 useThis wrapper library tries to follow naming conventions of the original
library.ClipperLibnamespace is represented by thepyclippermodule,classesClipperandClipperOffset->PyclipperandPyclipperOffset,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 becomesPyclipper.ExecuteandPyclipper.Execute2.Basic clipping example (based onAngus Johnson’s Clipper
library):importpyclippersubj=(((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:importpyclippersubj=((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 functionsscale_to_clipper()andscale_from_clipper()to achieve that.Migrating from Pyclipper0.9.3b0In previous version of Pyclipper (0.9.3b0) polygons could be automatically scaled using theSCALING_FACTORvariable. This was removed in version1.0.0due to inexact conversions related to floating point operations. This way the library now provides the original numerical robustness of the base library.TheSCALING_FACTORremovalbreaks backward compatibility.
For an explanation and help with migration, seehttps://github.com/fonttools/pyclipper/wiki/Deprecating-SCALING_FACTOR.AuthorsThe Clipper library is written byAngus
Johnson,This wrapper was initially written byMaxime
Chalton,Adaptions to make it work with version 5 written byLukas
Treyer,Adaptions to make it work with version 6.2.1 and PyPI package written byGregor Ratajc,SCALING_FACTORremoval and additions to documentation by Michael Schwarz (@Feuermurmel),Bug fixsympy.Zerois not a collection by Jamie Bull (@jamiebull1),Travis CI and Appveyor CI integration for continuous builds of wheel packages by Cosimo Lupo (@anthrotype).The package is maintained by Cosimo Lupo (@anthrotype).LicensePyclipper is available underMIT
license.The core Clipper library is available underBoost Software
License. Freeware for both
open source and commercial applications.Changelog1.1.0Updated embedded Clipper library to version 6.4.2.1.0.6Added support for Python 3.6.1.0.3added Travis CI and Appveyor CI to build wheel packages (thanks to @anthrotype)1.0.2bug fix:sympy.Zerorecognized as a collection (thanks to @jamiebull1)1.0.0(breaks backwards compatibility)removes SCALING_FACTOR (thanks to @Feuermurmel)0.9.3b0Applied SCALING_FACTOR to the relevant function parameters and class propertiesRefactored tests0.9.2b1bug fix: Fix setting of the PyPolyNode.IsHole property0.9.2b0enable preprocessor directiveuse_linesby default,bug fix: PyPolyNode.Contour that is now one path and not a list of paths as it was previously.