Skip to main content

Python port of polygon clipping algorithm by F. Martinez et al.

Project description

martinez

In what follows

  • python is an alias for python3.5 or any later version (python3.6 and so on).

Installation

Install the latest pip & setuptools packages versions:

python -m pip install --upgrade pip setuptools

User

Download and install the latest stable version from PyPI repository:

python -m pip install --upgrade martinez

Developer

Download the latest version from GitHub repository

git clone https://github.com/lycantropos/martinez.git
cd martinez

Install dependencies:

python -m pip install --force-reinstall -r requirements.txt

Install:

python setup.py install

Usage

>>> from martinez.contour import Contour
>>> from martinez.point import Point
>>> from martinez.polygon import Polygon
>>> left_polygon = Polygon([Contour([Point(0.0, 0.0), Point(2.0, 0.0), Point(2.0, 2.0), Point(0.0, 2.0)], [], True)])
>>> right_polygon = Polygon([Contour([Point(1.0, 1.0), Point(3.0, 1.0), Point(3.0, 3.0), Point(1.0, 3.0)], [], True)])
>>> from martinez.boolean import OperationType, compute
>>> compute(left_polygon, right_polygon, OperationType.INTERSECTION)
Polygon([Contour([Point(1.0, 1.0), Point(2.0, 1.0), Point(2.0, 2.0), Point(1.0, 2.0)], [], True)])
>>> compute(left_polygon, right_polygon, OperationType.UNION)
Polygon([Contour([Point(0.0, 0.0), Point(2.0, 0.0), Point(2.0, 1.0), Point(3.0, 1.0), Point(3.0, 3.0), Point(1.0, 3.0), Point(1.0, 2.0), Point(0.0, 2.0)], [], True)])
>>> compute(left_polygon, right_polygon, OperationType.DIFFERENCE)
Polygon([Contour([Point(0.0, 0.0), Point(2.0, 0.0), Point(2.0, 1.0), Point(1.0, 1.0), Point(1.0, 2.0), Point(0.0, 2.0)], [], True)])
>>> compute(left_polygon, right_polygon, OperationType.XOR)
Polygon([Contour([Point(0.0, 0.0), Point(2.0, 0.0), Point(2.0, 1.0), Point(1.0, 1.0), Point(1.0, 2.0), Point(0.0, 2.0)], [], True), Contour([Point(1.0, 2.0), Point(2.0, 2.0), Point(2.0, 1.0), Point(3.0, 1.0), Point(3.0, 3.0), Point(1.0, 3.0)], [], True)])

original C++ implementation can be invoked by importing from _martinez module instead.

Development

Bumping version

Preparation

Install bump2version.

Pre-release

Choose which version number category to bump following semver specification.

Test bumping version

bump2version --dry-run --verbose $CATEGORY

where $CATEGORY is the target version number category name, possible values are patch/minor/major.

Bump version

bump2version --verbose $CATEGORY

This will set version to major.minor.patch-alpha.

Release

Test bumping version

bump2version --dry-run --verbose release

Bump version

bump2version --verbose release

This will set version to major.minor.patch.

Running tests

Install dependencies:

python -m pip install --force-reinstall -r requirements-tests.txt

Plain

pytest

Inside Docker container:

docker-compose up

Bash script (e.g. can be used in Git hooks):

./run-tests.sh

PowerShell script (e.g. can be used in Git hooks):

.\run-tests.ps1

Project details


Download files

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

Source Distribution

martinez-0.5.2.tar.gz (23.3 kB view hashes)

Uploaded Source

Built Distributions

martinez-0.5.2-cp38-cp38-win_amd64.whl (157.7 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

martinez-0.5.2-cp38-cp38-win32.whl (138.1 kB view hashes)

Uploaded CPython 3.8 Windows x86

martinez-0.5.2-cp38-cp38-manylinux2010_x86_64.whl (2.9 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

martinez-0.5.2-cp38-cp38-manylinux2010_i686.whl (2.8 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

martinez-0.5.2-cp37-cp37m-win_amd64.whl (157.5 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

martinez-0.5.2-cp37-cp37m-win32.whl (140.0 kB view hashes)

Uploaded CPython 3.7m Windows x86

martinez-0.5.2-cp37-cp37m-manylinux2010_x86_64.whl (3.0 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

martinez-0.5.2-cp37-cp37m-manylinux2010_i686.whl (2.9 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686

martinez-0.5.2-cp36-cp36m-win_amd64.whl (157.4 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

martinez-0.5.2-cp36-cp36m-win32.whl (140.0 kB view hashes)

Uploaded CPython 3.6m Windows x86

martinez-0.5.2-cp36-cp36m-manylinux2010_x86_64.whl (3.0 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

martinez-0.5.2-cp36-cp36m-manylinux2010_i686.whl (2.9 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686

martinez-0.5.2-cp35-cp35m-win_amd64.whl (157.4 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

martinez-0.5.2-cp35-cp35m-win32.whl (140.0 kB view hashes)

Uploaded CPython 3.5m Windows x86

martinez-0.5.2-cp35-cp35m-manylinux2010_x86_64.whl (3.0 MB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ x86-64

martinez-0.5.2-cp35-cp35m-manylinux2010_i686.whl (2.2 MB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ i686

martinez-0.5.2-cp35-cp35m-macosx_10_9_x86_64.whl (250.4 kB view hashes)

Uploaded CPython 3.5m macOS 10.9+ x86-64

Supported by

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