Code Monkey home page Code Monkey logo

lineclipping-python-fortran's Introduction

Line clipping

Actions Status

PyPi versions PyPi Download stats

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

To install the latest release:

pip install pylineclip

Fortran

If you want to use the Fortran Cohen-Sutherland line clipping modules directly (optional):

meson build

meson test -C build

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.