public class LOS
extends java.lang.Object
implements java.io.Serializable
BRESENHAM
to
the constructor). For more specialized usage, there are other kinds of LOS in
this class, like lines that make no diagonal moves between cells (using
ORTHO
, or lines that check a wide path (but these use different
methods, like thickReachable(Radius)
).
RAY
is a tiny fraction faster than BRESENHAM
but produces
rather low-quality lines in comparison. Calculating the visibility of 40,000
lines in a 102x102 dungeon takes within 3% of 950ms (on an Intel i7-4700MQ laptop
processor) for every one of BRESENHAM, DDA, ORTHO, and RAY, even with ORTHO
finding a different kind of line by design.Modifier and Type | Field and Description |
---|---|
static int |
BRESENHAM
A Bresenham-based line-of-sight algorithm.
|
static int |
DDA
Optimized algorithm for Bresenham-like lines.
|
static int |
ELIAS
Uses Wu's Algorithm as modified by Elias to draw the line.
|
static int |
ORTHO
Draws a line using only North/South/East/West movement.
|
static int |
RAY
Uses a series of rays internal to the start and end point to
determine visibility.
|
static int |
THICK
Draws a line as if with a thick brush, going from a point between
a corner of the starting cell and the center of the starting cell
to the corresponding corner of the target cell, and considers the
target visible if any portion of the thick stroke reached it.
|
Constructor and Description |
---|
LOS()
Constructs an LOS that will draw Bresenham lines and measure distances using the CIRCLE radius strategy.
|
LOS(int type)
Constructs an LOS with the given type number, which must equal a static field in this class such as BRESENHAM.
|
Modifier and Type | Method and Description |
---|---|
java.util.ArrayDeque<Coord> |
getLastPath()
Returns the path of the last LOS calculation, with the starting point as
the head of the queue.
|
Radius |
getRadiusStrategy()
Gets the radius strategy this uses.
|
boolean |
isReachable(char[][] walls,
int startx,
int starty,
int targetx,
int targety)
Returns true if a line can be drawn from the start point to the target
point without intervening obstructions.
|
boolean |
isReachable(char[][] walls,
int startx,
int starty,
int targetx,
int targety,
Radius radiusStrategy)
Returns true if a line can be drawn from the start point to the target
point without intervening obstructions.
|
boolean |
isReachable(double[][] resistanceMap,
int startx,
int starty,
int targetx,
int targety)
Returns true if a line can be drawn from the start point to the target
point without intervening obstructions.
|
boolean |
isReachable(double[][] resistanceMap,
int startx,
int starty,
int targetx,
int targety,
Radius radiusStrategy)
Returns true if a line can be drawn from the start point to the target
point without intervening obstructions.
|
void |
setRadiusStrategy(Radius radiusStrategy)
Set the radius strategy to the given Radius; the default is CIRCLE if this is not called.
|
boolean |
spreadReachable(char[][] walls,
int startx,
int starty,
int targetx,
int targety,
Radius radiusStrategy,
int spread)
Returns true if a line can be drawn from the any of the points within spread cells of the start point,
to any of the corresponding points at the same direction and distance from the target point, without
intervening obstructions.
|
boolean |
spreadReachable(double[][] resistanceMap,
int startx,
int starty,
int targetx,
int targety,
Radius radiusStrategy,
int spread)
Returns true if a line can be drawn from the any of the points within spread cells of the start point,
to any of the corresponding points at the same direction and distance from the target point, without
intervening obstructions.
|
public static final int BRESENHAM
public static final int ELIAS
public static final int RAY
public static final int ORTHO
public static final int DDA
public static final int THICK
public LOS()
public LOS(int type)
type
- an int that must correspond to the value of a static field in this class (such as BRESENHAM)public Radius getRadiusStrategy()
public void setRadiusStrategy(Radius radiusStrategy)
radiusStrategy
- a Radius enum to determine how distances are measuredpublic boolean isReachable(char[][] walls, int startx, int starty, int targetx, int targety)
walls
- '#' is fully opaque, anything else is fully transparent, as always this uses x,y indexing.startx
- starting x position on the gridstarty
- starting y position on the gridtargetx
- ending x position on the gridtargety
- ending y position on the gridpublic boolean isReachable(double[][] resistanceMap, int startx, int starty, int targetx, int targety)
resistanceMap
- 0.0 is fully transparent, 1.0 is fully opaque, as always this uses x,y indexing.startx
- starting x position on the gridstarty
- starting y position on the gridtargetx
- ending x position on the gridtargety
- ending y position on the gridpublic boolean isReachable(double[][] resistanceMap, int startx, int starty, int targetx, int targety, Radius radiusStrategy)
resistanceMap
- 0.0 is fully transparent, 1.0 is fully opaque, as always this uses x,y indexing.startx
- starting x position on the gridstarty
- starting y position on the gridtargetx
- ending x position on the gridtargety
- ending y position on the gridradiusStrategy
- the strategy to use in computing unit distancepublic boolean isReachable(char[][] walls, int startx, int starty, int targetx, int targety, Radius radiusStrategy)
walls
- '#' is fully opaque, anything else is fully transparent, as always this uses x,y indexing.startx
- starting x position on the gridstarty
- starting y position on the gridtargetx
- ending x position on the gridtargety
- ending y position on the gridradiusStrategy
- the strategy to use in computing unit distancepublic boolean spreadReachable(char[][] walls, int startx, int starty, int targetx, int targety, Radius radiusStrategy, int spread)
walls
- '#' is fully opaque, anything else is fully transparent, as always this uses x,y indexing.startx
- starting x position on the gridstarty
- starting y position on the gridtargetx
- ending x position on the gridtargety
- ending y position on the gridradiusStrategy
- the strategy to use in computing unit distancespread
- the number of cells outward, measured by radiusStrategy, to place extra start and target pointspublic boolean spreadReachable(double[][] resistanceMap, int startx, int starty, int targetx, int targety, Radius radiusStrategy, int spread)
resistanceMap
- 0.0 is fully transparent, 1.0 is fully opaque, as always this uses x,y indexing.startx
- starting x position on the gridstarty
- starting y position on the gridtargetx
- ending x position on the gridtargety
- ending y position on the gridradiusStrategy
- the strategy to use in computing unit distancespread
- the number of cells outward, measured by radiusStrategy, to place extra start and target pointspublic java.util.ArrayDeque<Coord> getLastPath()
Copyright © Eben Howard 2012–2022. All rights reserved.