freshcrate
Home > Frameworks > pyclipper

pyclipper

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

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/

Release History

VersionChangesUrgencyDate
1.4.0Imported from PyPI (1.4.0)Low4/21/2026
1.3.0.post6Build Python 3.13 wheels. No code changes. Low10/18/2024
1.3.0.post5Build Python 3.12 wheels. No code changes. Low9/7/2023
1.3.0.post4Build Python 3.11 wheels. No code changes. Low11/16/2022
1.3.0.post3Rebuild pre-generated cython sources in sdist package to fix build issue on Python 3.11.0 beta1 Low6/13/2022
1.3.0.post2Added 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. Low12/1/2021
1.3.0Export `pyclipper.__version__` string (#40). Removed long-deprecated `SCALING_FACTOR` global variable. Low6/25/2021
1.2.1No code changes in the main library. Only added wheels for Python 3.9. Low12/27/2020
1.2.0Release 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).Low7/1/2020
1.1.0.post2Dropped support for setuptools_scm_git_archive. No code changes, only a minor change in setup process when building from source. Wheels are unaffected.Low7/27/2018
1.1.0.post1Added wheels for python3.7. No code changes.Low7/25/2018
1.1.0Updated embedded Clipper library to version 6.4.2Low1/6/2018
1.0.6Added support for Python 3.6. Low1/20/2017
1.0.5Release 1.0.5Low8/22/2016
1.0.4Release 1.0.4Low8/21/2016
1.0.2Release 1.0.2Low8/17/2016
1.0.1Release 1.0.1Low11/23/2015
0.9.3b0Release 0.9.3b0Low3/25/2015
0.9.2b1Release 0.9.2b1Low3/25/2015
0.9.2b0Release 0.9.2b0Low3/20/2015
0.9.1b0Release 0.9.1b0Low3/18/2015
0.8.dev2Release 0.8.dev2Low2/25/2015

Dependencies & License Audit

Loading dependencies...

Similar Packages

pre-commitA framework for managing and maintaining multi-language pre-commit hooks.v4.6.0
azure-core-tracing-opentelemetryMicrosoft Azure Azure Core OpenTelemetry plugin Library for Pythonazure-template_0.1.0b6187637
spdx-toolsSPDX parser and tools.0.8.5
lacesDjango components that know how to render themselves.0.1.2
django-tasksA backport of Django's built in Tasks framework0.12.0