Package squidpony.squidmath
Class OrthoLine
java.lang.Object
squidpony.squidmath.OrthoLine
public class OrthoLine extends Object
A simple line-drawing algorithm that only takes orthogonal steps; may be useful for LOS in games that use Manhattan
distances for measurements.
Algorithm is from http://www.redblobgames.com/grids/line-drawing.html#stepping , thanks Amit!
Created by Tommy Ettinger on 1/10/2016.
-
Constructor Summary
Constructors Constructor Description OrthoLine()
-
Method Summary
Modifier and Type Method Description static ArrayList<Coord>
line(int startX, int startY, int endX, int endY)
Draws a line from (startX, startY) to (endX, endY) using only N/S/E/W movement.static ArrayList<Coord>
line(Coord start, Coord end)
Draws a line from start to end using only N/S/E/W movement.static Coord[]
line_(int startX, int startY, int endX, int endY)
Draws a line from (startX, startY) to (endX, endY) using only N/S/E/W movement.static Coord[]
line_(Coord start, Coord end)
Draws a line from start to end using only N/S/E/W movement.static char[]
lineChars(List<Coord> line)
Given a List of Coord as produced byline(Coord, Coord)
orline(int, int, int, int)
, this gets a char array of box-drawing characters that connect when drawn at the corresponding Coord positions in the given line.static char[]
lineChars(Coord[] line)
Given an array of Coord as produced byline_(Coord, Coord)
orline_(int, int, int, int)
, this gets a char array of box-drawing characters that connect when drawn at the corresponding Coord positions in the given line.
-
Constructor Details
-
Method Details
-
line
Draws a line from (startX, startY) to (endX, endY) using only N/S/E/W movement. Returns a List of Coord in order.- Parameters:
startX
- x of starting pointstartY
- y of starting pointendX
- x of ending pointendY
- y of ending point- Returns:
- List of Coord, including (startX, startY) and (endX, endY) and all points walked between
-
line
Draws a line from start to end using only N/S/E/W movement. Returns a List of Coord in order.- Parameters:
start
- starting pointend
- ending point- Returns:
- List of Coord, including start and end and all points walked between
-
line_
Draws a line from (startX, startY) to (endX, endY) using only N/S/E/W movement. Returns an array of Coord in order.- Parameters:
startX
- x of starting pointstartY
- y of starting pointendX
- x of ending pointendY
- y of ending point- Returns:
- array of Coord, including (startX, startY) and (endX, endY) and all points walked between
-
line_
Draws a line from start to end using only N/S/E/W movement. Returns a List of Coord in order.- Parameters:
start
- starting pointend
- ending point- Returns:
- List of Coord, including start and end and all points walked between
-
lineChars
Given an array of Coord as produced byline_(Coord, Coord)
orline_(int, int, int, int)
, this gets a char array of box-drawing characters that connect when drawn at the corresponding Coord positions in the given line. This can be useful for drawing highlight lines or showing what path something will take, as long as it only uses 4-way orthogonal connections between Coords. Any connections that require a diagonal will not be handled by this method (returning a straight line without much accuracy), and any Coords that aren't adjacent will cause anIllegalStateException
if this has to draw a line between them. If this method is called on the result of this class' line_() method, then it should always return a valid result; if it is called on a path made with some other method, such as fromBresenham.line2D_(Coord, Coord)
, then it shouldn't throw an exception but may produce a low-quality (disconnected visually) line.- Parameters:
line
- a Coord array where each Coord is orthogonally adjacent to its neighbor(s) in the array; usually produced vialine_(Coord, Coord)
orline_(int, int, int, int)
- Returns:
- a char array of box-drawing chars that will connect when drawn at the same points as in line
-
lineChars
Given a List of Coord as produced byline(Coord, Coord)
orline(int, int, int, int)
, this gets a char array of box-drawing characters that connect when drawn at the corresponding Coord positions in the given line. This can be useful for drawing highlight lines or showing what path something will take, as long as it only uses 4-way orthogonal connections between Coords. Any connections that require a diagonal will not be handled by this method (returning a straight line without much accuracy), and any Coords that aren't adjacent will cause anIllegalStateException
if this has to draw a line between them. If this method is called on the result of this class' line() method, then it should always return a valid result; if it is called on a path made with some other method, such as fromBresenham.line2D(Coord, Coord)
, then it shouldn't throw an exception but may produce a low-quality (disconnected visually) line.- Parameters:
line
- a List of Coord where each Coord is orthogonally adjacent to its neighbor(s) in the List; usually produced vialine(Coord, Coord)
orline(int, int, int, int)
- Returns:
- a char array of box-drawing chars that will connect when drawn at the same points as in line
-