GitXplorerGitXplorer
e

bresenham

public
62 stars
12 forks
0 issues

Commits

List of commits on branch master.
Verified
efe416dddab8cb22f81bb3f926993eeff04a5665

README: mention wasabigeom

eencukou committed 4 years ago
Unverified
d18fe31725122b53a61a597b0fe36b22bf75b375

Bump version to 0.2.1 and add CHANGELOG

eencukou committed 6 years ago
Unverified
7396ea939f4224a0eb8dcd7eec50372f08e6f722

README: Add note and links to more serious code for this problem

eencukou committed 6 years ago
Unverified
a341fbd891edc014f3e5934cf4c12d1877b4fccd

Tweak README wording

eencukou committed 6 years ago
Unverified
bde5acd9e4160988fac0955a9f4452d64af4bf26

Bump to version 0.2

eencukou committed 7 years ago
Unverified
7ff017024e7c1dfbe98046a82418f7c4fa46c595

Add a test for a low-slope line

eencukou committed 7 years ago

README

The README file for this repository.

The bresenham module

A simple implementation of Bresenham's line drawing algorithm.

See the Wikipedia entry_ for details on what that is.

.. _the Wikipedia entry: https://en.wikipedia.org/wiki/Bresenham's_line_algorithm

Note that this is a simple implementation. It is written in Pure Python (without e.g. numpy), so it is relatively slow.

I found some beauty in combining the classic algorithm (whose ingenuity lies in using only integers – a constraint that isn't really as relevant now) with a Python generator (a modern device that follows the spirit of “executable pseudocode”, abstracting away the output subroutine). I hope others can appreciate the code as well.

For serious use, look at these:

  • skimage.draw.line_, which solves the same problem fast.
  • A Numpy-based recipe_ that generalizes the solution to N dimensions.
  • wasabigeom_, a 2D vector library made for games

.. _skimage.draw.line: http://scikit-image.org/docs/dev/api/skimage.draw.html#skimage.draw.line .. _Numpy-based recipe: http://code.activestate.com/recipes/578112-bresenhams-line-algorithm-in-n-dimensions/ .. _wasabigeom: https://pypi.org/project/wasabi-geom/

Installation

In a Python virtual environment, do::

python -m pip install bresenham

To install from a Git checkout (in editable mode)::

python -m pip install -e.

To install without a virtual envitonment, add the --user option.

Usage

The bresenham(x0, y0, x1, y1) function returns a generator of the coordinates of the line from (x0, y0) to (x1, y1).

For example, the coordinates of a line from (-1, -4) to (3, 2), are::

>>> from bresenham import bresenham

>>> list(bresenham(-1, -4, 3, 2))
[(-1, -4), (0, -3), (0, -2), (1, -1), (2, 0), (2, 1), (3, 2)]

Development

You're welcome to join this project!

If you spot an issue, please report it at the Issues page_ on Github.

If you'd like to start changing the code or documentation, check out the code locally using::

git clone https://github.com/encukou/bresenham

If you're new to this, please read the this guide_ about collaborating on Github-hosted projects like this one.

If that doesn't make sense, please e-mail the author <encukou@gmail.com>_ for clarification. I'd be happy to help you get started.

.. _Issues page: https://github.com/encukou/bresenham/issues .. _this guide: https://guides.github.com/activities/contributing-to-open-source/