Class Lines
Provides implementations of various line-drawing algorithms which are useful for generating lines on a 2D integer grid.
Namespace: SadRogue.Primitives
Assembly: TheSadRogue.Primitives.dll
Syntax
public static class Lines : Object
Methods
GetBresenhamLine(Point, Point)
Returns all points on the given line using the Bresenham line algorithm.
Declaration
public static BresenhamEnumerator GetBresenhamLine(Point start, Point end)
Parameters
Type | Name | Description |
---|---|---|
Point | start | The start point of the line. |
Point | end | The end point of the line. |
Returns
Type | Description |
---|---|
BresenhamEnumerator | Every point, in order, closest to a line between the two points specified (according to Bresenham's line algorithm). |
Remarks
This function returns a custom iterator which is very fast when used in a foreach loop. If you need an IEnumerable to use with LINQ or other code, the returned struct does implement that interface; however note that iterating over it this way will not perform as well as iterating directly over this object.
If you need a single function which takes any of the supported line drawing algorithms as a parameter and uses that to draw, you should use GetLine(Point, Point, Lines.Algorithm); however again this will be slower than using these functions directly.
GetBresenhamLine(Int32, Int32, Int32, Int32)
Returns all points on the given line using the Bresenham line algorithm.
Declaration
public static BresenhamEnumerator GetBresenhamLine(int startX, int startY, int endX, int endY)
Parameters
Type | Name | Description |
---|---|---|
Int32 | startX | X-coordinate of the starting point of the line. |
Int32 | startY | Y-coordinate of the starting point of the line. |
Int32 | endX | X-coordinate of the ending point of the line. |
Int32 | endY | Y-coordinate of the ending point of the line. |
Returns
Type | Description |
---|---|
BresenhamEnumerator | Every point, in order, closest to a line between the two points specified (according to Bresenham's line algorithm). |
Remarks
This function returns a custom iterator which is very fast when used in a foreach loop. If you need an IEnumerable to use with LINQ or other code, the returned struct does implement that interface; however note that iterating over it this way will not perform as well as iterating directly over this object.
If you need a single function which takes any of the supported line drawing algorithms as a parameter and uses that to draw, you should use GetLine(Int32, Int32, Int32, Int32, Lines.Algorithm); however again this will be slower than using these functions directly.
GetDDALine(Point, Point)
Returns all points on the given line using the DDA line algorithm.
Declaration
public static DDAEnumerator GetDDALine(Point start, Point end)
Parameters
Type | Name | Description |
---|---|---|
Point | start | The start point of the line. |
Point | end | The end point of the line. |
Returns
Type | Description |
---|---|
DDAEnumerator | Every point, in order, closest to a line between the two points specified (according to the DDA line algorithm). |
Remarks
This function returns a custom iterator which is very fast when used in a foreach loop. If you need an IEnumerable to use with LINQ or other code, the returned struct does implement that interface; however note that iterating over it this way will not perform as well as iterating directly over this object.
If you need a single function which takes any of the supported line drawing algorithms as a parameter and uses that to draw, you should use GetLine(Point, Point, Lines.Algorithm); however again this will be slower than using these functions directly.
GetDDALine(Int32, Int32, Int32, Int32)
Returns all points on the given line using the DDA line algorithm.
Declaration
public static DDAEnumerator GetDDALine(int startX, int startY, int endX, int endY)
Parameters
Type | Name | Description |
---|---|---|
Int32 | startX | X-coordinate of the starting point of the line. |
Int32 | startY | Y-coordinate of the starting point of the line. |
Int32 | endX | X-coordinate of the ending point of the line. |
Int32 | endY | Y-coordinate of the ending point of the line. |
Returns
Type | Description |
---|---|
DDAEnumerator | Every point, in order, closest to a line between the two points specified (according to the DDA line algorithm). |
Remarks
This function returns a custom iterator which is very fast when used in a foreach loop. If you need an IEnumerable to use with LINQ or other code, the returned struct does implement that interface; however note that iterating over it this way will not perform as well as iterating directly over this object.
If you need a single function which takes any of the supported line drawing algorithms as a parameter and uses that to draw, you should use GetLine(Int32, Int32, Int32, Int32, Lines.Algorithm); however again this will be slower than using these functions directly.
GetLine(Point, Point, Lines.Algorithm)
Returns an IEnumerable of every point, in order, closest to a line between the two points specified, using the line drawing algorithm given. The start and end points will be included. Slower than functions such as GetBresenhamLine(Point, Point), GetDDALine(Point, Point), and GetOrthogonalLine(Point, Point).
Declaration
public static IEnumerable<Point> GetLine(Point start, Point end, Lines.Algorithm type)
Parameters
Type | Name | Description |
---|---|---|
Point | start | The starting point of the line. |
Point | end | The ending point of the line. |
Lines.Algorithm | type | The line-drawing algorithm to use to generate the line. |
Returns
Type | Description |
---|---|
IEnumerable<Point> | An IEnumerable of every point, in order, closest to a line between the two points specified (according to the algorithm given). |
Remarks
You should only use this function if you need a single function which takes an arbitrary line algorithm, or you need an IEnumerable object specifically (for example, to use with LINQ). If you know what line algorithm you want to use and you just need to iterate over the points in a foreach loop, you should use GetBresenhamLine(Point, Point), GetDDALine(Point, Point), and GetOrthogonalLine(Point, Point) as applicable instead, since they offer significantly better performance.
GetLine(Int32, Int32, Int32, Int32, Lines.Algorithm)
Returns an IEnumerable of every point, in order, closest to a line between the two points specified, using the line drawing algorithm given. The start and end points will be included. Slower than functions such as GetBresenhamLine(Int32, Int32, Int32, Int32), GetDDALine(Int32, Int32, Int32, Int32), and GetOrthogonalLine(Int32, Int32, Int32, Int32).
Declaration
public static IEnumerable<Point> GetLine(int startX, int startY, int endX, int endY, Lines.Algorithm type)
Parameters
Type | Name | Description |
---|---|---|
Int32 | startX | X-coordinate of the starting point of the line. |
Int32 | startY | Y-coordinate of the starting point of the line. |
Int32 | endX | X-coordinate of the ending point of the line. |
Int32 | endY | Y-coordinate of the ending point of the line. |
Lines.Algorithm | type | The line-drawing algorithm to use to generate the line. |
Returns
Type | Description |
---|---|
IEnumerable<Point> | An IEnumerable of every point, in order, closest to a line between the two points specified (according to the algorithm given). |
Remarks
You should only use this function if you need a single function which takes an arbitrary line algorithm, or you need an IEnumerable object specifically (for example, to use with LINQ). If you know what line algorithm you want to use and you just need to iterate over the points in a foreach loop, you should use GetBresenhamLine(Int32, Int32, Int32, Int32), GetDDALine(Int32, Int32, Int32, Int32), and GetOrthogonalLine(Int32, Int32, Int32, Int32) as applicable instead, since they offer significantly better performance.
GetOrthogonalLine(Point, Point)
Returns all points on the given line using the Orthogonal line algorithm.
Declaration
public static OrthogonalEnumerator GetOrthogonalLine(Point start, Point end)
Parameters
Type | Name | Description |
---|---|---|
Point | start | The start point of the line. |
Point | end | The end point of the line. |
Returns
Type | Description |
---|---|
OrthogonalEnumerator | Every point, in order, closest to a line between the two points specified (according to the "orthogonal" line algorithm). |
Remarks
This function returns a custom iterator which is very fast when used in a foreach loop. If you need an IEnumerable to use with LINQ or other code, the returned struct does implement that interface; however note that iterating over it this way will not perform as well as iterating directly over this object.
If you need a single function which takes any of the supported line drawing algorithms as a parameter and uses that to draw, you should use GetLine(Point, Point, Lines.Algorithm); however again this will be slower than using these functions directly.
GetOrthogonalLine(Int32, Int32, Int32, Int32)
Returns all points on the given line using the Orthogonal line algorithm.
Declaration
public static OrthogonalEnumerator GetOrthogonalLine(int startX, int startY, int endX, int endY)
Parameters
Type | Name | Description |
---|---|---|
Int32 | startX | X-coordinate of the starting point of the line. |
Int32 | startY | Y-coordinate of the starting point of the line. |
Int32 | endX | X-coordinate of the ending point of the line. |
Int32 | endY | Y-coordinate of the ending point of the line. |
Returns
Type | Description |
---|---|
OrthogonalEnumerator | Every point, in order, closest to a line between the two points specified (according to the "orthogonal" line algorithm). |
Remarks
This function returns a custom iterator which is very fast when used in a foreach loop. If you need an IEnumerable to use with LINQ or other code, the returned struct does implement that interface; however note that iterating over it this way will not perform as well as iterating directly over this object.
If you need a single function which takes any of the supported line drawing algorithms as a parameter and uses that to draw, you should use GetLine(Int32, Int32, Int32, Int32, Lines.Algorithm); however again this will be slower than using these functions directly.