Class Bresenham

java.lang.Object
squidpony.squidmath.Bresenham

public class Bresenham
extends Object
Provides a means to generate Bresenham lines in 2D and 3D.
Author:
Eben Howard - http://squidpony.com - howard@squidpony.com, Lewis Potter, Tommy Ettinger, smelC
  • Method Summary

    Modifier and Type Method Description
    static Queue<Coord> line2D​(int startx, int starty, int endx, int endy)
    Generates a 2D Bresenham line between two points.
    static Queue<Coord> line2D​(int startx, int starty, int endx, int endy, int maxLength)
    Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength.
    static Queue<Coord> line2D​(Coord a, Coord b)
    Generates a 2D Bresenham line between two points.
    static Coord[] line2D_​(int startx, int starty, int endx, int endy)
    Generates a 2D Bresenham line between two points.
    static Coord[] line2D_​(int startx, int starty, int endx, int endy, int maxLength)
    Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength..
    static Coord[] line2D_​(Coord a, Coord b)
    Generates a 2D Bresenham line between two points.
    static Queue<Coord3D> line3D​(int startx, int starty, int startz, int endx, int endy, int endz)
    Generates a 3D Bresenham line between the given coordinates.
    static Queue<Coord3D> line3D​(Coord3D a, Coord3D b)
    Generates a 3D Bresenham line between two points.

    Methods inherited from class java.lang.Object

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

    • line2D

      public static Queue<Coord> line2D​(Coord a, Coord b)
      Generates a 2D Bresenham line between two points. If you don't need the Queue interface for the returned reference, consider using line2D_(Coord, Coord) to save some memory.
      Parameters:
      a - the starting point
      b - the ending point
      Returns:
      The path between a and b.
    • line2D_

      public static Coord[] line2D_​(Coord a, Coord b)
      Generates a 2D Bresenham line between two points.
      Parameters:
      a - the starting point
      b - the ending point
      Returns:
      The path between a and b.
    • line3D

      public static Queue<Coord3D> line3D​(Coord3D a, Coord3D b)
      Generates a 3D Bresenham line between two points.
      Parameters:
      a - Coord to start from. This will be the first element of the list
      b - Coord to end at. This will be the last element of the list.
      Returns:
      A list of points between a and b.
    • line3D

      public static Queue<Coord3D> line3D​(int startx, int starty, int startz, int endx, int endy, int endz)
      Generates a 3D Bresenham line between the given coordinates. Uses a Coord3D for each point; keep in mind Coord3D values are not pooled like ordinary 2D Coord values, and this may cause more work for the garbage collector, especially on Android, if many Coord3D values are produced.
      Parameters:
      startx - the x coordinate of the starting point
      starty - the y coordinate of the starting point
      startz - the z coordinate of the starting point
      endx - the x coordinate of the starting point
      endy - the y coordinate of the starting point
      endz - the z coordinate of the starting point
      Returns:
      a Queue (internally, an ArrayDeque) of Coord3D points along the line
    • line2D

      public static Queue<Coord> line2D​(int startx, int starty, int endx, int endy)
      Generates a 2D Bresenham line between two points. If you don't need the Queue interface for the returned reference, consider using line2D_(int, int, int, int) to save some memory.
      Uses ordinary Coord values for points, and these can be pooled if they aren't beyond 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
      endx - the x coordinate of the starting point
      endy - the y coordinate of the starting point
      Returns:
      a Queue (internally, an ArrayDeque) of Coord points along the line
    • line2D

      public static Queue<Coord> line2D​(int startx, int starty, int endx, int endy, int maxLength)
      Generates a 2D Bresenham line between two points, stopping early if the number of Coords returned reaches maxLength. If you don't need the Queue interface for the returned reference, consider using line2D_(int, int, int, int, int) to save some memory.
      Uses ordinary Coord values for points, and these can be pooled if they aren't beyond 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
      endx - the x coordinate of the starting point
      endy - the y coordinate of the starting point
      maxLength - the largest count of Coord points this can return; will stop early if reached
      Returns:
      a Queue (internally, a ArrayDeque) of Coord points along the line
    • line2D_

      public static Coord[] line2D_​(int startx, int starty, int endx, int endy)
      Generates a 2D Bresenham line between two points. Returns an array of Coord instead of a Queue.
      Uses ordinary Coord values for points, and these can be pooled if they aren't beyond 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
      endx - the x coordinate of the starting point
      endy - the y coordinate of the starting point
      Returns:
      an array of Coord points along the line
    • line2D_

      public static Coord[] line2D_​(int startx, int starty, int endx, int endy, 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 a Queue.
      Uses ordinary Coord values for points, and these can be pooled if they aren't beyond 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
      endx - the x coordinate of the starting point
      endy - the y coordinate of the starting 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