Skip to content

An iterator based implementation of Bresenham's line algorithm

License

Notifications You must be signed in to change notification settings

goof-bug/Iterator-Bresenham

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bresenham's line algorithm

An iterator based implementation of Bresenham's line algorithm in C#.

This approach makes integrating it with different methods of plotting or drawing easy and effecient because the iterator simply returns the relevant points one at a time.

Usage

The Bresenham.New() method returns an IEnumerable that will iterate over all the points in the line in the form of a ValueTuple<int, int>. This can easily be iterated over with a foreach loop like this:

var point1 = (1, 2);
var point2 = (4, 6);

foreach(var point in Bresenham.New(point1, point2)){
  Console.WriteLine(point);
}
// This will output:
// (1, 2)
// (2, 3)
// (3, 4)
// (3, 5)
// (4, 6)

The Console.WriteLine() can easily be substitued with a plotPixel() or similar relevant to your application.

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgements

About

An iterator based implementation of Bresenham's line algorithm

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages