Class BresenhamLine
java.lang.Object
com.github.yellowstonegames.grid.BresenhamLine
- All Implemented Interfaces:
LineDrawer
Provides a means to generate Bresenham lines in 2D.
You can use the static methods
line(Coord, Coord), lineArray(Coord, Coord),
and reachable(Coord, Coord, float[][]) (with many overloads possible), or their
equivalents using the LineDrawer interface: drawLine(Coord, Coord),
drawLineArray(Coord, Coord), or isReachable(Coord, Coord, float[][]).
The more verbose name of the pair is the instance method.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.github.tommyettinger.ds.ObjectDeque<Coord> drawLine(int startX, int startY, int targetX, int targetY) Generates a 2D Bresenham line between two points.com.github.tommyettinger.ds.ObjectDeque<Coord> drawLine(int startX, int startY, int targetX, int targetY, int maxLength) Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength (measured using Chebyshev distance, where diagonally adjacent cells are considered exactly as distant as orthogonally-adjacent cells).com.github.tommyettinger.ds.ObjectDeque<Coord> drawLine(int startX, int startY, int targetX, int targetY, int maxLength, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength (measured using Chebyshev distance, where diagonally adjacent cells are considered exactly as distant as orthogonally-adjacent cells).com.github.tommyettinger.ds.ObjectDeque<Coord> drawLine(int startX, int startY, int targetX, int targetY, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Generates a 2D Bresenham line between two points.com.github.tommyettinger.ds.ObjectDeque<Coord> Generates a 2D Bresenham line between two points.Coord[]drawLineArray(int startX, int startY, int targetX, int targetY) Generates a 2D Bresenham line between two points.Coord[]drawLineArray(int startX, int startY, int targetX, int targetY, int maxLength) Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength..Coord[]drawLineArray(Coord a, Coord b) Generates a 2D Bresenham line between two points.com.github.tommyettinger.ds.ObjectDeque<Coord> Gets the last line drawn using the internal buffer this carries, rather than an explicitly-specified buffer.booleanisReachable(int startX, int startY, int targetX, int targetY, float[][] resistanceMap) Checks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, without storing the line of points along the way.booleanisReachable(int startX, int startY, int targetX, int targetY, float[][] resistanceMap, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Checks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, and filling the list of cells along the line of sight intobuffer.booleanisReachable(int startX, int startY, int targetX, int targetY, int maxLength, float[][] resistanceMap) Checks whether the starting point can see the target point, using themaxLengthandresistanceMapto determine whether the line of sight is obstructed, without storing the line of points along the way.booleanisReachable(int startX, int startY, int targetX, int targetY, int maxLength, float[][] resistanceMap, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Checks whether the starting point can see the target point, using themaxLengthandresistanceMapto determine whether the line of sight is obstructed, and filling the list of cells along the line of sight intobuffer.booleanisReachable(Coord start, Coord target, float[][] resistanceMap) Checks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, without storing the line of points along the way.booleanisReachable(Coord start, Coord target, float[][] resistanceMap, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Checks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, and filling the list of cells along the line of sight intobuffer.static com.github.tommyettinger.ds.ObjectDeque<Coord> line(int startX, int startY, int targetX, int targetY) Generates a 2D Bresenham line between two points.static com.github.tommyettinger.ds.ObjectDeque<Coord> line(int startX, int startY, int targetX, int targetY, int maxLength) Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength (measured using Chebyshev distance, where diagonally adjacent cells are considered exactly as distant as orthogonally-adjacent cells).static com.github.tommyettinger.ds.ObjectDeque<Coord> line(int startX, int startY, int targetX, int targetY, int maxLength, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength (measured using Chebyshev distance, where diagonally adjacent cells are considered exactly as distant as orthogonally-adjacent cells).static com.github.tommyettinger.ds.ObjectDeque<Coord> line(int startX, int startY, int targetX, int targetY, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Generates a 2D Bresenham line between two points.static com.github.tommyettinger.ds.ObjectDeque<Coord> Generates a 2D Bresenham line between two points.static Coord[]lineArray(int startX, int startY, int targetX, int targetY) Generates a 2D Bresenham line between two points.static Coord[]lineArray(int startX, int startY, int targetX, int targetY, int maxLength) Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength..static Coord[]Generates a 2D Bresenham line between two points.static com.github.tommyettinger.ds.ObjectDeque<Coord> lineEuclidean(int startX, int startY, int targetX, int targetY, int maxLength, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength (measured using Euclidean distance, or "as the crow flies").static booleanreachable(int startX, int startY, int targetX, int targetY, float[][] resistanceMap) Checks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, without storing the line of points along the way.static booleanreachable(int startX, int startY, int targetX, int targetY, float[][] resistanceMap, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Checks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, and filling the list of cells along the line of sight intobuffer.static booleanreachable(int startX, int startY, int targetX, int targetY, int maxLength, float[][] resistanceMap) Checks whether the starting point can see the target point, using themaxLengthandresistanceMapto determine whether the line of sight is obstructed, without storing the line of points along the way.static booleanreachable(int startX, int startY, int targetX, int targetY, int maxLength, float[][] resistanceMap, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Checks whether the starting point can see the target point, using themaxLengthandresistanceMapto determine whether the line of sight is obstructed, and filling the list of cells along the line of sight intobuffer.static booleanChecks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, without storing the line of points along the way.static booleanreachable(Coord start, Coord target, float[][] resistanceMap, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Checks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, and filling the list of cells along the line of sight intobuffer.static booleanreachableEuclidean(int startX, int startY, int targetX, int targetY, int maxLength, float[][] resistanceMap, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Checks whether the starting point can see the target point, using themaxLengthandresistanceMapto determine whether the line of sight is obstructed, and filling the list of cells along the line of sight intobuffer.
-
Field Details
-
lastLine
-
-
Constructor Details
-
BresenhamLine
public BresenhamLine()Makes a new BresenhamLine and initializes its only state,lastLine.
-
-
Method Details
-
line
Generates a 2D Bresenham line between two points. If you want to save some memory, you can useline(int, int, int, int, ObjectDeque), which reuses an ObjectDeque of Coord as a buffer. You can also uselineArray(int, int, int, int); although that allocates a new array each time, having an array may be useful for some APIs.- Parameters:
a- the starting pointb- the ending point- Returns:
- The path between
aandb.
-
lineArray
-
line
public static com.github.tommyettinger.ds.ObjectDeque<Coord> line(int startX, int startY, int targetX, int targetY) Generates a 2D Bresenham line between two points. If you want to save some memory, you can useline(int, int, int, int, ObjectDeque), which reuses an ObjectDeque of Coord as a buffer. You can also uselineArray(int, int, int, int); although that allocates a new array each time, having an array may be useful for some APIs.
Uses ordinary Coord values for points, and these can be pooled if they are within what the current pool allows (it starts, by default, pooling Coords with x and y between -3 and 255, inclusive). If the Coords are pool-able, it can significantly reduce the work the garbage collector needs to do, especially on Android.- Parameters:
startX- the x coordinate of the starting pointstartY- the y coordinate of the starting pointtargetX- the x coordinate of the target pointtargetY- the y coordinate of the target point- Returns:
- a ObjectDeque of Coord points along the line
-
line
public static com.github.tommyettinger.ds.ObjectDeque<Coord> line(int startX, int startY, int targetX, int targetY, int maxLength) Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength (measured using Chebyshev distance, where diagonally adjacent cells are considered exactly as distant as orthogonally-adjacent cells). If you want to save some memory, you can useline(int, int, int, int, int, ObjectDeque), which reuses an ObjectDeque of Coord as a buffer. You can also uselineArray(int, int, int, int, int); although that allocates a new array each time, having an array may be useful for some APIs.
Uses ordinary Coord values for points, and these can be pooled if they are within what the current pool allows (it starts, by default, pooling Coords with x and y between -3 and 255, inclusive). If the Coords are pool-able, it can significantly reduce the work the garbage collector needs to do, especially on Android.- Parameters:
startX- the x coordinate of the starting pointstartY- the y coordinate of the starting pointtargetX- the x coordinate of the target pointtargetY- the y coordinate of the target pointmaxLength- the largest count of Coord points this can return; will stop early if reached- Returns:
- an ObjectDeque of Coord points along the line
-
line
public static com.github.tommyettinger.ds.ObjectDeque<Coord> line(int startX, int startY, int targetX, int targetY, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Generates a 2D Bresenham line between two points. If you want to save some memory, you can reuse an ObjectDeque of Coord,buffer, which will be cleared and filled with the resulting line of Coord. Ifbufferis null, this will create a new ObjectDeque of Coord and return that.
Uses ordinary Coord values for points, and these can be pooled if they are within what the current pool allows (it starts, by default, pooling Coords with x and y between -3 and 255, inclusive). If the Coords are pool-able, it can significantly reduce the work the garbage collector needs to do, especially on Android.- Parameters:
startX- the x coordinate of the starting pointstartY- the y coordinate of the starting pointtargetX- the x coordinate of the target pointtargetY- the y coordinate of the target pointbuffer- an ObjectDeque of Coord that will be reused and cleared if not null; will be modified- Returns:
- an ObjectDeque of Coord points along the line
-
line
public static com.github.tommyettinger.ds.ObjectDeque<Coord> line(int startX, int startY, int targetX, int targetY, int maxLength, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength (measured using Chebyshev distance, where diagonally adjacent cells are considered exactly as distant as orthogonally-adjacent cells). If you want to save some memory, you can reuse an ObjectDeque of Coord,buffer, which will be cleared and filled with the resulting line of Coord. Ifbufferis null, this will create a new ObjectDeque of Coord and return that.
Uses ordinary Coord values for points, and these can be pooled if they are within what the current pool allows (it starts, by default, pooling Coords with x and y between -3 and 255, inclusive). If the Coords are pool-able, it can significantly reduce the work the garbage collector needs to do, especially on Android.- Parameters:
startX- the x coordinate of the starting pointstartY- the y coordinate of the starting pointtargetX- the x coordinate of the target pointtargetY- the y coordinate of the target pointmaxLength- the largest count of Coord points this can return; will stop early if reachedbuffer- an ObjectDeque of Coord that will be reused and cleared if not null; will be modified- Returns:
- an ObjectDeque of Coord points along the line
-
lineEuclidean
public static com.github.tommyettinger.ds.ObjectDeque<Coord> lineEuclidean(int startX, int startY, int targetX, int targetY, int maxLength, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength (measured using Euclidean distance, or "as the crow flies"). If you want to save some memory, you can reuse an ObjectDeque of Coord,buffer, which will be cleared and filled with the resulting line of Coord. Ifbufferis null, this will create a new ObjectDeque of Coord and return that.
Uses ordinary Coord values for points, and these can be pooled if they are within what the current pool allows (it starts, by default, pooling Coords with x and y between -3 and 255, inclusive). If the Coords are pool-able, it can significantly reduce the work the garbage collector needs to do, especially on Android.- Parameters:
startX- the x coordinate of the starting pointstartY- the y coordinate of the starting pointtargetX- the x coordinate of the target pointtargetY- the y coordinate of the target pointmaxLength- the largest count of Coord points this can return; will stop early if reachedbuffer- an ObjectDeque of Coord that will be reused and cleared if not null; will be modified- Returns:
- an ObjectDeque of Coord points along the line
-
reachable
public static boolean reachable(Coord start, Coord target, float[][] resistanceMap, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Checks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, and filling the list of cells along the line of sight intobuffer.resistanceMapmust not be null; it can be initialized in the same way as FOV's resistance maps can withFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]).buffermay be null (in which case it is ignored), or may be an existing ObjectDeque of Coord (which will be cleared if it has any contents, and filled with the line's Coord points). If the starting point can see the target point, this returns true and buffer will contain all Coord points along the line of sight; otherwise this returns false and buffer will only contain up to and including the point that blocked the line of sight.- Parameters:
start- the starting pointtarget- the target pointresistanceMap- a resistance map as produced byFOV.generateResistances(char[][]); 0 is visible and 1 is blockedbuffer- an ObjectDeque of Coord that will be reused and cleared if not null; if null, will be ignored- Returns:
- true if the starting point can see the target point; false otherwise
-
reachable
public static boolean reachable(int startX, int startY, int targetX, int targetY, float[][] resistanceMap, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Checks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, and filling the list of cells along the line of sight intobuffer.resistanceMapmust not be null; it can be initialized in the same way as FOV's resistance maps can withFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]).buffermay be null (in which case it is ignored), or may be an existing ObjectDeque of Coord (which will be cleared if it has any contents, and filled with the line's Coord points). If the starting point can see the target point, this returns true and buffer will contain all Coord points along the line of sight; otherwise this returns false and buffer will only contain up to and including the point that blocked the line of sight.- Parameters:
startX- the x-coordinate of the starting pointstartY- the y-coordinate of the starting pointtargetX- the x-coordinate of the target pointtargetY- the y-coordinate of the target pointresistanceMap- a resistance map as produced byFOV.generateResistances(char[][]); 0 is visible and 1 is blockedbuffer- an ObjectDeque of Coord that will be reused and cleared if not null; if null, will be ignored- Returns:
- true if the starting point can see the target point; false otherwise
-
reachable
public static boolean reachable(int startX, int startY, int targetX, int targetY, int maxLength, float[][] resistanceMap, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Checks whether the starting point can see the target point, using themaxLengthandresistanceMapto determine whether the line of sight is obstructed, and filling the list of cells along the line of sight intobuffer. ThemaxLengthis measured using Chebyshev distance, where diagonally adjacent cells are considered exactly as distant as orthogonally-adjacent cells.resistanceMapmust not be null; it can be initialized in the same way as FOV's resistance maps can withFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]).buffermay be null (in which case it is ignored), or may be an existing ObjectDeque of Coord (which will be cleared if it has any contents, and filled with the line's Coord points). If the starting point can see the target point, this returns true and buffer will contain all Coord points along the line of sight; otherwise this returns false and buffer will only contain up to and including the point that blocked the line of sight.- Parameters:
startX- the x-coordinate of the starting pointstartY- the y-coordinate of the starting pointtargetX- the x-coordinate of the target pointtargetY- the y-coordinate of the target pointmaxLength- the maximum permitted length of a line of sightresistanceMap- a resistance map as produced byFOV.generateResistances(char[][]); 0 is visible and 1 is blockedbuffer- an ObjectDeque of Coord that will be reused and cleared if not null; if null, will be ignored- Returns:
- true if the starting point can see the target point; false otherwise
-
reachableEuclidean
public static boolean reachableEuclidean(int startX, int startY, int targetX, int targetY, int maxLength, float[][] resistanceMap, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Checks whether the starting point can see the target point, using themaxLengthandresistanceMapto determine whether the line of sight is obstructed, and filling the list of cells along the line of sight intobuffer. ThemaxLengthis measured using Euclidean distance, where diagonally adjacent cells are considered about 1.4 times as distant as orthogonally-adjacent cells; this is the natural way in the real world.resistanceMapmust not be null; it can be initialized in the same way as FOV's resistance maps can withFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]).buffermay be null (in which case it is ignored), or may be an existing ObjectDeque of Coord (which will be cleared if it has any contents, and filled with the line's Coord points). If the starting point can see the target point, this returns true and buffer will contain all Coord points along the line of sight; otherwise this returns false and buffer will only contain up to and including the point that blocked the line of sight.- Parameters:
startX- the x-coordinate of the starting pointstartY- the y-coordinate of the starting pointtargetX- the x-coordinate of the target pointtargetY- the y-coordinate of the target pointmaxLength- the maximum permitted length of a line of sightresistanceMap- a resistance map as produced byFOV.generateResistances(char[][]); 0 is visible and 1 is blockedbuffer- an ObjectDeque of Coord that will be reused and cleared if not null; if null, will be ignored- Returns:
- true if the starting point can see the target point; false otherwise
-
reachable
Checks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, without storing the line of points along the way.resistanceMapmust not be null; it can be initialized in the same way as FOV's resistance maps can withFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]). If the starting point can see the target point, this returns true; otherwise this returns false.- Parameters:
start- the starting pointtarget- the target pointresistanceMap- a resistance map as produced byFOV.generateResistances(char[][]); 0 is visible and 1 is blocked- Returns:
- true if the starting point can see the target point; false otherwise
-
reachable
public static boolean reachable(int startX, int startY, int targetX, int targetY, float[][] resistanceMap) Checks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, without storing the line of points along the way.resistanceMapmust not be null; it can be initialized in the same way as FOV's resistance maps can withFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]). If the starting point can see the target point, this returns true; otherwise this returns false.- Parameters:
startX- the x-coordinate of the starting pointstartY- the y-coordinate of the starting pointtargetX- the x-coordinate of the target pointtargetY- the y-coordinate of the target pointresistanceMap- a resistance map as produced byFOV.generateResistances(char[][]); 0 is visible and 1 is blocked- Returns:
- true if the starting point can see the target point; false otherwise
-
reachable
public static boolean reachable(int startX, int startY, int targetX, int targetY, int maxLength, float[][] resistanceMap) Checks whether the starting point can see the target point, using themaxLengthandresistanceMapto determine whether the line of sight is obstructed, without storing the line of points along the way.resistanceMapmust not be null; it can be initialized in the same way as FOV's resistance maps can withFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]). If the starting point can see the target point, this returns true; otherwise this returns false.- Parameters:
startX- the x-coordinate of the starting pointstartY- the y-coordinate of the starting pointtargetX- the x-coordinate of the target pointtargetY- the y-coordinate of the target pointmaxLength- the maximum permitted length of a line of sightresistanceMap- a resistance map as produced byFOV.generateResistances(char[][]); 0 is visible and 1 is blocked- Returns:
- true if the starting point can see the target point; false otherwise
-
lineArray
Generates a 2D Bresenham line between two points. Returns an array of Coord instead of a ObjectDeque. This allocates a new array with each call, sized to fit the line exactly.
Uses ordinary Coord values for points, and these can be pooled if they are within what the current pool allows (it starts, by default, pooling Coords with x and y between -3 and 255, inclusive). If the Coords are pool-able, it can significantly reduce the work the garbage collector needs to do, especially on Android.- Parameters:
startX- the x coordinate of the starting pointstartY- the y coordinate of the starting pointtargetX- the x coordinate of the target pointtargetY- the y coordinate of the target point- Returns:
- an array of Coord points along the line
-
lineArray
Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength.. Returns an array of Coord instead of an ObjectDeque. This allocates a new array with each call, sized to fit the line exactly.
Uses ordinary Coord values for points, and these can be pooled if they are within what the current pool allows (it starts, by default, pooling Coords with x and y between -3 and 255, inclusive). If the Coords are pool-able, it can significantly reduce the work the garbage collector needs to do, especially on Android.- Parameters:
startX- the x coordinate of the starting pointstartY- the y coordinate of the starting pointtargetX- the x coordinate of the target pointtargetY- the y coordinate of the target pointmaxLength- the largest count of Coord points this can return; will stop early if reached- Returns:
- an array of Coord points along the line
-
getLastLine
Gets the last line drawn using the internal buffer this carries, rather than an explicitly-specified buffer.- Specified by:
getLastLinein interfaceLineDrawer- Returns:
- an ObjectDeque of Coord that contains the last line drawn with this BresenhamLine's internal buffer
-
drawLine
Generates a 2D Bresenham line between two points. ReuseslastLineand returns it as the buffer; later calls to drawLine() without a buffer will probably clear lastLine (which is the same ObjectDeque this returns) as they are run.- Specified by:
drawLinein interfaceLineDrawer- Parameters:
a- the starting pointb- the ending point- Returns:
- The path between
aandb.
-
drawLine
public com.github.tommyettinger.ds.ObjectDeque<Coord> drawLine(int startX, int startY, int targetX, int targetY) Generates a 2D Bresenham line between two points. ReuseslastLineand returns it as the buffer; later calls to drawLine() without a buffer will probably clear lastLine (which is the same ObjectDeque this returns) as they are run.
Uses ordinary Coord values for points, and these can be pooled if they are within what the current pool allows (it starts, by default, pooling Coords with x and y between -3 and 255, inclusive). If the Coords are pool-able, it can significantly reduce the work the garbage collector needs to do, especially on Android.- Specified by:
drawLinein interfaceLineDrawer- Parameters:
startX- the x coordinate of the starting pointstartY- the y coordinate of the starting pointtargetX- the x coordinate of the target pointtargetY- the y coordinate of the target point- Returns:
- a ObjectDeque of Coord points along the line
-
drawLine
public com.github.tommyettinger.ds.ObjectDeque<Coord> drawLine(int startX, int startY, int targetX, int targetY, int maxLength) Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength (measured using Chebyshev distance, where diagonally adjacent cells are considered exactly as distant as orthogonally-adjacent cells). ReuseslastLineand returns it as the buffer; later calls to drawLine() without a buffer will probably clear lastLine (which is the same ObjectDeque this returns) as they are run.
Uses ordinary Coord values for points, and these can be pooled if they are within what the current pool allows (it starts, by default, pooling Coords with x and y between -3 and 255, inclusive). If the Coords are pool-able, it can significantly reduce the work the garbage collector needs to do, especially on Android.- Specified by:
drawLinein interfaceLineDrawer- Parameters:
startX- the x coordinate of the starting pointstartY- the y coordinate of the starting pointtargetX- the x coordinate of the target pointtargetY- the y coordinate of the target point- Returns:
- a ObjectDeque of Coord points along the line
-
drawLine
public com.github.tommyettinger.ds.ObjectDeque<Coord> drawLine(int startX, int startY, int targetX, int targetY, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Generates a 2D Bresenham line between two points. If you want to save some memory, you can reuse an ObjectDeque of Coord,buffer, which will be cleared and filled with the resulting line of Coord. Ifbufferis null, this will create a new ObjectDeque of Coord and return that.
Uses ordinary Coord values for points, and these can be pooled if they are within what the current pool allows (it starts, by default, pooling Coords with x and y between -3 and 255, inclusive). If the Coords are pool-able, it can significantly reduce the work the garbage collector needs to do, especially on Android.- Specified by:
drawLinein interfaceLineDrawer- Parameters:
startX- the x coordinate of the starting pointstartY- the y coordinate of the starting pointtargetX- the x coordinate of the target pointtargetY- the y coordinate of the target pointbuffer- an ObjectDeque of Coord that will be reused and cleared if not null; will be modified- Returns:
- an ObjectDeque of Coord points along the line
-
isReachable
public boolean isReachable(Coord start, Coord target, float[][] resistanceMap, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Checks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, and filling the list of cells along the line of sight intobuffer.resistanceMapmust not be null; it can be initialized in the same way as FOV's resistance maps can withFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]).buffermay be null (in which case a temporary ObjectDeque is allocated, which can be wasteful), or may be an existing ObjectDeque of Coord (which will be cleared if it has any contents). If the starting point can see the target point, this returns true and buffer will contain all Coord points along the line of sight; otherwise this returns false and buffer will only contain up to and including the point that blocked the line of sight.- Specified by:
isReachablein interfaceLineDrawer- Parameters:
start- the starting pointtarget- the target pointresistanceMap- a resistance map as produced byFOV.generateResistances(char[][]); 0 is visible and 1 is blockedbuffer- an ObjectDeque of Coord that will be reused and cleared if not null; will be modified- Returns:
- true if the starting point can see the target point; false otherwise
-
drawLine
public com.github.tommyettinger.ds.ObjectDeque<Coord> drawLine(int startX, int startY, int targetX, int targetY, int maxLength, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength (measured using Chebyshev distance, where diagonally adjacent cells are considered exactly as distant as orthogonally-adjacent cells). If you want to save some memory, you can reuse an ObjectDeque of Coord,buffer, which will be cleared and filled with the resulting line of Coord. Ifbufferis null, this will create a new ObjectDeque of Coord and return that.
Uses ordinary Coord values for points, and these can be pooled if they are within what the current pool allows (it starts, by default, pooling Coords with x and y between -3 and 255, inclusive). If the Coords are pool-able, it can significantly reduce the work the garbage collector needs to do, especially on Android.- Specified by:
drawLinein interfaceLineDrawer- Parameters:
startX- the x coordinate of the starting pointstartY- the y coordinate of the starting pointtargetX- the x coordinate of the target pointtargetY- the y coordinate of the target pointmaxLength- the largest count of Coord points this can return; will stop early if reachedbuffer- an ObjectDeque of Coord that will be reused and cleared if not null; will be modified- Returns:
- an ObjectDeque of Coord points along the line
-
isReachable
public boolean isReachable(int startX, int startY, int targetX, int targetY, float[][] resistanceMap, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Checks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, and filling the list of cells along the line of sight intobuffer.resistanceMapmust not be null; it can be initialized in the same way as FOV's resistance maps can withFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]).buffermay be null (in which case a temporary ObjectDeque is allocated, which can be wasteful), or may be an existing ObjectDeque of Coord (which will be cleared if it has any contents). If the starting point can see the target point, this returns true and buffer will contain all Coord points along the line of sight; otherwise this returns false and buffer will only contain up to and including the point that blocked the line of sight.- Specified by:
isReachablein interfaceLineDrawer- Parameters:
startX- the x-coordinate of the starting pointstartY- the y-coordinate of the starting pointtargetX- the x-coordinate of the target pointtargetY- the y-coordinate of the target pointresistanceMap- a resistance map as produced byFOV.generateResistances(char[][]); 0 is visible and 1 is blockedbuffer- an ObjectDeque of Coord that will be reused and cleared if not null; will be modified- Returns:
- true if the starting point can see the target point; false otherwise
-
isReachable
public boolean isReachable(int startX, int startY, int targetX, int targetY, int maxLength, float[][] resistanceMap, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer) Checks whether the starting point can see the target point, using themaxLengthandresistanceMapto determine whether the line of sight is obstructed, and filling the list of cells along the line of sight intobuffer. ThemaxLengthis measured using Chebyshev distance, where diagonally adjacent cells are considered exactly as distant as orthogonally-adjacent cells.resistanceMapmust not be null; it can be initialized in the same way as FOV's resistance maps can withFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]).buffermay be null (in which case a temporary ObjectDeque is allocated, which can be wasteful), or may be an existing ObjectDeque of Coord (which will be cleared if it has any contents). If the starting point can see the target point, this returns true and buffer will contain all Coord points along the line of sight; otherwise this returns false and buffer will only contain up to and including the point that blocked the line of sight.- Specified by:
isReachablein interfaceLineDrawer- Parameters:
startX- the x-coordinate of the starting pointstartY- the y-coordinate of the starting pointtargetX- the x-coordinate of the target pointtargetY- the y-coordinate of the target pointmaxLength- the maximum permitted length of a line of sightresistanceMap- a resistance map as produced byFOV.generateResistances(char[][]); 0 is visible and 1 is blockedbuffer- an ObjectDeque of Coord that will be reused and cleared if not null; will be modified- Returns:
- true if the starting point can see the target point; false otherwise
-
isReachable
Checks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, without storing the line of points along the way.resistanceMapmust not be null; it can be initialized in the same way as FOV's resistance maps can withFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]). If the starting point can see the target point, this returns true; otherwise this returns false.- Specified by:
isReachablein interfaceLineDrawer- Parameters:
start- the starting pointtarget- the target pointresistanceMap- a resistance map as produced byFOV.generateResistances(char[][]); 0 is visible and 1 is blocked- Returns:
- true if the starting point can see the target point; false otherwise
-
isReachable
public boolean isReachable(int startX, int startY, int targetX, int targetY, float[][] resistanceMap) Checks whether the starting point can see the target point, using theresistanceMapto determine whether the line of sight is obstructed, without storing the line of points along the way.resistanceMapmust not be null; it can be initialized in the same way as FOV's resistance maps can withFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]). If the starting point can see the target point, this returns true; otherwise this returns false.- Specified by:
isReachablein interfaceLineDrawer- Parameters:
startX- the x-coordinate of the starting pointstartY- the y-coordinate of the starting pointtargetX- the x-coordinate of the target pointtargetY- the y-coordinate of the target pointresistanceMap- a resistance map as produced byFOV.generateResistances(char[][]); 0 is visible and 1 is blocked- Returns:
- true if the starting point can see the target point; false otherwise
-
isReachable
public boolean isReachable(int startX, int startY, int targetX, int targetY, int maxLength, float[][] resistanceMap) Checks whether the starting point can see the target point, using themaxLengthandresistanceMapto determine whether the line of sight is obstructed, without storing the line of points along the way.resistanceMapmust not be null; it can be initialized in the same way as FOV's resistance maps can withFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]). If the starting point can see the target point, this returns true; otherwise this returns false.- Specified by:
isReachablein interfaceLineDrawer- Parameters:
startX- the x-coordinate of the starting pointstartY- the y-coordinate of the starting pointtargetX- the x-coordinate of the target pointtargetY- the y-coordinate of the target pointmaxLength- the maximum permitted length of a line of sightresistanceMap- a resistance map as produced byFOV.generateResistances(char[][]); 0 is visible and 1 is blocked- Returns:
- true if the starting point can see the target point; false otherwise
-
drawLineArray
Generates a 2D Bresenham line between two points. This allocates a new array with each call, sized to fit the line exactly. It does not changelastLine.- Specified by:
drawLineArrayin interfaceLineDrawer- Parameters:
a- the starting pointb- the ending point- Returns:
- The path between
aandb.
-
drawLineArray
Generates a 2D Bresenham line between two points. Returns an array of Coord instead of a ObjectDeque. This allocates a new array with each call, sized to fit the line exactly.
Uses ordinary Coord values for points, and these can be pooled if they are within what the current pool allows (it starts, by default, pooling Coords with x and y between -3 and 255, inclusive). If the Coords are pool-able, it can significantly reduce the work the garbage collector needs to do, especially on Android.- Specified by:
drawLineArrayin interfaceLineDrawer- Parameters:
startX- the x coordinate of the starting pointstartY- the y coordinate of the starting pointtargetX- the x coordinate of the target pointtargetY- the y coordinate of the target point- Returns:
- an array of Coord points along the line
-
drawLineArray
Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength.. Returns an array of Coord instead of an ObjectDeque. This allocates a new array with each call, sized to fit the line exactly.
Uses ordinary Coord values for points, and these can be pooled if they are within what the current pool allows (it starts, by default, pooling Coords with x and y between -3 and 255, inclusive). If the Coords are pool-able, it can significantly reduce the work the garbage collector needs to do, especially on Android.- Specified by:
drawLineArrayin interfaceLineDrawer- Parameters:
startX- the x coordinate of the starting pointstartY- the y coordinate of the starting pointtargetX- the x coordinate of the target pointtargetY- the y coordinate of the target pointmaxLength- the largest count of Coord points this can return; will stop early if reached- Returns:
- an array of Coord points along the line
-