Interface LineDrawer

All Known Implementing Classes:
BresenhamLine, EliasWuLine, OrthoLine

public interface LineDrawer
A shared interface for line-drawing classes, so instances can be interchanged. One of these can draw a line as an ObjectDeque of Coord (which may reuse an existing ObjectDeque) or as a newly-allocated array of Coord. It can also check whether there is a complete line that can be drawn between a start and an end point, given a 2D array of the resistance of cells along the way that might block the line's passage.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.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.
    drawLineArray(int startX, int startY, int targetX, int targetY)
    Generates a 2D Bresenham line between two points.
    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.
    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.
    boolean
    isReachable(int startX, int startY, int targetX, int targetY, float[][] resistanceMap)
    Checks whether the starting point can see the target point, using the resistanceMap to determine whether the line of sight is obstructed, without storing the line of points along the way.
    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 the resistanceMap to determine whether the line of sight is obstructed, and filling the list of cells along the line of sight into buffer.
    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 the maxLength and resistanceMap to determine whether the line of sight is obstructed, without storing the line of points along the way.
    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 the maxLength and resistanceMap to determine whether the line of sight is obstructed, and filling the list of cells along the line of sight into buffer.
    boolean
    isReachable(Coord start, Coord target, float[][] resistanceMap)
    Checks whether the starting point can see the target point, using the resistanceMap to determine whether the line of sight is obstructed, without storing the line of points along the way.
    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 the resistanceMap to determine whether the line of sight is obstructed, and filling the list of cells along the line of sight into buffer.
  • Method Details

    • getLastLine

      com.github.tommyettinger.ds.ObjectDeque<Coord> getLastLine()
      Gets the last line drawn using the internal buffer this carries, rather than an explicitly-specified buffer.
      Returns:
      an ObjectDeque of Coord that contains the last line drawn with this LineDrawer's internal buffer
    • drawLine

      com.github.tommyettinger.ds.ObjectDeque<Coord> drawLine(Coord a, Coord b)
      Generates a 2D Bresenham line between two points. Reuses getLastLine() and 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.
      Parameters:
      a - the starting point
      b - the ending point
      Returns:
      The path between a and b.
    • drawLine

      com.github.tommyettinger.ds.ObjectDeque<Coord> drawLine(int startX, int startY, int targetX, int targetY)
      Generates a 2D Bresenham line between two points. Reuses getLastLine() and 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.
      Parameters:
      startX - the x coordinate of the starting point
      startY - the y coordinate of the starting point
      targetX - the x coordinate of the target point
      targetY - the y coordinate of the target point
      Returns:
      a ObjectDeque of Coord points along the line
    • drawLine

      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). Reuses getLastLine() and 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.
      Parameters:
      startX - the x coordinate of the starting point
      startY - the y coordinate of the starting point
      targetX - the x coordinate of the target point
      targetY - the y coordinate of the target point
      Returns:
      a ObjectDeque of Coord points along the line
    • drawLine

      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. If buffer is 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 point
      startY - the y coordinate of the starting point
      targetX - the x coordinate of the target point
      targetY - the y coordinate of the target point
      buffer - 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

      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 the resistanceMap to determine whether the line of sight is obstructed, and filling the list of cells along the line of sight into buffer. resistanceMap must not be null; it can be initialized in the same way as FOV's resistance maps can with FOV.generateResistances(char[][]) or FOV.generateSimpleResistances(char[][]). buffer may 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.
      Parameters:
      start - the starting point
      target - the target point
      resistanceMap - a resistance map as produced by FOV.generateResistances(char[][]); 0 is visible and 1 is blocked
      buffer - 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

      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. If buffer is 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 point
      startY - the y coordinate of the starting point
      targetX - the x coordinate of the target point
      targetY - the y coordinate of the target point
      maxLength - the largest count of Coord points this can return; will stop early if reached
      buffer - 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

      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 the resistanceMap to determine whether the line of sight is obstructed, and filling the list of cells along the line of sight into buffer. resistanceMap must not be null; it can be initialized in the same way as FOV's resistance maps can with FOV.generateResistances(char[][]) or FOV.generateSimpleResistances(char[][]). buffer may 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.
      Parameters:
      startX - the x-coordinate of the starting point
      startY - the y-coordinate of the starting point
      targetX - the x-coordinate of the target point
      targetY - the y-coordinate of the target point
      resistanceMap - a resistance map as produced by FOV.generateResistances(char[][]); 0 is visible and 1 is blocked
      buffer - 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

      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 the maxLength and resistanceMap to determine whether the line of sight is obstructed, and filling the list of cells along the line of sight into buffer. The maxLength is measured using Chebyshev distance, where diagonally adjacent cells are considered exactly as distant as orthogonally-adjacent cells. resistanceMap must not be null; it can be initialized in the same way as FOV's resistance maps can with FOV.generateResistances(char[][]) or FOV.generateSimpleResistances(char[][]). buffer may 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.
      Parameters:
      startX - the x-coordinate of the starting point
      startY - the y-coordinate of the starting point
      targetX - the x-coordinate of the target point
      targetY - the y-coordinate of the target point
      maxLength - the maximum permitted length of a line of sight
      resistanceMap - a resistance map as produced by FOV.generateResistances(char[][]); 0 is visible and 1 is blocked
      buffer - 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

      boolean isReachable(Coord start, Coord target, float[][] resistanceMap)
      Checks whether the starting point can see the target point, using the resistanceMap to determine whether the line of sight is obstructed, without storing the line of points along the way. resistanceMap must not be null; it can be initialized in the same way as FOV's resistance maps can with FOV.generateResistances(char[][]) or FOV.generateSimpleResistances(char[][]). If the starting point can see the target point, this returns true; otherwise this returns false.
      Parameters:
      start - the starting point
      target - the target point
      resistanceMap - a resistance map as produced by FOV.generateResistances(char[][]); 0 is visible and 1 is blocked
      Returns:
      true if the starting point can see the target point; false otherwise
    • isReachable

      boolean isReachable(int startX, int startY, int targetX, int targetY, float[][] resistanceMap)
      Checks whether the starting point can see the target point, using the resistanceMap to determine whether the line of sight is obstructed, without storing the line of points along the way. resistanceMap must not be null; it can be initialized in the same way as FOV's resistance maps can with FOV.generateResistances(char[][]) or FOV.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 point
      startY - the y-coordinate of the starting point
      targetX - the x-coordinate of the target point
      targetY - the y-coordinate of the target point
      resistanceMap - a resistance map as produced by FOV.generateResistances(char[][]); 0 is visible and 1 is blocked
      Returns:
      true if the starting point can see the target point; false otherwise
    • isReachable

      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 the maxLength and resistanceMap to determine whether the line of sight is obstructed, without storing the line of points along the way. resistanceMap must not be null; it can be initialized in the same way as FOV's resistance maps can with FOV.generateResistances(char[][]) or FOV.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 point
      startY - the y-coordinate of the starting point
      targetX - the x-coordinate of the target point
      targetY - the y-coordinate of the target point
      maxLength - the maximum permitted length of a line of sight
      resistanceMap - a resistance map as produced by FOV.generateResistances(char[][]); 0 is visible and 1 is blocked
      Returns:
      true if the starting point can see the target point; false otherwise
    • drawLineArray

      Coord[] drawLineArray(Coord a, Coord b)
      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 change getLastLine().
      Parameters:
      a - the starting point
      b - the ending point
      Returns:
      The path between a and b.
    • drawLineArray

      Coord[] drawLineArray(int startX, int startY, int targetX, int targetY)
      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 point
      startY - the y coordinate of the starting point
      targetX - the x coordinate of the target point
      targetY - the y coordinate of the target point
      Returns:
      an array of Coord points along the line
    • drawLineArray

      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. 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 point
      startY - the y coordinate of the starting point
      targetX - the x coordinate of the target point
      targetY - the y coordinate of the target point
      maxLength - the largest count of Coord points this can return; will stop early if reached
      Returns:
      an array of Coord points along the line