项目作者: lycantropos

项目描述 :
Correct processing of planar geometry objects (boolean operations, plain/constrained Delaunay triangulation, convex hull, etc.)
高级语言: Python
项目地址: git://github.com/lycantropos/gon.git
创建时间: 2019-07-01T04:06:06Z
项目社区:https://github.com/lycantropos/gon

开源协议:MIT License

下载


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

  1. python -m pip install --upgrade pip setuptools

User

Download and install the latest stable version from PyPI repository

  1. python -m pip install --upgrade gon

Developer

Download the latest version from GitHub repository

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

Install dependencies

  1. python -m pip install -r requirements.txt

Install

  1. python setup.py install

Usage

  1. >>> from gon.base import EMPTY, Angle, Contour, Point, Polygon
  2. >>> square = Polygon(Contour([Point(0, 0), Point(4, 0), Point(4, 4),
  3. ... Point(0, 4)]))
  4. >>> square == square
  5. True
  6. >>> square >= square
  7. True
  8. >>> square <= square
  9. True
  10. >>> square < square
  11. False
  12. >>> square > square
  13. False
  14. >>> square & square == square
  15. True
  16. >>> square | square == square
  17. True
  18. >>> square - square is EMPTY
  19. True
  20. >>> square ^ square is EMPTY
  21. True
  22. >>> Point(0, 0) in square
  23. True
  24. >>> square.index()
  25. >>> Point(0, 0) in square
  26. True
  27. >>> len(square.border.vertices) == 4
  28. True
  29. >>> len(square.holes) == 0
  30. True
  31. >>> square.is_convex
  32. True
  33. >>> square.convex_hull == square
  34. True
  35. >>> square.area == 16
  36. True
  37. >>> square.perimeter == 16
  38. True
  39. >>> square.centroid == Point(2, 2)
  40. True
  41. >>> square.distance_to(Point(2, 2)) == 0
  42. True
  43. >>> square.distance_to(Point(7, 8)) == 5
  44. True
  45. >>> (square.rotate(Angle(0, 1), Point(4, 4))
  46. ... == Polygon(Contour([Point(8, 0), Point(8, 4), Point(4, 4), Point(4, 0)])))
  47. True
  48. >>> (square.scale(1, 2)
  49. ... == Polygon(Contour([Point(0, 0), Point(4, 0), Point(4, 8), Point(0, 8)])))
  50. True
  51. >>> (square.translate(1, 2)
  52. ... == Polygon(Contour([Point(1, 2), Point(5, 2), Point(5, 6), Point(1, 6)])))
  53. True
  54. >>> (square.triangulate().triangles()
  55. ... == [Contour([Point(0, 4), Point(4, 0), Point(4, 4)]),
  56. ... Contour([Point(0, 0), Point(4, 0), Point(0, 4)])])
  57. True

Development

Bumping version

Preparation

Install
bump2version.

Pre-release

Choose which version number category to bump following semver
specification
.

Test bumping version

  1. bump2version --dry-run --verbose $CATEGORY

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

Bump version

  1. bump2version --verbose $CATEGORY

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

Release

Test bumping version

  1. bump2version --dry-run --verbose release

Bump version

  1. bump2version --verbose release

This will set version to major.minor.patch.

Running tests

Install dependencies

  1. python -m pip install -r requirements-tests.txt

Plain

  1. pytest

Inside Docker container:

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

Bash script:

  • with CPython

    1. ./run-tests.sh

    or

    1. ./run-tests.sh cpython
  • with PyPy

    1. ./run-tests.sh pypy

PowerShell script:

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