Skip to main content

Python library for polygon clipping and offsetting based on Clipper2.

Project description

https://github.com/drlukeparry/pyclipr/actions/workflows/pythonpublish.yml/badge.svg https://badge.fury.io/py/pyclipr.svg https://static.pepy.tech/personalized-badge/pyclipr?period=total&units=international_system&left_color=black&right_color=orange&left_text=Downloads

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 is currently supported on Windows, Mac. No special requirements or prerequeisites are necessary.

conda install -c numpy
pip install numpy

Installation of pycork can then be performed using 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 on Windows 10, using VS2019. E

Ensure that you perform the recurisve submodule when initialising the repoistory.

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

python setup.py install

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.

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

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 = [(0, 0), (0, 50), (100, 50), (100, 0), (0,0)]


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

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

# add the path - ensuring to use Polygon for the endType argument
po.addPath(np.array(path), pyclipr.Miter, pyclipr.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.EvenOdd)
out2 = pc.execute(pyclipr.Union, pyclipr.EvenOdd)
out3 = pc.execute(pyclipr.Difference, pyclipr.EvenOdd)
out4 = pc.execute(pyclipr.Xor, pyclipr.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.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( ((50,-10),(50,110)), 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.NonZero)
outC2, openPathsC = pc2.execute(pyclipr.Intersection, pyclipr.NonZero, returnOpenPaths=True)

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyclipr-0.1.2-cp311-cp311-win_amd64.whl (154.4 kB view details)

Uploaded CPython 3.11Windows x86-64

pyclipr-0.1.2-cp311-cp311-macosx_12_0_universal2.whl (177.1 kB view details)

Uploaded CPython 3.11macOS 12.0+ universal2 (ARM64, x86-64)

pyclipr-0.1.2-cp310-cp310-win_amd64.whl (153.6 kB view details)

Uploaded CPython 3.10Windows x86-64

pyclipr-0.1.2-cp310-cp310-macosx_12_0_x86_64.whl (175.8 kB view details)

Uploaded CPython 3.10macOS 12.0+ x86-64

pyclipr-0.1.2-cp39-cp39-win_amd64.whl (153.7 kB view details)

Uploaded CPython 3.9Windows x86-64

pyclipr-0.1.2-cp39-cp39-macosx_12_0_x86_64.whl (175.9 kB view details)

Uploaded CPython 3.9macOS 12.0+ x86-64

pyclipr-0.1.2-cp38-cp38-win_amd64.whl (153.6 kB view details)

Uploaded CPython 3.8Windows x86-64

pyclipr-0.1.2-cp38-cp38-macosx_12_0_x86_64.whl (175.8 kB view details)

Uploaded CPython 3.8macOS 12.0+ x86-64

pyclipr-0.1.2-cp37-cp37m-win_amd64.whl (153.8 kB view details)

Uploaded CPython 3.7mWindows x86-64

pyclipr-0.1.2-cp37-cp37m-macosx_12_0_x86_64.whl (173.9 kB view details)

Uploaded CPython 3.7mmacOS 12.0+ x86-64

File details

Details for the file pyclipr-0.1.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pyclipr-0.1.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 154.4 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pyclipr-0.1.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 319d78baf6731cd81773910c2cfa39769eac8f97758f276974fd1d750e9badd1
MD5 0e0867841a75cbb4a711ed0b2effc37e
BLAKE2b-256 34826453560a1d7d075d7ef955c3b778a22ac348ea6ada541765b87196b29ab2

See more details on using hashes here.

File details

Details for the file pyclipr-0.1.2-cp311-cp311-macosx_12_0_universal2.whl.

File metadata

File hashes

Hashes for pyclipr-0.1.2-cp311-cp311-macosx_12_0_universal2.whl
Algorithm Hash digest
SHA256 5d7b0f47c1d36fb517bcb56947ff02ff826adc9285627d00221be9c5629da031
MD5 a4ff156a8ff9aa7dca3204c99ba4faef
BLAKE2b-256 45ddfcf6fc0efa7b37939b11069fd8c6a0c64af7b491e0c03edafe70dfddea4e

See more details on using hashes here.

File details

Details for the file pyclipr-0.1.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pyclipr-0.1.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 153.6 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for pyclipr-0.1.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 796e4c159ada3149eec3802965d03cdf934d169358e0cca0d6084a4ff40181ec
MD5 02a74d21e0680bd944a1ef0bb4d9ff84
BLAKE2b-256 a01a68c33aeba25048dd36501204a02b8b56064604ec1c05b12fc80570ccbae0

See more details on using hashes here.

File details

Details for the file pyclipr-0.1.2-cp310-cp310-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for pyclipr-0.1.2-cp310-cp310-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 2b8c332e76d4af9804cceeeb11f7d935daf3f15a7db4df38aa68e2d2723b2229
MD5 4921c181330945dfc346680ab85a7513
BLAKE2b-256 a0f646dd29d600448727aa95caad4d431825a13322d4bdb20960f2b86de195f9

See more details on using hashes here.

File details

Details for the file pyclipr-0.1.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pyclipr-0.1.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 153.7 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for pyclipr-0.1.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 7c611e849b2db8339954f35a6aba8a851bd18afb0233a6e5eba602b58b6c5153
MD5 469847f5427803c2662fc42ee902bcc4
BLAKE2b-256 77c44c7ffc0f3a8cefc7cd11753a617eb4b5bb576eb5d90f51c002aaab4475f8

See more details on using hashes here.

File details

Details for the file pyclipr-0.1.2-cp39-cp39-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for pyclipr-0.1.2-cp39-cp39-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 0e38a022973411caa43049a4d9af2e63cc219db88a6974ef5baf18e3fe5fff59
MD5 15f8a006a88bf98dc734158d9f7249e4
BLAKE2b-256 57fea6f30831791f525ee0defe1813af0748df07717ac1b573ec408a213b222f

See more details on using hashes here.

File details

Details for the file pyclipr-0.1.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pyclipr-0.1.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 153.6 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for pyclipr-0.1.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 b463bb9f268a18948d85c5badd249b8356c0d24b46fa472774a5ab7b442a9f6d
MD5 d45e0f184d05a0557d17ec4d6bc7ee0d
BLAKE2b-256 6f84d5a4fd6b92f50f4a4be5b8e6b0445e99e39bd246bb6620c894b7df899a52

See more details on using hashes here.

File details

Details for the file pyclipr-0.1.2-cp38-cp38-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for pyclipr-0.1.2-cp38-cp38-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 c4d62cc4703a5877e6af543a1720b09c4bb90aaef1b5b4bfd44e27b486bf8e6d
MD5 7c23462c2d8932d70c2a9a6f3fe9bf3f
BLAKE2b-256 68c012653c9d432aaba4c8b3caf9be8401edb9b317867dd79f3a5da3400a7b72

See more details on using hashes here.

File details

Details for the file pyclipr-0.1.2-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: pyclipr-0.1.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 153.8 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.9

File hashes

Hashes for pyclipr-0.1.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 48104a52dcc964801053c6c8ffe5dd41acf19629b6ce85c0c4986d83d23ba545
MD5 b62f36ffe7d60894ff6734725c0458c3
BLAKE2b-256 6d866587fc12e90b3ac35e4de6186fed66d71e939f03cd39a00cf8895d1b747c

See more details on using hashes here.

File details

Details for the file pyclipr-0.1.2-cp37-cp37m-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for pyclipr-0.1.2-cp37-cp37m-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 11e3e4e64224753a32956ff19b9af8a4ed00b4831127801e9a78bf6378a79760
MD5 73734a9f560f9451d301ebf88544d14c
BLAKE2b-256 0869f1dbc46a79113988373a885048b79dc15a5b8fccefc4ab43436c56266505

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page