public class Region extends java.util.AbstractList<Coord> implements java.io.Serializable
GreasedRegion before using this class, unless you know Region does exactly
what you want.
| Modifier and Type | Field and Description |
|---|---|
protected Coord[] |
coords |
protected short[] |
raw |
| Constructor and Description |
|---|
Region(char[][] map,
char... using)
A constructor for a Region that takes a 2D char array, the kind produced by most map/dungeon generators in this
library, and a vararg or array of char that will have their Coord positions used where those chars appear in map.
|
Region(java.util.Collection<Coord> points)
A constructor for a Region that takes a Collection of Coord, such as a List or Set, and encodes all of them in
the Region.
|
Region(Coord... points)
A constructor for a Region that takes an array or vararg of Coord and encodes all of them in the Region.
|
Region(Coord center,
int circleRadius,
int mapWidth,
int mapHeight)
A constructor for a circular Region (possibly truncated at the edges) with a Coord center, an int radius, and a
maximum width and height that the Coords in this Region will not exceed.
|
Region(double[][] fovMap)
A constructor for a Region that takes a 2D double array, usually the kind produced by FOV, and stores only Coord
positions that correspond to values greater than 0.0 (actually, greater than epsilon, which here is 0.0001).
|
Region(double[][] dijkstraMap,
double maximum)
A constructor for a Region that takes a 2D double array, usually produced by DijkstraMap, and a maximum value,
and stores only Coord positions that correspond to values no greater than maximum.
|
Region(int minX,
int minY,
int width,
int height)
A constructor for a rectangular Region that stores Coords for the area from (minX,minY) at the minimum corner to
(width + minX - 1, height + minY - 1) at the maximum corner.
|
Region(Region other)
A constructor that copies another Region so this Region will have the same contents.
|
Region(short[] packedData)
A constructor for a Region that takes a specifically-formatted short array (packed data), as produced by
CoordPacker or sometimes other classes, like RegionMap or RoomFinder.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(Coord coord)
Adds a Coord to this Region, returning false if the Coord is null or already included in this, or true otherwise.
|
void |
debugPrint(int width,
int height)
Prints this Region to System.out as a grid of chars with the given width and height, using '.' for Coords this
contains and '#' for empty space.
|
Coord |
get(int index)
Gets the Coord stored at the given index in this Region, or null if index is out of bounds.
|
Coord[] |
getCoords()
Gets the Coords contained in this as an array, a direct reference that does permit modifying the Coords in your
own code without altering "dirty/clean" status.
|
Coord |
getRandomCoord(IRNG rng)
Gets a single random Coord from this using the given RNG (which can be seeded); returns null if this is empty.
|
short[] |
getRaw()
Gets a direct reference to this Region's "raw packed data"; don't modify it unless you know what you're doing!
It's fine to pass this to methods in CoordPacker, since essentially all of those methods won't modify packed data
given as arguments.
|
boolean |
isEmpty()
Returns true if there are no Coords in this Region, or false otherwise.
|
Region |
randomSeparated(int separation,
IRNG rng)
Takes this region and walks through its Coords in chunks with length equal to separation, creating a new Region
where one randomly-chosen Coord in each chunk is kept and the others are discarded.
|
Region |
separated(int separation)
Takes this region and walks through its Coords in chunks with length equal to separation, creating a new Region
where one Coord in each chunk is kept and the others are discarded.
|
void |
setCoords(Coord... coords)
Changes this Region to include the given Coords and disregard its previous contents.
|
void |
setRaw(short[] raw)
Sets the "raw packed data" to the given short array, as generated by CoordPacker or some parts of RegionMap.
|
int |
size()
Gets the size of this Region as measured in Coords stored.
|
boolean[][] |
toBooleanArray(int width,
int height)
Gets a representation of this Region as a 2D boolean array with the given width and height.
|
char[][] |
toCharArray(int width,
int height,
char on,
char off)
Gets a representation of this Region as a 2D char array with the given width and height, using on to represent
present Coords and off to represent absent ones.
|
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subListaddAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitprotected short[] raw
protected Coord[] coords
public Region(double[][] fovMap)
fovMap - a 2D double array as produced by FOVpublic Region(double[][] dijkstraMap,
double maximum)
dijkstraMap - a 2D double array as produced by DijkstraMapmaximum - the highest value that a position can have in dijkstraMap and still be given a Coord in thispublic Region(char[][] map,
char... using)
map - a 2D char array that is usually the kind returned by a dungeon or map generatorusing - an array or vararg of char that will have their Coords used where they appear in mappublic Region(Coord... points)
points - an array or vararg of Coord that will be stored in this Region, none can be nullpublic Region(java.util.Collection<Coord> points)
points - a Collection of Coord that will be stored in this Region, none can be nullpublic Region(Region other)
other - another Region to copy into this onepublic Region(Coord center, int circleRadius, int mapWidth, int mapHeight)
center - the center of the circular RegioncircleRadius - the radius as an intmapWidth - one more than the maximum x-position of any Coord this will containmapHeight - one more than the maximum y-position of any Coord this will containpublic Region(int minX,
int minY,
int width,
int height)
minX - lowest x-coordinate in the rectangle; should be between 0 and 255minY - lowest y-coordinate in the rectangle; should be between 0 and 255width - total width of the rectangle; must be non-negativeheight - total height of the rectangle; must be non-negativepublic Region(short[] packedData)
packedData - a short array as produced by CoordPacker (usually), or sometimes RoomFinder or RegionMappublic Coord getRandomCoord(IRNG rng)
rng - the source of random numbers used to get a random Coord from this Regionpublic Region separated(int separation)
separation - an int where higher numbers mean there will be more distance between Coords, and fewer totalpublic Region randomSeparated(int separation, IRNG rng)
separation - an int where higher numbers mean there will be more distance between Coords, and fewer totalrng - the source of random numbers used to randomize Coords used, removing any noticeable patternpublic boolean[][] toBooleanArray(int width,
int height)
width - the width of the 2D array to returnheight - the height of the 2D array to returnpublic char[][] toCharArray(int width,
int height,
char on,
char off)
width - the width of the 2D array to returnheight - the height of the 2D array to returnon - the char to use when a Coord is present in this Regionoff - the char to use where no Coord is present in this Regionpublic Coord get(int index)
get in interface java.util.List<Coord>get in class java.util.AbstractList<Coord>index - the index into this Region to get a Coord at; should be less than size() and non-negative.public int size()
public boolean isEmpty()
public boolean add(Coord coord)
add in interface java.util.Collection<Coord>add in interface java.util.List<Coord>add in class java.util.AbstractList<Coord>coord - a Coord to add to this regionpublic short[] getRaw()
public void setRaw(short[] raw)
raw - a short array of packed data; has a very specific format and should usually not be made manuallypublic Coord[] getCoords()
public void setCoords(Coord... coords)
coords - an array or vararg of Coord that will be used as the entirety of this Regionpublic void debugPrint(int width,
int height)
width - the width in chars of the grid to printheight - the height in chars of the grid to printCopyright © Eben Howard 2012–2022. All rights reserved.