# pyclipper

> Cython wrapper for the C++ translation of the Angus Johnson's Clipper library (ver. 6.4.2)

- **URL**: https://www.freshcrate.ai/projects/pyclipper
- **Author**: Angus Johnson
- **Category**: Frameworks
- **Latest version**: `1.4.0` (2026-04-21)
- **License**: MIT
- **Source**: https://github.com/fonttools/pyclipper
- **Language**: C++
- **GitHub**: 257 stars, 47 forks
- **Registry**: pypi (`pyclipper`)
- **Tags**: `clipping`, `intersection`, `offsetting`, `polygon`, `pypi`, `union`

## Description

About
=====

.. image:: https://badge.fury.io/py/pyclipper.svg
    :target: https://badge.fury.io/py/pyclipper
.. image:: https://github.com/fonttools/pyclipper/workflows/Build%20+%20Deploy/badge.svg
    :target: https://github.com/fonttools/pyclipper/actions?query=workflow%3A%22Build+%2B+Deploy%22

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) <http://www.angusj.com/delphi/clipper.php>`__.

Source code is available on
`GitHub <https://github.com/fonttools/pyclipper>`__. The package is published on 
`PyPI <https://pypi.python.org/pypi/pyclipper>`__.


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.

        \ `Angus Johnson's Clipper
        library <http://www.angusj.com/delphi/clipper.php>`__\ 

Install
=======

From PyPI
---------

::

        pip install pyclipper


From source
-----------

Clone the repository:

::

        git clone git@github.com:fonttools/pyclipper.git
        

Install:

::

        pip install .

For development, use an editable install:

::

        pip install -e .

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 <http://www.angusj.com/delphi/clipper.php>`__):

.. code:: python

    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:

.. code:: python

    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.

Authors
=======

-  The Clipper library is written by `Angus
   Johnson <http://www.angusj.com/delphi/clipper.php>`__,
-  This wrapper was initially written by `Maxime
   Chalton <https://sites.google.com/site/

## Recent releases

| Version | Date | Urgency | Changes |
| --- | --- | --- | --- |
| `1.4.0` | 2026-04-21 | Low | Imported from PyPI (1.4.0) |
| `1.3.0.post6` | 2024-10-18 | Low | Build Python 3.13 wheels. No code changes. |
| `1.3.0.post5` | 2023-09-07 | Low | Build Python 3.12 wheels. No code changes. |
| `1.3.0.post4` | 2022-11-16 | Low | Build Python 3.11 wheels. No code changes. |
| `1.3.0.post3` | 2022-06-13 | Low | Rebuild pre-generated cython sources in sdist package to fix build issue on Python 3.11.0 beta1 |
| `1.3.0.post2` | 2021-12-01 | Low | Added wheels for Python 3.10, mac universal2 and linux aarch64 and pypy3 (#44). Fixed issue with automatic wheel deployment. No code changes since 1.3.0. |
| `1.3.0` | 2021-06-25 | Low | Export `pyclipper.__version__` string (#40). Removed long-deprecated `SCALING_FACTOR` global variable. |
| `1.2.1` | 2020-12-27 | Low | No code changes in the main library. Only added wheels for Python 3.9. |
| `1.2.0` | 2020-07-01 | Low | Release the Global Interpreter Lock (GIL) while doing more CPU intensive calls to ClipperLib (union, difference, intersection, minkowski, offset, etc), to allow Python apps to better parallelize when using threading (#29, #30). |
| `1.1.0.post2` | 2018-07-27 | Low | Dropped support for setuptools_scm_git_archive. No code changes, only a minor change in setup process when building from source. Wheels are unaffected. |

## Citation

- HTML: https://www.freshcrate.ai/projects/pyclipper
- Markdown: https://www.freshcrate.ai/projects/pyclipper.md
- Dependencies JSON: https://www.freshcrate.ai/api/projects/pyclipper/deps

_Generated by freshcrate.ai. Indexes pypi releases for AI-agent ecosystem packages._
