Skip to main content

GitHub Actions Workflow Status pypi-badge GitHub License pepy-badge python-badge py-version-badge

Pyclipr is a Python library offering the functionality of the Clipper2 polygon clipping and offsetting library and are built upon pybind . The underlying Clipper2 library performs intersection, union, difference and XOR boolean operations on both simple and complex polygons and also performs offsetting of polygons and inflation of paths.

Unlike pyclipper, this library is not built using cython. Instead the full use of capability pybind is exploited. This library aims to provide convenient access to the Clipper2 library for Python users, especially with its usage in 3D Printing and computer graphics applications.

For further information, see the latest release notes.

Installation

Installation using pre-built packages are currently supported on Windows, Mac but excludes Linux because pre-built packages are unsupported via PyPi. Otherwise, no special requirements or prerequisites are necessary.

conda install -c numpy
pip install numpy

Installation of pyclipr can then be performed using the pre-built python packages using the PyPi repository.

pip install pyclipr

Alternatively, pyclipr may be compiled directly from source within the python environment. Currently the prerequisites are the a compliant c++ build environment include CMake build system (>v3.15) and the availability of a compiler with c++17 compatibility. Currently the package has been tested built using Windows 10, using VS2019 and Mac OSX Sonoma.

Firstly, clone the pyclipr repository whilst ensuring that you perform the recurisve submodule when initialising the repoistory. This ensures that all dependencies (•pybind, • pyclipr, •eigen) are downloaded into the source tree.

git clone https://github.com/drlukeparry/pyclipr.git && cd ./pyclipr
git submodule update --init --recursive

python -m build

Usage

The pyclipr library follows similar structure to that documented in Clipper2 library. Although for consistency most methods are implemented using camelCase naming convention and more generic functions are provided for the addition of paths.

The library assumes that coordinates are provided and scaled by a scaleFactor (default = 1e3), set within the Clipper and ClipperOffset classes to ensure correct numerical robustness outlined in the underlying Clipper library. The coordinates for the paths may be provided as a list of tuples or a numpy array. The internal scale factor determines the precision of the clipping and offsetting operations but can impact performance. It is recommended to adjust this in accordance to your applications.

Both Path64 and PolyTree64 structures are supported from the clipping and offsetting operations, which are enacted by using either execute or execute2 methods, respectively.

A variety of other utilities are provided for inspection of polygons and paths.

import numpy as np
import pyclipr

# Tuple definition of a path
path = [(0.0, 0.), (0, 105.1234), (100, 105.1234), (100, 0), (0, 0)]
path2 = [(1.0, 1.0), (1.0, 50), (100, 50), (100, 1.0), (1.0,1.0)]

# Create an offsetting object
po = pyclipr.ClipperOffset()

# Set the scale factor to convert to internal integer representation
po.scaleFactor = int(1000)

# add the path - ensuring to use Polygon for the endType argument
# addPaths is required when working with polygon - this is a list of correctly orientated paths for exterior
# and interior holes
po.addPaths([np.array(path)], pyclipr.JoinType.Miter, pyclipr.EndType.Polygon)

# Apply the offsetting operation using a delta.
offsetSquare = po.execute(10.0)

# Create a clipping object
pc = pyclipr.Clipper()
pc.scaleFactor = int(1000)

# Add the paths to the clipping object. Ensure the subject and clip arguments are set to differentiate
# the paths during the Boolean operation. The final argument specifies if the path is
# open.
pc.addPaths(offsetSquare, pyclipr.Subject)
pc.addPath(np.array(path2), pyclipr.Clip)

""" Test Polygon Clipping """
# Below returns paths
out  = pc.execute(pyclipr.Intersection, pyclipr.FillRule.EvenOdd)
out2 = pc.execute(pyclipr.Union, pyclipr.FillRule.EvenOdd)
out3 = pc.execute(pyclipr.Difference, pyclipr.FillRule.EvenOdd)
out4 = pc.execute(pyclipr.Xor, pyclipr.FillRule.EvenOdd)

# Using execute2 returns a PolyTree structure that provides hierarchical information inflormation
# if the paths are interior or exterior
outB = pc.execute2(pyclipr.Intersection, pyclipr.FillRule.EvenOdd)

# An alternative equivalent name is executeTree
outB = pc.executeTree(pyclipr.Intersection, pyclipr.FillRule.EvenOdd)

""" Test Open Path Clipping """
# Pyclipr can be used for clipping open paths.  This remains simple to complete using the Clipper2 library

pc2 = pyclipr.Clipper()
pc2.scaleFactor = int(1e5)

# The open path is added as a subject (note the final argument is set to True)
pc2.addPath( ((40,-10),(50,130)), pyclipr.Subject, True)

# The clipping object is usually set to the Polygon
pc2.addPaths(offsetSquare, pyclipr.Clip, False)

""" Test the return types for open path clipping with option enabled"""
# The returnOpenPaths argument is set to True to return the open paths. Note this function only works
# well using the Boolean intersection option
outC = pc2.execute(pyclipr.Intersection, pyclipr.FillRule.NonZero)
outC2, openPathsC = pc2.execute(pyclipr.Intersection, pyclipr.FillRule.NonZero, returnOpenPaths=True)

outD = pc2.execute2(pyclipr.Intersection,  pyclipr.FillRule.NonZero)
outD2, openPathsD = pc2.execute2(pyclipr.Intersection,  pyclipr.FillRule.NonZero, returnOpenPaths=True)

# Plot the results
pathPoly = np.array(path)

import matplotlib.pyplot as plt
plt.figure()
plt.axis('equal')

# Plot the original polygon
plt.fill(pathPoly[:,0], pathPoly[:,1], 'b', alpha=0.1, linewidth=1.0, linestyle='dashed', edgecolor='#000')

# Plot the offset square
plt.fill(offsetSquare[0][:, 0], offsetSquare[0][:, 1], linewidth=1.0, linestyle='dashed', edgecolor='#333', facecolor='none')

# Plot the intersection
plt.fill(out[0][:, 0], out[0][:, 1],  facecolor='#75507b')

# Plot the open path intersection
plt.plot(openPathsC[0][:,0], openPathsC[0][:,1],color='#222', linewidth=1.0, linestyle='dashed', marker='.',markersize=20.0)

""" Utility Functions """

# Simplification of Paths
rect = [(0,0), (100,0), (100,100), (0,100), (0,0)]
rect2 = [(20,0), (20,10), (30,10), (30,0), (20,0)]

simplifiedPaths = pyclipr.simplifyPaths([rect, rect2], epsilon=0.001)

# Check the orientation of a path (True if Counter-Clockwise)
isCCW = pyclipr.orientation(rect)

Metadata

Release files for pyclipr 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyclipr 0.1.8
File Size Uploaded
pyclipr-0.1.8.tar.gz 4.6 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for pyclipr 0.1.8
File
pyclipr-0.1.8-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
pyclipr-0.1.8-cp314-cp314-macosx_15_0_arm64.whl CPython 3.14 CPython 3.14 macOS 15.0+ ARM64 Details
pyclipr-0.1.8-cp314-cp314-macosx_14_0_arm64.whl CPython 3.14 CPython 3.14 macOS 14.0+ ARM64 Details
pyclipr-0.1.8-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
pyclipr-0.1.8-cp313-cp313-macosx_15_0_arm64.whl CPython 3.13 CPython 3.13 macOS 15.0+ ARM64 Details
pyclipr-0.1.8-cp313-cp313-macosx_14_0_arm64.whl CPython 3.13 CPython 3.13 macOS 14.0+ ARM64 Details
pyclipr-0.1.8-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
pyclipr-0.1.8-cp312-cp312-macosx_15_0_arm64.whl CPython 3.12 CPython 3.12 macOS 15.0+ ARM64 Details
pyclipr-0.1.8-cp312-cp312-macosx_14_0_arm64.whl CPython 3.12 CPython 3.12 macOS 14.0+ ARM64 Details
pyclipr-0.1.8-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
pyclipr-0.1.8-cp311-cp311-macosx_15_0_arm64.whl CPython 3.11 CPython 3.11 macOS 15.0+ ARM64 Details
pyclipr-0.1.8-cp311-cp311-macosx_14_0_arm64.whl CPython 3.11 CPython 3.11 macOS 14.0+ ARM64 Details
pyclipr-0.1.8-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
pyclipr-0.1.8-cp310-cp310-macosx_15_0_arm64.whl CPython 3.10 CPython 3.10 macOS 15.0+ ARM64 Details
pyclipr-0.1.8-cp310-cp310-macosx_14_0_arm64.whl CPython 3.10 CPython 3.10 macOS 14.0+ ARM64 Details
pyclipr-0.1.8-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
pyclipr-0.1.8-cp39-cp39-macosx_15_0_arm64.whl CPython 3.9 CPython 3.9 macOS 15.0+ ARM64 Details
pyclipr-0.1.8-cp39-cp39-macosx_14_0_arm64.whl CPython 3.9 CPython 3.9 macOS 14.0+ ARM64 Details

Total release size: 8.1 MB

Release files / pyclipr-0.1.8.tar.gz

Download URL pyclipr-0.1.8.tar.gz
Size 4.6 MB
Tags Source
SHA-256 checksum
How to use checksums
ff8360330f827dc4801a57cd18d3bc925814b6a9a05f14be1e0f8f72cc27488f
BLAKE2b-256 checksum
How to use checksums
e396c8049cfb9166c1f50d878535f2d1cdae1303e994dea7783a3f9075aa0679
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp314-cp314-win_amd64.whl

Download URL pyclipr-0.1.8-cp314-cp314-win_amd64.whl
Size 198.9 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
daf588b99921ee7e10acf01353ecd434a9931d33cc1eaba9ba27fa810077a999
BLAKE2b-256 checksum
How to use checksums
b0852091db1fc711afef762769e5c1e4ac5b9442787e55af3c444743bfd4be87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp314-cp314-macosx_15_0_arm64.whl

Download URL pyclipr-0.1.8-cp314-cp314-macosx_15_0_arm64.whl
Size 193.3 kB
Tags CPython 3.14 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
b0501fdfedfde2dca68018c987b54965c61f689203877bb46ba3692c231735ab
BLAKE2b-256 checksum
How to use checksums
692eea808a37078e9379990e059b6a69916b73375e3cb14a89eb604d9e541dc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp314-cp314-macosx_14_0_arm64.whl

Download URL pyclipr-0.1.8-cp314-cp314-macosx_14_0_arm64.whl
Size 198.6 kB
Tags CPython 3.14 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
a444bf4ff7940fc1417b6e6ca8f65c6c7226c2540033c29dec00e4d1f7cb7989
BLAKE2b-256 checksum
How to use checksums
2532f8cd08904dbd2cad91b68594da06afd5dacfd027f973988a61002c13773f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp313-cp313-win_amd64.whl

Download URL pyclipr-0.1.8-cp313-cp313-win_amd64.whl
Size 193.5 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
9ae1c856116fc3b46546f724ca20b1145f085b7bb09d2e743260db59615c2fcb
BLAKE2b-256 checksum
How to use checksums
b128b5b61d8083bfd0c375e1c4e9467f5fb5d40afccc51954b9fdec9997b3601
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp313-cp313-macosx_15_0_arm64.whl

Download URL pyclipr-0.1.8-cp313-cp313-macosx_15_0_arm64.whl
Size 192.9 kB
Tags CPython 3.13 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
6e377302f1f5c8f9e7b2da3f118c23b70f11da5089b3769bb9ea5b5650fd4560
BLAKE2b-256 checksum
How to use checksums
6f8a6f7ef580fc12fba2780b63a3f33e5f763ac05cca0ea8262a5f0510dcff6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp313-cp313-macosx_14_0_arm64.whl

Download URL pyclipr-0.1.8-cp313-cp313-macosx_14_0_arm64.whl
Size 198.0 kB
Tags CPython 3.13 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
16efa7fe9c0ddf2123629e3245c531b06d4e8cc1ad3a413c9f86f8d724212ff3
BLAKE2b-256 checksum
How to use checksums
a59849df896630649283202bb68b3fef828491796026e59b86be60f759f45cc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp312-cp312-win_amd64.whl

Download URL pyclipr-0.1.8-cp312-cp312-win_amd64.whl
Size 193.3 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
502e3404f72186a5571a0d9dddbc2c9b493cb3b56598d4800de3e67e5dc0a5fd
BLAKE2b-256 checksum
How to use checksums
a8a7756c10ddbf4f69eb37aeb3d895a29824d5285975db254570758eba57656a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp312-cp312-macosx_15_0_arm64.whl

Download URL pyclipr-0.1.8-cp312-cp312-macosx_15_0_arm64.whl
Size 192.8 kB
Tags CPython 3.12 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
f961a754b114f69f1638bafd98df60e2fba672ccd921ea5bf2173e271ede43f9
BLAKE2b-256 checksum
How to use checksums
bbbfe686ab34bf5f45a64548e590a6c794e6dcde56b8c08f1c60bec9ba620ec8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp312-cp312-macosx_14_0_arm64.whl

Download URL pyclipr-0.1.8-cp312-cp312-macosx_14_0_arm64.whl
Size 198.0 kB
Tags CPython 3.12 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
3517ce2f86f201bb7be0894bfd368d9e446e2b0c74914b80bdeee551ccc6ee82
BLAKE2b-256 checksum
How to use checksums
82d41758ae1390f02f7dccddec8186f04e1e982a59bd978918a381a10e7ccd67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp311-cp311-win_amd64.whl

Download URL pyclipr-0.1.8-cp311-cp311-win_amd64.whl
Size 192.2 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
c453c85664245beb94e1b2bf49f441faa640da73832a59cfa6a6fbd340e3d890
BLAKE2b-256 checksum
How to use checksums
c4e9b38300f5d15f404a6f5aa9050d6e33f6dbca334d649e60364cc89a8df1d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp311-cp311-macosx_15_0_arm64.whl

Download URL pyclipr-0.1.8-cp311-cp311-macosx_15_0_arm64.whl
Size 192.3 kB
Tags CPython 3.11 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
bcb37cee65c82229f34704c305b3ad174c3e91a108f5b9e95467b68036dd06dd
BLAKE2b-256 checksum
How to use checksums
f91c6d6e660f015362636bf0b0ae7d2f9eba110b1080d89dec355cdc6c0b8222
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp311-cp311-macosx_14_0_arm64.whl

Download URL pyclipr-0.1.8-cp311-cp311-macosx_14_0_arm64.whl
Size 196.4 kB
Tags CPython 3.11 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
d20f0e81671ad9e490036d68b475d65a54ad794f890b363ed4525004f4c9bedf
BLAKE2b-256 checksum
How to use checksums
639f26b36527d36d6589fa2e6148eddda63cfb355e6a157080f7887ad5ade88c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp310-cp310-win_amd64.whl

Download URL pyclipr-0.1.8-cp310-cp310-win_amd64.whl
Size 191.6 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
51f4203b8b8d6daaa456a19f3313b98dbfeb9bf8f63e7b7ecd1fa46fda8cc8a7
BLAKE2b-256 checksum
How to use checksums
8fbe6361ce98e03abc11e339b96d2f09d4c9820596f1db0366456800e2dc4eab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp310-cp310-macosx_15_0_arm64.whl

Download URL pyclipr-0.1.8-cp310-cp310-macosx_15_0_arm64.whl
Size 191.1 kB
Tags CPython 3.10 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
5030d1183176d183bc53c001e2f97805e9ed004a403cde4fed67045ca62efcd8
BLAKE2b-256 checksum
How to use checksums
4f141c3f2bcd7bba84134a28aa51819fe41273e74fe284095f50605c7082e8d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp310-cp310-macosx_14_0_arm64.whl

Download URL pyclipr-0.1.8-cp310-cp310-macosx_14_0_arm64.whl
Size 195.0 kB
Tags CPython 3.10 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
a7bcec2ba41b73dbb3d39075ebd8dc9f98025ed6feda521a313046e72dd68522
BLAKE2b-256 checksum
How to use checksums
aadab0b005aa9d1fe05391b8974b425c1fbb2351f9f6967811a023f9ca87821d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp39-cp39-win_amd64.whl

Download URL pyclipr-0.1.8-cp39-cp39-win_amd64.whl
Size 199.7 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
9ed5e9df0bf887e5ee947578d348e4e45c8fce307f4de2e5f63d43a8203f05c2
BLAKE2b-256 checksum
How to use checksums
8a76557e35a086b9fcbb3a785d71a737711a6786a00d893172bafe974717d050
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp39-cp39-macosx_15_0_arm64.whl

Download URL pyclipr-0.1.8-cp39-cp39-macosx_15_0_arm64.whl
Size 191.2 kB
Tags CPython 3.9 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
04920f97c5313f09a5a990078d56c6990143dbc21dbff899c32a0e34310df955
BLAKE2b-256 checksum
How to use checksums
22196ee9dee46038e523c070034d9942e6ccd0eb65e6390128b296cda6395bdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyclipr-0.1.8-cp39-cp39-macosx_14_0_arm64.whl

Download URL pyclipr-0.1.8-cp39-cp39-macosx_14_0_arm64.whl
Size 195.2 kB
Tags CPython 3.9 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
1657444d99dce19621a7e314800a3c755376311774e71416fd9a909f2706be06
BLAKE2b-256 checksum
How to use checksums
4700363586cf3c86d1dabe602d30c0ba882fca6e304c0570350047c0fbddaa11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.1.8 This release

19 release files

0.1.7

13 release files

0.1.6

12 release files

0.1.5

3 release files

0.1.4

12 release files

0.1.2

10 release files

0.1.1

10 release files

0.1.0

10 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page