Line clipping: Cohen-Sutherland
Project description
Line clipping
lineClipping.jl
Cohen-Sutherland line clipping algorithm for Julia. Input scalars, output intersection length, orNone
if no intersection.lineclipping.f90
Cohen-Sutherland line clipping algorithm for massively parallel coarray modern Fortran. Input scalars or arrays, output intersections orNaN
if no intersection.lineClipping.py
Cohen-Sutherland line clipping algorithm for Python. Input scalars, output intersection length, orNone
if no intersection.
Install
Python
python -m pip install -e .
Fortran
If you want to use the Fortran Cohen-Sutherland line clipping modules directly (optional):
cd bin
cmake ..
make
Usage
The main difference with textbook implementations is that I return a sentinel value (NaN, None, nothing) if there's no intersection of line with box.
Python
import pylineclip.lineclipping as lc
x3,y3,x4,y4 = lc.cohensutherland((xmin, ymax, xmax, ymin, x1, y1, x2, y2)
If no intersection, (None, None, None, None)
is returned.
Fortran
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).
Fortran programs will simply use
use lineclipping
call cohensutherland(xmin,ymax,xmax,ymin,x1,y1,x2,y2)
The arguments are:
INPUTS
------
xmin,ymax,xmax,ymin: upper left and lower right corners of box (pixel coordinates)
INOUT
-----
x1,y1,x2,y2:
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.
cohensutherland(xmin, ymax, xmax, ymin, x1, y1, x2, y2)
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
Built Distribution
File details
Details for the file pylineclip-0.9.1.tar.gz
.
File metadata
- Download URL: pylineclip-0.9.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d34db25e328404b7dd1edd8d1580f430960f7d9a69199c196c60443f27791fc |
|
MD5 | 9331ae563af8a6ee8223c2adc3ff5dff |
|
BLAKE2b-256 | e15b3b3eba5d56e75d8f94d3728a0fcb77d830a2c1ceab40ad319c8ac099d508 |
File details
Details for the file pylineclip-0.9.1-py3-none-any.whl
.
File metadata
- Download URL: pylineclip-0.9.1-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55f922b84d9ee7db5dc82e5b8e9176fce8b3534ab24b53776e6e3e111cf94c20 |
|
MD5 | 88cb1de30a17453e95e7400bc50c2a2d |
|
BLAKE2b-256 | feb4bcded4ff58fb6f4041421f96386490a2b819da1c7df6edb46ba4c4c5b5b0 |