Skip to main content

gon

Summary

gon is a pure Python library that provides support for planar geometry objects built from discrete points, finite number of straight line segments (e.g. polylines) and areas bound by closed polylines (e.g. polygons).

Main features are

  • convenience: all geometric objects are immutable, hashable and implement set-like interface, i.e. support containment, equality, "is-subset" tests and boolean set operations (e.g. finding intersection).
  • correctness: all calculations are robust for floating point numbers & precise for integral numbers (like int), each operation corresponds to its mathematical definition and property-based tested.
  • efficiency: all operations are efficient in terms of both time & memory complexity, upper bound for expected time complexity is O(n * log n), for memory complexity is O(n).

In what follows python is an alias for python3.7 or pypy3.7 or any later version (python3.7, pypy3.8 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 gon

Developer

Download the latest version from GitHub repository

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

Install dependencies

python -m pip install -r requirements.txt

Install

python setup.py install

Usage

>>> from gon.base import EMPTY, Angle, Contour, Point, Polygon
>>> square = Polygon(Contour([Point(0, 0), Point(4, 0), Point(4, 4),
...                           Point(0, 4)]))
>>> square == square
True
>>> square >= square
True
>>> square <= square
True
>>> square < square
False
>>> square > square
False
>>> square & square == square
True
>>> square | square == square
True
>>> square - square is EMPTY
True
>>> square ^ square is EMPTY
True
>>> Point(0, 0) in square
True
>>> square.index()
>>> Point(0, 0) in square
True
>>> len(square.border.vertices) == 4
True
>>> len(square.holes) == 0
True
>>> square.is_convex
True
>>> square.convex_hull == square
True
>>> square.area == 16
True
>>> square.perimeter == 16
True
>>> square.centroid == Point(2, 2)
True
>>> square.distance_to(Point(2, 2)) == 0
True
>>> square.distance_to(Point(7, 8)) == 5
True
>>> (square.rotate(Angle(0, 1), Point(4, 4))
...  == Polygon(Contour([Point(8, 0), Point(8, 4), Point(4, 4), Point(4, 0)])))
True
>>> (square.scale(1, 2)
...  == Polygon(Contour([Point(0, 0), Point(4, 0), Point(4, 8), Point(0, 8)])))
True
>>> (square.translate(1, 2)
...  == Polygon(Contour([Point(1, 2), Point(5, 2), Point(5, 6), Point(1, 6)])))
True
>>> (square.triangulate().triangles()
...  == [Contour([Point(0, 4), Point(4, 0), Point(4, 4)]),
...      Contour([Point(0, 0), Point(4, 0), Point(0, 4)])])
True

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 -r requirements-tests.txt

Plain

pytest

Inside Docker container:

  • with CPython
    docker-compose --file docker-compose.cpython.yml up
    
  • with PyPy
    docker-compose --file docker-compose.pypy.yml up
    

Bash script:

  • with CPython

    ./run-tests.sh
    

    or

    ./run-tests.sh cpython
    
  • with PyPy

    ./run-tests.sh pypy
    

PowerShell script:

  • with CPython
    .\run-tests.ps1
    
    or
    .\run-tests.ps1 cpython
    
  • with PyPy
    .\run-tests.ps1 pypy
    

Metadata

Release files for gon 6.0.0

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

Source distribution (sdist)

Source distribution for gon 6.0.0
File Size Uploaded Provenance Actions
gon-6.0.0.tar.gz 36.6 kB Without provenance Details for gon-6.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gon 6.0.0
File Interpreter ABI Platform Actions
gon-6.0.0-py3-none-any.whl Python 3 none any Details for gon-6.0.0-py3-none-any.whl

Total release size: 79.2 kB

Release files / gon-6.0.0.tar.gz

Download URL gon-6.0.0.tar.gz
Size 36.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a2c0a708d34e3470018e7b29dffb520abcb3d97daa8cdba6b401c483f624db0b
BLAKE2b-256 checksum
How to use checksums
d4d3af8de2e1cc1685f7c9b098c58204328fcbdb24b29a4a7805b921cf3e26d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / gon-6.0.0-py3-none-any.whl

Download URL gon-6.0.0-py3-none-any.whl
Size 42.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c2e6f4daa271bfac27a6e16f111bdbd1b23cd83dab09fa0782ee4398c4cd5d5
BLAKE2b-256 checksum
How to use checksums
c894447c399e1256b84d1ddc180de9d1d1625a4f158202bae01cff1ec63da35c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Security for gon 6.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

6.0.0 This release

2 release files No provenance

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