{"id":18356568,"url":"https://github.com/drlukeparry/pyclipr","last_synced_at":"2026-02-01T16:01:15.472Z","repository":{"id":164965916,"uuid":"627638152","full_name":"drlukeparry/pyclipr","owner":"drlukeparry","description":"Python Polygon Clipping and Offsetting based on Clipper2 Library","archived":false,"fork":false,"pushed_at":"2025-08-18T00:04:12.000Z","size":95,"stargazers_count":28,"open_issues_count":12,"forks_count":11,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-18T00:21:36.741Z","etag":null,"topics":["clipper","clipper2","polygon","polygon-clipping","polygon-intersection","polygon-offsetting","python"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drlukeparry.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-04-13T22:15:11.000Z","updated_at":"2025-05-05T10:53:08.000Z","dependencies_parsed_at":"2024-01-10T21:57:35.553Z","dependency_job_id":"4b433c3b-3658-4f9a-8591-3dddc88d6daf","html_url":"https://github.com/drlukeparry/pyclipr","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/drlukeparry/pyclipr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drlukeparry%2Fpyclipr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drlukeparry%2Fpyclipr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drlukeparry%2Fpyclipr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drlukeparry%2Fpyclipr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drlukeparry","download_url":"https://codeload.github.com/drlukeparry/pyclipr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drlukeparry%2Fpyclipr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28981893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T15:35:50.179Z","status":"ssl_error","status_checked_at":"2026-02-01T15:35:38.075Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clipper","clipper2","polygon","polygon-clipping","polygon-intersection","polygon-offsetting","python"],"created_at":"2024-11-05T22:10:46.569Z","updated_at":"2026-02-01T16:01:15.464Z","avatar_url":"https://github.com/drlukeparry.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"Pyclipr - Python Polygon and Offsetting Library (Clipper2 Bindings)\n========================================================================\n\n|ci-badge| |pypi-badge| |license-badge| |pepy-badge|  |python-badge| |py-version-badge|\n\n.. |ci-badge| image:: https://img.shields.io/github/actions/workflow/status/drlukeparry/pyclipr/cd.yml\n    :alt: GitHub Actions Workflow Status\n.. |pypi-badge| image:: https://badge.fury.io/py/pyclipr.svg\n    :target: https://pypi.python.org/pypi/pyclipr/\n.. |license-badge| image:: https://img.shields.io/github/license/drlukeparry/pyclipr\n     :alt: GitHub License\n.. |pepy-badge| image:: https://static.pepy.tech/personalized-badge/pyclipr?period=total\u0026units=international_system\u0026left_color=black\u0026right_color=orange\u0026left_text=Downloads\n    :target: https://pepy.tech/project/pyclipr\n.. |python-badge| image:: https://img.shields.io/badge/Made%20with-Python-1f425f.svg\n   :target: https://www.python.org/\n.. |py-version-badge| image:: https://img.shields.io/pypi/pyversions/pyclipr.svg\n    :target: https://pypi.python.org/pypi/pyclipr/\n\n\nPyclipr is a Python library offering the functionality of the `Clipper2 \u003chttp://www.angusj.com/clipper2/Docs/Overview.htm\u003e`_\npolygon clipping and offsetting library and are built upon `pybind \u003chttps://pybind11.readthedocs.io/en/stable/basics.html\u003e`_ .\nThe underlying Clipper2 library performs intersection, union, difference and XOR boolean operations on both simple and\ncomplex polygons and also performs offsetting of polygons and inflation of paths.\n\nUnlike `pyclipper \u003chttps://pypi.org/project/pyclipper/\u003e`_, this library is not built using cython. Instead the full use of\ncapability pybind is exploited. This library aims to provide convenient access to the Clipper2 library for Python users,\nespecially with its usage in 3D Printing and computer graphics applications.\n\nFor further information, see the latest `release notes \u003chttps://github.com/drlukeparry/pyclipr/blob/master/CHANGELOG.md\u003e`_.\n\nInstallation\n*************\n\nInstallation using pre-built packages are currently supported on Windows, Mac but excludes Linux because pre-built\npackages are unsupported via PyPi. Otherwise, no special requirements or prerequisites are necessary.\n\n.. code:: bash\n\n    conda install -c numpy\n    pip install numpy\n\nInstallation of `pyclipr` can then be performed using the pre-built python packages using the PyPi repository.\n\n.. code:: bash\n\n    pip install pyclipr\n\nAlternatively, pyclipr may be compiled directly from source within the python environment. Currently the prerequisites\nare the a compliant c++ build environment include CMake build system (\u003ev3.15) and the availability of a compiler with\nc++17 compatibility.  Currently the package has been tested built using Windows 10, using VS2019 and Mac OSX Sonoma.\n\nFirstly, clone the pyclipr repository whilst ensuring that you perform the recurisve submodule when initialising\nthe repoistory. This ensures that all dependencies (•pybind, • pyclipr, •eigen) are downloaded into the source tree.\n\n.. code:: bash\n\n    git clone https://github.com/drlukeparry/pyclipr.git \u0026\u0026 cd ./pyclipr\n    git submodule update --init --recursive\n\n    python -m build\n\nUsage\n******\n\nThe pyclipr library follows similar structure to that documented in `Clipper2 \u003chttp://www.angusj.com/clipper2/Docs/Overview.htm\u003e`_\nlibrary. Although for consistency most methods are implemented using camelCase naming convention and more generic\nfunctions are provided for the addition of paths.\n\nThe library assumes that coordinates are provided and scaled by a ``scaleFactor``  (*default = 1e3*), set within\nthe ``Clipper`` and ``ClipperOffset`` classes to ensure correct numerical robustness outlined in the underlying Clipper\nlibrary. The coordinates for the paths may be provided as a list of tuples or a numpy array. The internal scale factor\ndetermines the precision of the clipping and offsetting operations but can impact performance. It is recommended to\nadjust this in accordance to your applications.\n\nBoth ``Path64`` and ``PolyTree64`` structures are supported from the clipping and offsetting operations, which are\nenacted by using either `execute` or `execute2` methods, respectively.\n\nA variety of other utilities are provided for inspection of polygons and paths.\n\n.. code:: python\n\n    import numpy as np\n    import pyclipr\n\n    # Tuple definition of a path\n    path = [(0.0, 0.), (0, 105.1234), (100, 105.1234), (100, 0), (0, 0)]\n    path2 = [(1.0, 1.0), (1.0, 50), (100, 50), (100, 1.0), (1.0,1.0)]\n\n    # Create an offsetting object\n    po = pyclipr.ClipperOffset()\n\n    # Set the scale factor to convert to internal integer representation\n    po.scaleFactor = int(1000)\n\n    # add the path - ensuring to use Polygon for the endType argument\n    # addPaths is required when working with polygon - this is a list of correctly orientated paths for exterior\n    # and interior holes\n    po.addPaths([np.array(path)], pyclipr.JoinType.Miter, pyclipr.EndType.Polygon)\n\n    # Apply the offsetting operation using a delta.\n    offsetSquare = po.execute(10.0)\n\n    # Create a clipping object\n    pc = pyclipr.Clipper()\n    pc.scaleFactor = int(1000)\n\n    # Add the paths to the clipping object. Ensure the subject and clip arguments are set to differentiate\n    # the paths during the Boolean operation. The final argument specifies if the path is\n    # open.\n    pc.addPaths(offsetSquare, pyclipr.Subject)\n    pc.addPath(np.array(path2), pyclipr.Clip)\n\n    \"\"\" Test Polygon Clipping \"\"\"\n    # Below returns paths\n    out  = pc.execute(pyclipr.Intersection, pyclipr.FillRule.EvenOdd)\n    out2 = pc.execute(pyclipr.Union, pyclipr.FillRule.EvenOdd)\n    out3 = pc.execute(pyclipr.Difference, pyclipr.FillRule.EvenOdd)\n    out4 = pc.execute(pyclipr.Xor, pyclipr.FillRule.EvenOdd)\n\n    # Using execute2 returns a PolyTree structure that provides hierarchical information inflormation\n    # if the paths are interior or exterior\n    outB = pc.execute2(pyclipr.Intersection, pyclipr.FillRule.EvenOdd)\n\n    # An alternative equivalent name is executeTree\n    outB = pc.executeTree(pyclipr.Intersection, pyclipr.FillRule.EvenOdd)\n\n    \"\"\" Test Open Path Clipping \"\"\"\n    # Pyclipr can be used for clipping open paths.  This remains simple to complete using the Clipper2 library\n\n    pc2 = pyclipr.Clipper()\n    pc2.scaleFactor = int(1e5)\n\n    # The open path is added as a subject (note the final argument is set to True)\n    pc2.addPath( ((40,-10),(50,130)), pyclipr.Subject, True)\n\n    # The clipping object is usually set to the Polygon\n    pc2.addPaths(offsetSquare, pyclipr.Clip, False)\n\n    \"\"\" Test the return types for open path clipping with option enabled\"\"\"\n    # The returnOpenPaths argument is set to True to return the open paths. Note this function only works\n    # well using the Boolean intersection option\n    outC = pc2.execute(pyclipr.Intersection, pyclipr.FillRule.NonZero)\n    outC2, openPathsC = pc2.execute(pyclipr.Intersection, pyclipr.FillRule.NonZero, returnOpenPaths=True)\n\n    outD = pc2.execute2(pyclipr.Intersection,  pyclipr.FillRule.NonZero)\n    outD2, openPathsD = pc2.execute2(pyclipr.Intersection,  pyclipr.FillRule.NonZero, returnOpenPaths=True)\n\n    # Plot the results\n    pathPoly = np.array(path)\n\n    import matplotlib.pyplot as plt\n    plt.figure()\n    plt.axis('equal')\n\n    # Plot the original polygon\n    plt.fill(pathPoly[:,0], pathPoly[:,1], 'b', alpha=0.1, linewidth=1.0, linestyle='dashed', edgecolor='#000')\n\n    # Plot the offset square\n    plt.fill(offsetSquare[0][:, 0], offsetSquare[0][:, 1], linewidth=1.0, linestyle='dashed', edgecolor='#333', facecolor='none')\n\n    # Plot the intersection\n    plt.fill(out[0][:, 0], out[0][:, 1],  facecolor='#75507b')\n\n    # Plot the open path intersection\n    plt.plot(openPathsC[0][:,0], openPathsC[0][:,1],color='#222', linewidth=1.0, linestyle='dashed', marker='.',markersize=20.0)\n\n    \"\"\" Utility Functions \"\"\"\n\n    # Simplification of Paths\n    rect = [(0,0), (100,0), (100,100), (0,100), (0,0)]\n    rect2 = [(20,0), (20,10), (30,10), (30,0), (20,0)]\n\n    simplifiedPaths = pyclipr.simplifyPaths([rect, rect2], epsilon=0.001)\n\n    # Check the orientation of a path (True if Counter-Clockwise)\n    isCCW = pyclipr.orientation(rect)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrlukeparry%2Fpyclipr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrlukeparry%2Fpyclipr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrlukeparry%2Fpyclipr/lists"}