Skip to main content

Line clipping: Cohen-Sutherland

Project description

Travis CI Coverage Status AppVeyor PyPi versions PyPi wheels PyPi Download stats

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.

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

pylineclip-0.9.2.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file pylineclip-0.9.2.tar.gz.

File metadata

  • Download URL: pylineclip-0.9.2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pylineclip-0.9.2.tar.gz
Algorithm Hash digest
SHA256 fe3bf34d791242f6813500fd2a83843872c03e9a191c27dddd65bad68b62d05a
MD5 dfe893b0e33c475d401ccca97a8ad446
BLAKE2b-256 81ef082c93252d1cba3dfdab98b05e938fd8e0b20d4fa6ea14c7beff27d55fd8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page