From 608499a7ae74991c108b733220309a49ed7bbeeb Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Tue, 19 Nov 2019 13:14:06 -0500 Subject: [PATCH] ci=> actions, modernize package badge --- .coveragerc | 2 +- .flake8 | 5 +++++ .github/FUNDING.yml | 4 ++++ .github/workflows/ci_python.yml | 27 +++++++++++++++++++++++ DemoLineclip.py | 16 ++++++-------- LICENSE => LICENSE.txt | 0 README.md | 30 +++++++++++++++----------- .appveyor.yml => archive/.appveyor.yml | 1 - .travis.yml => archive/.travis.yml | 3 +-- build/bin/.ignore | 0 mypy.ini | 6 ++++++ pylineclip/__init__.py | 13 ++++++----- pyproject.toml | 5 +++++ pytest.ini | 2 ++ setup.cfg | 26 ++++++---------------- setup.py | 1 + tests/test_all.py | 9 +++----- 17 files changed, 94 insertions(+), 56 deletions(-) create mode 100644 .flake8 create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/ci_python.yml rename LICENSE => LICENSE.txt (100%) rename .appveyor.yml => archive/.appveyor.yml (99%) rename .travis.yml => archive/.travis.yml (99%) delete mode 100644 build/bin/.ignore create mode 100644 mypy.ini create mode 100644 pyproject.toml create mode 100644 pytest.ini diff --git a/.coveragerc b/.coveragerc index 8166e9d..07c9cee 100644 --- a/.coveragerc +++ b/.coveragerc @@ -17,4 +17,4 @@ exclude_lines = logging.warning logging.error logging.critical - if __name__ == .__main__.: + if __name__ == .__main__.: \ No newline at end of file diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..57a6c02 --- /dev/null +++ b/.flake8 @@ -0,0 +1,5 @@ +[flake8] +max-line-length = 132 +exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/ +per-file-ignores = + __init__.py:F401 diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..702f5b3 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms + +github: [scivision] +ko_fi: scivision diff --git a/.github/workflows/ci_python.yml b/.github/workflows/ci_python.yml new file mode 100644 index 0000000..8b1b6ea --- /dev/null +++ b/.github/workflows/ci_python.yml @@ -0,0 +1,27 @@ +name: ci_python + +on: + push: + paths: + - "**.py" + pull_request: + paths: + - "**.py" + +jobs: + + linux: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.5, '3.x'] + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - run: pip install .[tests,lint] + - run: flake8 + - run: mypy . + - run: pytest + working-directory: tests diff --git a/DemoLineclip.py b/DemoLineclip.py index dbcb712..461fd33 100755 --- a/DemoLineclip.py +++ b/DemoLineclip.py @@ -1,7 +1,6 @@ #!/usr/bin/env python -import numpy as np from pylineclip import cohensutherland - +from pytest import approx """ make box with corners LL/UR (1,3) (4,5) and line segment with ends (0,0) (4,6) @@ -10,19 +9,16 @@ def main(): # %% LOWER to UPPER test - x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, - 0, 0, 4, 6) + x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, 0, 0, 4, 6) - np.testing.assert_array_almost_equal([x1, y1, x2, y2], [2, 3, 3.3333333333333, 5]) + assert [x1, y1, x2, y2] == approx([2, 3, 3.3333333333333, 5]) # %% no intersection test - x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, - 0, 0.1, 0, 0.1) + x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, 0, 0.1, 0, 0.1) assert x1 is None and y1 is None and x2 is None and y2 is None # %% left to right test - x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, - 0, 4, 5, 4) - np.testing.assert_array_almost_equal([x1, y1, x2, y2], [1, 4, 4, 4]) + x1, y1, x2, y2 = cohensutherland(1, 5, 4, 3, 0, 4, 5, 4) + assert [x1, y1, x2, y2] == [1, 4, 4, 4] if __name__ == '__main__': diff --git a/LICENSE b/LICENSE.txt similarity index 100% rename from LICENSE rename to LICENSE.txt diff --git a/README.md b/README.md index 4d416d6..63f2d73 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -[![Travis CI](https://travis-ci.org/scivision/lineclipping-python-fortran.svg?branch=master)](https://travis-ci.org/scivision/lineclipping-python-fortran) -[![Coverage Status](https://coveralls.io/repos/github/scivision/lineclipping-python-fortran/badge.svg?branch=master)](https://coveralls.io/github/scivision/lineclipping-python-fortran?branch=master) -[![AppVeyor](https://ci.appveyor.com/api/projects/status/cr0omkhjvgwcyxiy?svg=true)](https://ci.appveyor.com/project/scivision/lineclipping-python-fortran) +[![Actions Status](https://github.com/scivision/lineclipping-python-fortran/workflows/ci_python/badge.svg)](https://github.com/scivision/lineclipping-python-fortran/actions) + + [![PyPi versions](https://img.shields.io/pypi/pyversions/pylineclip.svg)](https://pypi.python.org/pypi/pylineclip) [![PyPi Download stats](http://pepy.tech/badge/pylineclip)](http://pepy.tech/project/pylineclip) @@ -11,24 +11,30 @@ output intersections or `NaN` if no intersection. - `lineClipping.py` Cohen-Sutherland line clipping algorithm for Python. Input scalars, output intersection length, or `None` if no intersection. - - + + Julia line clipping is at https://github.com/scivision/lineclipping-julia ## Install -### Python +To install the latest release: + +```sh +pip install pylineclip +``` + - python -m pip install -e . ### Fortran If you want to use the Fortran Cohen-Sutherland line clipping modules directly (optional): - cd bin - cmake .. - make +```sh +meson build + +meson test -C build +``` ## Usage @@ -48,7 +54,7 @@ If no intersection, `(None, None, None, None)` is returned. ### Fortran -lineclipping.f90 has two subroutines. +lineclipping.f90 has two subroutines. Pick Ccohensutherland if you're calling from C/C++/Python, which cannot tolerate assummed-shape arrays. It's a slim wrapper to cohensutherland which is elemental (can handle scalar or any rank array). @@ -67,7 +73,7 @@ The arguments are: INOUT ----- - x1,y1,x2,y2: + x1,y1,x2,y2: in - endpoints of line out - intersection points with box. If no intersection, all NaN diff --git a/.appveyor.yml b/archive/.appveyor.yml similarity index 99% rename from .appveyor.yml rename to archive/.appveyor.yml index 495f1b7..64c08b5 100644 --- a/.appveyor.yml +++ b/archive/.appveyor.yml @@ -28,4 +28,3 @@ test_script: - ctest -V - cd .. - pytest -rsv - diff --git a/.travis.yml b/archive/.travis.yml similarity index 99% rename from .travis.yml rename to archive/.travis.yml index 6146320..0178a2c 100644 --- a/.travis.yml +++ b/archive/.travis.yml @@ -11,7 +11,7 @@ python: os: - linux - + env: FC=gfortran-6 addons: @@ -40,4 +40,3 @@ after_success: pytest --cov coveralls; fi - diff --git a/build/bin/.ignore b/build/bin/.ignore deleted file mode 100644 index e69de29..0000000 diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..5457c7e --- /dev/null +++ b/mypy.ini @@ -0,0 +1,6 @@ +[mypy] +ignore_missing_imports = True +strict_optional = False +allow_redefinition = True +show_error_context = False +show_column_numbers = True \ No newline at end of file diff --git a/pylineclip/__init__.py b/pylineclip/__init__.py index 3093f5c..b31ba95 100644 --- a/pylineclip/__init__.py +++ b/pylineclip/__init__.py @@ -1,10 +1,13 @@ #!/usr/bin/env python from typing import Union, Tuple + # from numba import jit ''' The MIT License (MIT) Copyright (c) 2014 Michael Hirsch + reference: http://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm + * The best way to Numba JIT this would probably be in the function calling this, to include the loop itself inside the jit decoration. ''' @@ -12,9 +15,9 @@ # @jit -def cohensutherland(xmin: float, ymax: float, xmax: float, ymin: float, - x1: float, y1: float, x2: float, y2: float) -> Tuple[ - Union[None, float], Union[None, float], Union[None, float], Union[None, float]]: +def cohensutherland( + xmin: float, ymax: float, xmax: float, ymin: float, x1: float, y1: float, x2: float, y2: float +) -> Tuple[float, float, float, float]: """Clips a line to a rectangular area. This implements the Cohen-Sutherland line clipping algorithm. xmin, @@ -45,11 +48,11 @@ def _getclip(xa, ya): p |= UPPER # bitwise OR return p -# check for trivially outside lines + # check for trivially outside lines k1 = _getclip(x1, y1) k2 = _getclip(x2, y2) -# %% examine non-trivially outside points + # %% examine non-trivially outside points # bitwise OR | while (k1 | k2) != 0: # if both points are inside box (0000) , ACCEPT trivial whole line in box diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..2f2c683 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,5 @@ +[build-system] +requires = ["setuptools", "wheel"] + +[tool.black] +line-length = 132 diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..b175c60 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +addopts = -ra -v diff --git a/setup.cfg b/setup.cfg index ff79034..2c3ceb2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = pylineclip -version = 0.9.2 +version = 1.0.0 description = Line clipping: Cohen-Sutherland author = Michael Hirsch, Ph.D. url = https://github.com/scivision/lineclipping-python-fortran @@ -17,36 +17,24 @@ classifiers = Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 Topic :: Scientific/Engineering :: Visualization -license_file = LICENSE +license_files = + LICENSE.txt long_description = file: README.md long_description_content_type = text/markdown [options] python_requires = >= 3.5 -setup_requires = - setuptools >= 38.6 - pip >= 10 - twine >= 1.11 include_package_data = True +zip_safe = False packages = find: install_requires = - numpy [options.extras_require] tests = pytest -cov = - pytest-cov - coveralls +lint = flake8 mypy - -[options.entry_points] -console_scripts = - DemoLineclip = DemoLineclip:main - -[flake8] -max-line-length = 132 -exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/ - diff --git a/setup.py b/setup.py index bb42283..c823345 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ #!/usr/bin/env python from setuptools import setup + setup() diff --git a/tests/test_all.py b/tests/test_all.py index 9982b7b..eba4b25 100755 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -10,18 +10,15 @@ def test_lineclip(): and line segment with ends (0,0) (4,6) """ # %% LOWER to UPPER test - x1, y1, x2, y2 = plc.cohensutherland(1, 5, 4, 3, - 0, 0, 4, 6) + x1, y1, x2, y2 = plc.cohensutherland(1, 5, 4, 3, 0, 0, 4, 6) assert [x1, y1, x2, y2] == approx([2, 3, 3.3333333333333, 5]) # %% no intersection test - x1, y1, x2, y2 = plc.cohensutherland(1, 5, 4, 3, - 0, 0.1, 0, 0.1) + x1, y1, x2, y2 = plc.cohensutherland(1, 5, 4, 3, 0, 0.1, 0, 0.1) assert x1 is None and y1 is None and x2 is None and y2 is None # %% left to right test - x1, y1, x2, y2 = plc.cohensutherland(1, 5, 4, 3, - 0, 4, 5, 4) + x1, y1, x2, y2 = plc.cohensutherland(1, 5, 4, 3, 0, 4, 5, 4) assert [x1, y1, x2, y2] == [1, 4, 4, 4]