public class OrthoLine
extends java.lang.Object
Constructor and Description |
---|
OrthoLine() |
Modifier and Type | Method and Description |
---|---|
static Coord[] |
line_(Coord start,
Coord end)
Draws a line from start to end using only N/S/E/W movement.
|
static Coord[] |
line_(int startX,
int startY,
int endX,
int endY)
Draws a line from (startX, startY) to (endX, endY) using only N/S/E/W movement.
|
static java.util.ArrayList<Coord> |
line(Coord start,
Coord end)
Draws a line from start to end using only N/S/E/W movement.
|
static java.util.ArrayList<Coord> |
line(int startX,
int startY,
int endX,
int endY)
Draws a line from (startX, startY) to (endX, endY) using only N/S/E/W movement.
|
static char[] |
lineChars(Coord[] line)
Given an array 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 char[] |
lineChars(java.util.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. |
static boolean |
reachable(Coord start,
Coord target,
double[][] 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,
double[][] resistanceMap,
java.util.ArrayList<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,
double[][] 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,
double[][] resistanceMap,
java.util.ArrayList<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,
double[][] 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,
double[][] resistanceMap,
java.util.ArrayList<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 . |
public static java.util.ArrayList<Coord> line(int startX, int startY, int endX, int endY)
startX
- x of starting pointstartY
- y of starting pointendX
- x of ending pointendY
- y of ending pointpublic static java.util.ArrayList<Coord> line(Coord start, Coord end)
start
- starting pointend
- ending pointpublic static Coord[] line_(int startX, int startY, int endX, int endY)
startX
- x of starting pointstartY
- y of starting pointendX
- x of ending pointendY
- y of ending pointpublic static Coord[] line_(Coord start, Coord end)
start
- starting pointend
- ending pointpublic static boolean reachable(Coord start, Coord target, double[][] resistanceMap, java.util.ArrayList<Coord> buffer)
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 DungeonUtility.generateResistances(char[][])
or DungeonUtility.generateSimpleResistances(char[][])
.
buffer
may be null (in which case a temporary ArrayList is allocated, which can be wasteful), or may be
an existing ArrayList 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.start
- the starting pointtarget
- the target pointresistanceMap
- a resistance map as produced by DungeonUtility.generateResistances(char[][])
; 0 is visible and 1 is blockedbuffer
- an ArrayList of Coord that will be reused and cleared if not null; will be modifiedpublic static boolean reachable(int startX, int startY, int targetX, int targetY, double[][] resistanceMap, java.util.ArrayList<Coord> buffer)
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 DungeonUtility.generateResistances(char[][])
or DungeonUtility.generateSimpleResistances(char[][])
.
buffer
may be null (in which case a temporary ArrayList is allocated, which can be wasteful), or may be
an existing ArrayList 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.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 by DungeonUtility.generateResistances(char[][])
; 0 is visible and 1 is blockedbuffer
- an ArrayList of Coord that will be reused and cleared if not null; will be modifiedpublic static boolean reachable(int startX, int startY, int targetX, int targetY, int maxLength, double[][] resistanceMap, java.util.ArrayList<Coord> buffer)
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 DungeonUtility.generateResistances(char[][])
or DungeonUtility.generateSimpleResistances(char[][])
.
buffer
may be null (in which case a temporary ArrayList is allocated, which can be wasteful), or may be
an existing ArrayList 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.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 by DungeonUtility.generateResistances(char[][])
; 0 is visible and 1 is blockedbuffer
- an ArrayList of Coord that will be reused and cleared if not null; will be modifiedpublic static boolean reachable(Coord start, Coord target, double[][] resistanceMap)
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
DungeonUtility.generateResistances(char[][])
or DungeonUtility.generateSimpleResistances(char[][])
. If the starting
point can see the target point, this returns true; otherwise this returns false.start
- the starting pointtarget
- the target pointresistanceMap
- a resistance map as produced by DungeonUtility.generateResistances(char[][])
; 0 is visible and 1 is blockedpublic static boolean reachable(int startX, int startY, int targetX, int targetY, double[][] resistanceMap)
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
DungeonUtility.generateResistances(char[][])
or DungeonUtility.generateSimpleResistances(char[][])
. If the starting
point can see the target point, this returns true; otherwise this returns false.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 by DungeonUtility.generateResistances(char[][])
; 0 is visible and 1 is blockedpublic static boolean reachable(int startX, int startY, int targetX, int targetY, int maxLength, double[][] resistanceMap)
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
DungeonUtility.generateResistances(char[][])
or DungeonUtility.generateSimpleResistances(char[][])
. If the starting
point can see the target point, this returns true; otherwise this returns false.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 by DungeonUtility.generateResistances(char[][])
; 0 is visible and 1 is blockedpublic static char[] lineChars(Coord[] line)
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, such as from Bresenham.line2D_(Coord, Coord)
, then it shouldn't throw an
exception but may produce a low-quality (disconnected visually) line.line
- a Coord array where each Coord is orthogonally adjacent to its neighbor(s) in the array; usually
produced via line_(Coord, Coord)
or line_(int, int, int, int)
public static char[] lineChars(java.util.List<Coord> line)
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, such as from Bresenham.line2D(Coord, Coord)
, then it shouldn't throw an
exception but may produce a low-quality (disconnected visually) line.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)
Copyright © Eben Howard 2012–2022. All rights reserved.