Class OrthoLine

java.lang.Object
com.github.yellowstonegames.grid.OrthoLine
All Implemented Interfaces:
LineDrawer

public class OrthoLine extends Object implements LineDrawer
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 Red Blob Games, thanks again to Amit!
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final com.github.tommyettinger.ds.ObjectDeque<Coord>
    A buffer of Coord as an ObjectDeque; this is cleared and reused by the drawLine() methods, so its state can only be certain until you make another call to one of those methods.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Makes a new OrthoLine and initializes its only state, lastLine.
  • 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.
    static com.github.tommyettinger.ds.ObjectDeque<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 com.github.tommyettinger.ds.ObjectDeque<Coord>
    line(int startX, int startY, int endX, int endY, int maxLength, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer)
    Draws a line from (startX, startY) to (endX, endY) using only N/S/E/W movement.
    static com.github.tommyettinger.ds.ObjectDeque<Coord>
    line(int startX, int startY, int endX, int endY, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer)
    Draws a line from (startX, startY) to (endX, endY) using only N/S/E/W movement.
    static com.github.tommyettinger.ds.ObjectDeque<Coord>
    line(Coord start, Coord end)
    Draws a line from start to end using only N/S/E/W movement.
    static Coord[]
    lineArray(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[]
    lineArray(int startX, int startY, int endX, int endY, int maxLength)
    Draws a line from (startX, startY) to (endX, endY) using only N/S/E/W movement.
    static Coord[]
    lineArray(Coord start, Coord end)
    Draws a line from start to end using only N/S/E/W movement.
    static char[]
    lineChars(Coord[] line)
    Given an array of Coord as produced by lineArray(Coord, Coord) or lineArray(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[]
    Given a List of Coord as produced by line(Coord, Coord) or line(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 boolean
    reachable(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.
    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 the resistanceMap to determine whether the line of sight is obstructed, and filling the list of cells along the line of sight into buffer.
    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 the maxLength and resistanceMap to determine whether the line of sight is obstructed, without storing the line of points along the way.
    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 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.
    static boolean
    reachable(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.
    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 the resistanceMap to determine whether the line of sight is obstructed, and filling the list of cells along the line of sight into buffer.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • lastLine

      public final com.github.tommyettinger.ds.ObjectDeque<Coord> lastLine
      A buffer of Coord as an ObjectDeque; this is cleared and reused by the drawLine() methods, so its state can only be certain until you make another call to one of those methods. The drawLine() overloads that explicitly take a buffer argument don't use this field.
  • Constructor Details

    • OrthoLine

      public OrthoLine()
      Makes a new OrthoLine and initializes its only state, lastLine.
  • Method Details

    • line

      public static com.github.tommyettinger.ds.ObjectDeque<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. Consider reusing an ObjectDeque instead of allocating a new one each time, if possible; this method allocates an ObjectDeque per call, but line(int, int, int, int, ObjectDeque) does not. Returns an ObjectDeque of Coord in order.
      Parameters:
      startX - x of starting point
      startY - y of starting point
      endX - x of ending point
      endY - y of ending point
      Returns:
      ObjectDeque of Coord, including (startX, startY) and (endX, endY) and all points walked between
    • line

      public static com.github.tommyettinger.ds.ObjectDeque<Coord> line(int startX, int startY, int endX, int endY, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer)
      Draws a line from (startX, startY) to (endX, endY) using only N/S/E/W movement. If buffer is not null, it will be cleared and reused; if it is null, then a new ObjectDeque will be allocated. Reusing buffer across multiple calls is a good way to reduce GC pressure. Returns an ObjectDeque of Coord in order.
      Parameters:
      startX - x of starting point
      startY - y of starting point
      endX - x of ending point
      endY - y of ending point
      buffer - an ObjectDeque of Coord that will be reused and cleared if not null; will be modified
      Returns:
      ObjectDeque of Coord, including (startX, startY) and (endX, endY) and all points walked between
    • line

      public static com.github.tommyettinger.ds.ObjectDeque<Coord> line(int startX, int startY, int endX, int endY, int maxLength, com.github.tommyettinger.ds.ObjectDeque<Coord> buffer)
      Draws a line from (startX, startY) to (endX, endY) using only N/S/E/W movement. If buffer is not null, it will be cleared and reused; if it is null, then a new ObjectDeque will be allocated. Reusing buffer across multiple calls is a good way to reduce GC pressure. Returns an ObjectDeque of Coord in order.
      Parameters:
      startX - x of starting point
      startY - y of starting point
      endX - x of ending point
      endY - y of ending point
      buffer - an ObjectDeque of Coord that will be reused and cleared if not null; will be modified
      Returns:
      ObjectDeque of Coord, including (startX, startY) and (endX, endY) and all points walked between
    • 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 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
    • 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 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
    • 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 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. 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
    • reachable

      public static boolean reachable(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
    • 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 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
    • 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 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
    • line

      public static com.github.tommyettinger.ds.ObjectDeque<Coord> line(Coord start, Coord end)
      Draws a line from start to end using only N/S/E/W movement. Consider reusing an ObjectDeque instead of allocating a new one each time, if possible; this method allocates an ObjectDeque per call, but line(int, int, int, int, ObjectDeque) does not. Returns an ObjectDeque of Coord in order.
      Parameters:
      start - starting point
      end - ending point
      Returns:
      ObjectDeque of Coord, including start and end and all points walked between
    • lineArray

      public static Coord[] lineArray(int startX, int startY, int endX, int endY)
      Draws a line from (startX, startY) to (endX, endY) using only N/S/E/W movement. Allocates a new exactly-sized array of Coord, in order, and returns it.
      Parameters:
      startX - x of starting point
      startY - y of starting point
      endX - x of ending point
      endY - y of ending point
      Returns:
      array of Coord, including (startX, startY) and (endX, endY) and all points walked between
    • lineArray

      public static Coord[] lineArray(int startX, int startY, int endX, int endY, int maxLength)
      Draws a line from (startX, startY) to (endX, endY) using only N/S/E/W movement. Allocates a new exactly-sized array of Coord, in order, and returns it.
      Parameters:
      startX - x of starting point
      startY - y of starting point
      endX - x of ending point
      endY - y of ending point
      Returns:
      array of Coord, including (startX, startY) and (endX, endY) and all points walked between
    • lineArray

      public static Coord[] lineArray(Coord start, Coord end)
      Draws a line from start to end using only N/S/E/W movement. Allocates a new exactly-sized array of Coord, in order, and returns it.
      Parameters:
      start - starting point
      end - ending point
      Returns:
      array of Coord, including start and end and all points walked between
    • lineChars

      public static char[] lineChars(Coord[] line)
      Given an array of Coord as produced by lineArray(Coord, Coord) or lineArray(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 an IllegalStateException if this has to draw a line between them. If this method is called on the result of this class' lineArray() method, then it should always return a valid result; if it is called on a path made with some other method, then it shouldn't throw an exception but may produce a low-quality (visually disconnected) line.
      Parameters:
      line - a Coord array where each Coord is orthogonally adjacent to its neighbor(s) in the array; usually produced via lineArray(Coord, Coord) or lineArray(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

      public static char[] lineChars(List<Coord> line)
      Given a List of Coord as produced by line(Coord, Coord) or line(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 an IllegalStateException 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, then it shouldn't throw an exception but may produce a low-quality (visually disconnected) line.
      Parameters:
      line - a List of Coord where each Coord is orthogonally adjacent to its neighbor(s) in the List; usually produced via line(Coord, Coord) or line(int, int, int, int)
      Returns:
      a char array of box-drawing chars that will connect when drawn at the same points as in line
    • getLastLine

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

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

      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). Reuses lastLine 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.
      Specified by:
      drawLine in interface LineDrawer
      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

      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. 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.
      Specified by:
      drawLine in interface LineDrawer
      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

      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 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.
      Specified by:
      isReachable in interface LineDrawer
      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

      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. 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.
      Specified by:
      drawLine in interface LineDrawer
      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

      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 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.
      Specified by:
      isReachable in interface LineDrawer
      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

      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 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.
      Specified by:
      isReachable in interface LineDrawer
      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

      public 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.
      Specified by:
      isReachable in interface LineDrawer
      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

      public 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.
      Specified by:
      isReachable in interface LineDrawer
      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

      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 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.
      Specified by:
      isReachable in interface LineDrawer
      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

      public 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 lastLine.
      Specified by:
      drawLineArray in interface LineDrawer
      Parameters:
      a - the starting point
      b - the ending point
      Returns:
      The path between a and b.
    • drawLineArray

      public 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.
      Specified by:
      drawLineArray in interface LineDrawer
      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

      public 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.
      Specified by:
      drawLineArray in interface LineDrawer
      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