Pyclipper is a Cython wrapper that exposes the public functions and classes of the C++ translation of the Angus Johnson's Clipper library (version 6.4.2). It provides robust algorithms for 2D polygon clipping (intersection, union, difference, XOR) and offsetting (inflating/deflating). The library is actively maintained, with the latest version being 1.4.0, and releases occur as needed for updates or Python compatibility.
pip install pyclipperVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic polygon clipping and offsetting using `pyclipper`. It sets up subject and clip polygons, performs an intersection operation, and then an inward offset on a single polygon. All coordinates are integers, as required by the underlying Clipper library.
Manually scale floating-point coordinates to integers before passing them to `pyclipper` functions using `pyclipper.scale_to_clipper()` and scale results back using `pyclipper.scale_from_clipper()`.
Always convert your floating-point coordinates to integers by multiplying them with a suitable scaling factor (e.g., 1000000 for high precision) before passing them to `pyclipper`. Use `pyclipper.scale_to_clipper()` and `pyclipper.scale_from_clipper()` helper functions for convenience.
Ensure your project's Python environment is running Python 3.10 or a later version.
If building from source, ensure Cython is installed in your build environment (`pip install Cython`). For typical `pip install pyclipper` from PyPI, pre-built wheels are usually provided, making Cython unnecessary.
Ensure `pyclipper` is installed in your environment using `pip install pyclipper`. If you have multiple Python installations, use `python -m pip install pyclipper` to target the specific Python interpreter you are using.
Install the necessary build tools for your operating system (e.g., `xcode-select --install` on macOS, Visual Studio Build Tools on Windows). For Python version conflicts (e.g., with Python 3.9+ and older pyclipper versions), ensure you have an up-to-date `pip` and `setuptools`, and try installing a `pyclipper` version with pre-built wheels for your Python version, or upgrade Cython before attempting to install.
Install the Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017, 2019, and 2022 (x64 and x86 versions) from the official Microsoft website. This provides the runtime components required by C++ compiled Python extensions.
When clipping open paths, use `pc.Execute2()` instead of `pc.Execute()` as `Execute2` is designed to return a `PolyTree` structure suitable for open path clipping.