diff --git a/.appveyor.yml b/.appveyor.yml index 52827da..495f1b7 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,6 +1,6 @@ image: - Visual Studio 2017 -- Ubuntu +- Ubuntu1804 stack: python 3 @@ -19,7 +19,7 @@ init: install: - pip install -e .[tests] -- cd bin +- cd build - cmd: cmake -G "MinGW Makefiles" -DCMAKE_SH="CMAKE_SH-NOTFOUND" .. - sh: cmake .. - cmake --build . diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..8166e9d --- /dev/null +++ b/.coveragerc @@ -0,0 +1,20 @@ +[run] +cover_pylib = false +omit = + /home/travis/virtualenv/* + */site-packages/* + */bin/* + +[report] +exclude_lines = + pragma: no cover + def __repr__ + except RuntimeError + except NotImplementedError + except ImportError + except FileNotFoundError + except CalledProcessError + logging.warning + logging.error + logging.critical + if __name__ == .__main__.: diff --git a/.gitignore b/.gitignore index 74a174d..59dfe54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ + +build/ .pytest_cache/ bin/ diff --git a/.travis.yml b/.travis.yml index eef44c5..6146320 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: python group: travis_latest +dist: xenial git: depth: 3 @@ -19,23 +20,15 @@ addons: packages: gfortran-6 -before_install: -- if [[ $TRAVIS_OS_NAME == osx ]]; then - brew update > /dev/null; - brew install gcc > /dev/null || brew link --overwrite gcc > /dev/null; - export FC=gfortran; - brew install opencoarrays > /dev/null; - fi - install: -- pip install -e .[tests] +- pip install -e .[tests,cov] -- cd bin +- cd build - cmake .. - cmake --build . script: -- ctest -V +- ctest --output-on-failure - cd .. - pytest -rsv @@ -44,7 +37,7 @@ script: after_success: - if [[ $TRAVIS_PYTHON_VERSION == 3.6* ]]; then - pytest --cov --cov-config=setup.cfg; + pytest --cov coveralls; fi diff --git a/README.md b/README.md index 60d196c..4d416d6 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,18 @@ [![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) [![PyPi versions](https://img.shields.io/pypi/pyversions/pylineclip.svg)](https://pypi.python.org/pypi/pylineclip) -[![PyPi wheels](https://img.shields.io/pypi/format/pylineclip.svg)](https://pypi.python.org/pypi/pylineclip) [![PyPi Download stats](http://pepy.tech/badge/pylineclip)](http://pepy.tech/project/pylineclip) # Line clipping -- `lineClipping.jl` Cohen-Sutherland line clipping algorithm for Julia. - Input scalars, output intersection length, or `None` if no intersection. - `lineclipping.f90` Cohen-Sutherland line clipping algorithm for massively parallel coarray modern Fortran. Input scalars or arrays, 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 @@ -71,11 +71,3 @@ The arguments are: in - endpoints of line out - intersection points with box. If no intersection, all NaN -### Julia - -Simliar to Python, except `nothing` is returned if no intersection -found. - -```julia -cohensutherland(xmin, ymax, xmax, ymin, x1, y1, x2, y2) -``` diff --git a/bin/.ignore b/build/bin/.ignore similarity index 100% rename from bin/.ignore rename to build/bin/.ignore diff --git a/lineClipping.jl b/lineClipping.jl deleted file mode 100755 index 317291b..0000000 --- a/lineClipping.jl +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env julia -#= - The MIT License (MIT) - Copyright (c) 2018 Michael Hirsch, Ph.D. -=# -using Test - -function cohensutherland(xmin, ymax, xmax, ymin, x1, y1, x2, y2) - #= - Clips a line to a rectangular area. - - This implements the Cohen-Sutherland line clipping algorithm. xmin, - ymax, xmax and ymin denote the clipping area, into which the line - defined by x1, y1 (start point) and x2, y2 (end point) will be - clipped. - - If the line intersects with the rectangular clipping area, - a tuple of the clipped line points will be returned in the form (cx1, cy1, cx2, cy2). - =# - INSIDE,LEFT, RIGHT, LOWER, UPPER = 0,1, 2, 4, 8 - - function _getclip(xa, ya) - p = INSIDE #default is inside - - # consider x - if xa < xmin - p |= LEFT - elseif xa > xmax - p |= RIGHT - end - - # consider y - if ya < ymin - p |= LOWER # bitwise OR - elseif ya > ymax - p |= UPPER #bitwise OR - end - - return p - end - -# check for trivially outside lines - k1 = _getclip(x1, y1) - k2 = _getclip(x2, y2) - -#%% examine non-trivially outside points - #bitwise OR | - while (k1 | k2) != 0 # if both points are inside box (0000) , ACCEPT trivial whole line in box - - # if line trivially outside window, REJECT - if (k1 & k2) != 0 #bitwise AND & - return nothing - end - - # non-trivial case, at least one point outside window - - # this is NOT a bitwise or - if k1 != 0 - opt = k1 - elseif k2 != 0 - opt = k2 - else - jl_error("unexpected k1,k2 $k1 $k2") - end - - if (opt & UPPER) != 0 #these are bitwise ANDS - x = x1 + (x2 - x1) * (ymax - y1) / (y2 - y1) - y = ymax - elseif (opt & LOWER) != 0 - x = x1 + (x2 - x1) * (ymin - y1) / (y2 - y1) - y = ymin - elseif (opt & RIGHT) != 0 - y = y1 + (y2 - y1) * (xmax - x1) / (x2 - x1) - x = xmax - elseif (opt & LEFT) != 0 - y = y1 + (y2 - y1) * (xmin - x1) / (x2 - x1) - x = xmin - else - jl_error("Undefined clipping state") - end - - if opt == k1 - x1, y1 = x, y - k1 = _getclip(x1, y1) - #println("checking k1: $x , $y $k1") - elseif opt == k2 - x2, y2 = x, y - k2 = _getclip(x2, y2) - #println("checking 2: $x , $y $k2") - end - - end - - return x1, y1, x2, y2 -end - - -if basename(PROGRAM_FILE) == basename(@__FILE__) - xmin, ymax, xmax, ymin, x1, y1, x2, y2 = 1, 5, 4, 3, 0, 0, 4, 6 - - x1, y1, x2, y2 = cohensutherland(xmin, ymax, xmax, ymin, x1, y1, x2, y2) - - @test x1≈2 - @test y1≈3 - @test x2≈3.3333333 - @test y2≈5 - - println("x1,y2,x2,y2 $x1 $y1 $x2 $y2") -end diff --git a/setup.cfg b/setup.cfg index 9b04e29..ff79034 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,6 +36,7 @@ install_requires = [options.extras_require] tests = pytest +cov = pytest-cov coveralls flake8 @@ -49,23 +50,3 @@ console_scripts = max-line-length = 132 exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/ -[coverage:run] -cover_pylib = false -omit = - /home/travis/virtualenv/* - */site-packages/* - */bin/* - -[coverage:report] -exclude_lines = - pragma: no cover - def __repr__ - except RuntimeError - except NotImplementedError - except ImportError - except FileNotFoundError - except CalledProcessError - logging.warning - logging.error - logging.critical - if __name__ == .__main__.: