public class GreasedRegion extends Zone.Skeleton implements java.util.Collection<Coord>, java.io.Serializable, MutableZone
expand()
), retract()
), fringe()
), surface()
, and flood(GreasedRegion)
,
and slightly faster on others, like and(GreasedRegion)
(called intersectPacked() in CoordPacker) and
or(GreasedRegion)
(called unionPacked() in CoordPacker).
expand()
changes any cells next to a currently "on" cell to also be "on." It's 4-way, and has an
8-way variant expand8way()
. There's an overload that expands several times as if by a loop,
expand(int)
, which also has an 8-way variant. You can use expandSeries(int)
to get multiple
GreasedRegions produced as intermediate values of a series of expansions; this also has an 8-way variant.
expandSeriesToLimit()
returns an ArrayList of as many GreasedRegions as it takes to expand until no more
cells can change.retract()
is just like expand()
, but changes any "on" cells that are next to an "off" cell
to also be "off." It can be thought of as expanding the "off" cells, with the subtle difference that the edges
are also considered "off" here. All of the above variants of expand()
listed above have equivalents for
retract()
, like retractSeriesToLimit()
.fringe()
is like expand()
, but doesn't keep the old contents of the GreasedRegion, only the
cells that are added. This has some differences in how fringe(int)
works (it returns a
multiple-cell-thick fringe section, still not containing any of the original), and how fringeSeries(int)
works (it returns many single-cell-thick fringe sections). There's a fringeSeriesToLimit()
, too.surface()
is something like removing the result of retract()
from this GreasedRegion; it
gets only those "on" cells that are next to an "off" cell. Like with fringe()
, the variants are a little
different; surface(int)
gets a multiple-cell deep surface, and surfaceSeries(int)
gets a series
of single-cell deep rings from further and further inside the original GreasedRegion. Yes, there's also a
surfaceSeriesToLimit()
.flood(GreasedRegion)
is useful; it acts like expand()
, but won't change any cells unless
they are "on" in its bounds
argument, another GreasedRegion. There's also
flood(GreasedRegion, int)
, which may be most useful with a very large amount
parameter to fill
up the bounds completely with whatever the original GreasedRegion could reach. flood8way(GreasedRegion)
,
floodSeries(GreasedRegion, int)
, and floodSeriesToLimit(GreasedRegion)
are all here, too.spill(GreasedRegion, int, IRNG)
is like calling flood(GreasedRegion)
many times, but only
expanding one cell on the edge each time, randomly choosing it. As long as volume
is not enough to fully
fill the reachable part of bounds
, the filled area will be random but always connected.randomRegion(IRNG, int)
simply chooses "on" points from this
GreasedRegion until it reaches size
, deteriorate(RandomnessSource, double)
randomly removes
points but stops when the fraction of cells remaining is equal to preservation
, fray(double)
acts like deteriorate(RandomnessSource, double)
but only affects the surface (what surface()
would return), and disperseRandom(RandomnessSource)
randomly removes one of each pair of "on" cells.
separatedRegionBlue(double)
if you want
to get an approximate fraction of well-separated "on" cells from a GreasedRegion; there are other similar methods
but the ones that use BlueNoise
seem superior. fray(double)
also has a quasi-random version that
doesn't use a RandomnessSource.singleRandom(IRNG)
),randomPortion(IRNG, int)
),randomRegion(IRNG, int)
),mixedRandomSeparated(double, int, long)
with
a random long for the last parameter, or separatedBlue(double)
if you don't want a random seed),mixedRandomRegion(double, int, long)
or separatedRegionBlue(double)
),asCoords()
to get a Coord array, or produce a 2D array of the contents
with decode()
or toChars(char, char)
),mask(char[][], char)
,
inverseMask(char[][], char)
, writeDoubles(double[][], double)
, or
writeIntsInto(int[][], int)
, along with variations on those.sum(GreasedRegion...)
or
toChars()
. The most effective techniques regarding GreasedRegion involve multiple methods, like getting a
few random points from an existing GreasedRegion representing floor tiles in a dungeon with
randomRegion(IRNG, int)
, then finding a random expansion of those initial points with
spill(GreasedRegion, int, IRNG)
, giving the original GreasedRegion of floor tiles as the first argument.
This could be used to position puddles of water or toxic waste in a dungeon level, while still keeping the starting
points and finished points within the boundaries of valid (floor) cells. If you wanted to place something like mold
that can be on floors or on cells immediately adjacent to floors (like walls), you could call expand()
on
the floor tiles before calling spill, allowing the spill to spread onto non-floor cells that are next to floors.
remake(GreasedRegion)
, or give the information that would normally be used to
construct a fresh GreasedRegion to an existing one of the same dimensions with refill(boolean[][])
or any
of the overloads of refill(). These re-methods don't do as much work as a constructor does if the width and height
of their argument are identical to their current width and height, and don't create more garbage for the GC.
Modifier and Type | Class and Description |
---|---|
class |
GreasedRegion.GRIterator |
Zone.Helper, Zone.Skeleton
Constructor and Description |
---|
GreasedRegion()
Constructs an empty 64x64 GreasedRegion.
|
GreasedRegion(boolean[][] bits)
Constructs a GreasedRegion with the given rectangular boolean array, with width of bits.length and height of
bits[0].length, any value of true considered "on", and any value of false considered "off."
|
GreasedRegion(boolean[] bits,
int width,
int height)
Constructs a GreasedRegion with the given 1D boolean array, with the given width and height, where an [x][y]
position is obtained from bits given an index n with x = n / height, y = n % height, any value of true
considered "on", and any value of false considered "off."
|
GreasedRegion(byte[][] map,
int lower,
int upper)
Constructs this GreasedRegion using a byte[][], treating cells as on if they are greater than or equal to lower
and less than upper, or off otherwise.
|
GreasedRegion(char[][] map,
char yes)
Constructs a GreasedRegion with the given rectangular char array, with width of map.length and height of
map[0].length, any value that equals yes is considered "on", and any other value considered "off."
|
GreasedRegion(char[][] map,
char[] yes)
Constructs a GreasedRegion with the given rectangular char array, with width of map.length and height of
map[0].length, any value that equals yes is considered "on", and any other value considered "off."
|
GreasedRegion(Coord single,
int width,
int height)
Constructor for a GreasedRegion that contains a single "on" cell, and has the given width and height.
|
GreasedRegion(double[][] map,
double upperBound)
Constructs this GreasedRegion using a double[][] (typically one generated by
DijkstraMap ) that only stores two relevant states: an "on" state for values less than
or equal to upperBound (inclusive), and an "off" state for anything else. |
GreasedRegion(double[][] map,
double lowerBound,
double upperBound)
Constructs this GreasedRegion using a double[][] (typically one generated by
DijkstraMap ) that only stores two relevant states: an "on" state for values between
lowerBound (inclusive) and upperBound (exclusive), and an "off" state for anything else. |
GreasedRegion(double[][] map,
double lowerBound,
double upperBound,
int scale)
Constructs this GreasedRegion using a double[][] that only stores two relevant states: an "on" state for values
between lowerBound (inclusive) and upperBound (exclusive), and an "off" state for anything else.
|
GreasedRegion(GreasedRegion other)
Copy constructor that takes another GreasedRegion and copies all of its data into this new one.
|
GreasedRegion(int[][] map,
int yes)
Constructs a GreasedRegion with the given rectangular int array, with width of map.length and height of
map[0].length, any value that equals yes is considered "on", and any other value considered "off."
|
GreasedRegion(int[][] map,
int lower,
int upper)
Constructs this GreasedRegion using an int[][], treating cells as on if they are greater than or equal to lower
and less than upper, or off otherwise.
|
GreasedRegion(int width,
int height)
Constructor for an empty GreasedRegion of the given width and height.
|
GreasedRegion(int width,
int height,
Coord... points)
Constructor for a GreasedRegion that can have several "on" cells specified, and has the given width and height.
|
GreasedRegion(int width,
int height,
java.lang.Iterable<Coord> points)
Constructor for a GreasedRegion that can have several "on" cells specified, and has the given width and height.
|
GreasedRegion(IRNG random,
int width,
int height)
Constructor for a random GreasedRegion of the given width and height, typically assigning approximately half of
the cells in this to "on" and the rest to off.
|
GreasedRegion(long[] data2,
int width,
int height)
Primarily for internal use, this constructor copies data2 exactly into the internal long array the new
GreasedRegion will use, and does not perform any validation steps to ensure that cells that would be "on" but are
outside the actual height of the GreasedRegion are actually removed (this only matters if height is not a
multiple of 64).
|
GreasedRegion(long[] data2,
int dataWidth,
int dataHeight,
int width,
int height)
Primarily for internal use, this constructor copies data2 into the internal long array the new GreasedRegion will
use, but treats data2 as having the dimensions [dataWidth][dataHeight], and uses the potentially-different
dimensions [width][height] for the constructed GreasedRegion.
|
GreasedRegion(RandomnessSource random,
double fraction,
int width,
int height)
Constructor for a random GreasedRegion of the given width and height, trying to set the given fraction of cells
to on.
|
GreasedRegion(RandomnessSource random,
int width,
int height)
Constructor for a random GreasedRegion of the given width and height, typically assigning approximately half of
the cells in this to "on" and the rest to off.
|
GreasedRegion(short[][] map,
int lower,
int upper)
Constructs this GreasedRegion using a short[][], treating cells as on if they are greater than or equal to lower
and less than upper, or off otherwise.
|
GreasedRegion(java.lang.String[] map,
char yes)
Weird constructor that takes a String array, _as it would be printed_, so each String is a row and indexing would
be done with y, x instead of the normal x, y.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(Coord coord) |
boolean |
addAll(java.util.Collection<? extends Coord> c) |
GreasedRegion |
allOn()
Sets all cells in this to "on."
|
GreasedRegion |
alterBounds(int widthChange,
int heightChange)
Changes the width and/or height of this GreasedRegion, enlarging or shrinking starting at the edges where
x == width - 1 and y == height - 1 . |
GreasedRegion |
and(GreasedRegion other)
Intersection of two GreasedRegions, assigning the result into this GreasedRegion.
|
GreasedRegion |
andNot(GreasedRegion other)
Difference of two GreasedRegions, assigning the result into this GreasedRegion.
|
GreasedRegion |
andWrapping64(GreasedRegion other)
Intersection of two GreasedRegions, assigning the result into this GreasedRegion, with the special requirement
that other must be a 64x64 area, and the special property that other will be considered tiled to cover all of the
area of this GreasedRegion.
|
static java.util.Collection<GreasedRegion> |
appendContaining(java.util.Collection<GreasedRegion> into,
int x,
int y,
java.util.Collection<GreasedRegion> packed)
Tries to look up the position x,y in each GreasedRegion in packed; each GreasedRegion that contains that x,y
point is appended into the Collection
into . |
static java.util.Collection<GreasedRegion> |
appendContaining(java.util.Collection<GreasedRegion> into,
int x,
int y,
GreasedRegion... packed)
Tries to look up the position x,y in each GreasedRegion in packed; each GreasedRegion that contains that x,y
point is appended into the Collection
into . |
java.lang.StringBuilder |
appendPackedString(java.lang.StringBuilder packing)
Packs this GreasedRegion using a Hilbert Curve RLE algorithm and appends the result into
packing . |
static long |
approximateBits(RandomnessSource random,
int bitCount)
Generates a random 64-bit long with a number of '1' bits (Hamming weight) equal on average to bitCount.
|
Coord[] |
asCoords() |
Coord[] |
asCoords(Coord[] points) |
int[] |
asEncoded() |
int[] |
asTightEncoded() |
Coord |
atFraction(double fraction) |
int |
atFractionTight(double fraction) |
static int[][] |
bitSum(GreasedRegion... regions)
Generates a 2D int array from an array or vararg of GreasedRegions, treating each cell in the nth region as the
nth bit of the int at the corresponding x,y cell in the int array.
|
void |
clear() |
GreasedRegion |
connect()
Takes the pairs of "on" cells in this GreasedRegion that are separated by exactly one cell in an orthogonal line,
and changes the gap cells to "on" as well.
|
GreasedRegion |
connect8way()
Takes the pairs of "on" cells in this GreasedRegion that are separated by exactly one cell in an orthogonal or
diagonal line, and changes the gap cells to "on" as well.
|
GreasedRegion |
connectLines()
Takes the pairs of "on" cells in this GreasedRegion that are separated by exactly one cell in an orthogonal or
diagonal line, and changes the gap cells to "on" as well.
|
boolean |
contains(Coord c)
Checks if
c is present in this GreasedRegion. |
boolean |
contains(int x,
int y) |
boolean |
contains(java.lang.Object o) |
boolean |
contains(Zone other)
Checks whether all Coords in
other are also present in this . |
boolean |
containsAll(java.util.Collection<?> c) |
GreasedRegion |
copy()
Simple method that returns a newly-allocated copy of this GreasedRegion; modifications to one won't change the
other, and this method returns the copy while leaving the original unchanged.
|
GreasedRegion |
copyRotated(int turns)
Makes a copy of this GreasedRegion that has been rotated 90 degrees
turns times. |
boolean[][] |
decode()
Returns this GreasedRegion's data as a 2D boolean array, [width][height] in size, with on treated as true and off
treated as false.
|
static GreasedRegion |
decompress(java.lang.String compressed)
Decompresses a String returned by
toCompressedString() , returning a new GreasedRegion with identical
width, height, and contents to the GreasedRegion before compression. |
static GreasedRegion |
deserializeFromString(java.lang.String s) |
GreasedRegion |
deteriorate(RandomnessSource random,
double preservation)
Randomly removes points from a GreasedRegion, with preservation as a fraction between 1.0 (keep all) and 0.0
(remove all).
|
GreasedRegion |
deteriorate(RandomnessSource rng,
int preservation)
Randomly removes points from a GreasedRegion, with larger values for preservation keeping more of the existing
shape intact.
|
static double[][] |
dijkstraScan(char[][] map,
Coord... goals)
Discouraged from active use; slower than
DijkstraMap and has less features. |
static double[][] |
dijkstraScan8way(char[][] map,
Coord... goals)
Discouraged from active use; slower than
DijkstraMap and has less features. |
GreasedRegion |
disperse()
Removes "on" cells that are orthogonally adjacent to other "on" cells, keeping at least one cell in a group "on."
Uses a "checkerboard" pattern to determine which cells to turn off, with all cells that would be black on a
checkerboard turned off and all others kept as-is.
|
GreasedRegion |
disperse8way()
Removes "on" cells that are 8-way adjacent to other "on" cells, keeping at least one cell in a group "on."
Uses a "grid-like" pattern to determine which cells to turn off, with all cells with even x and even y kept as-is
but all other cells (with either or both odd x or odd y) turned off.
|
static int |
disperseBits(int n)
Narrow-purpose; takes an int that represents a distance down the Z-order curve and moves its bits around so that
its x component is stored in the bottom 16 bits (use
(n & 0xffff) to obtain) and its y component is
stored in the upper 16 bits (use (n >>> 16) to obtain). |
GreasedRegion |
disperseRandom(RandomnessSource random)
Removes "on" cells that are nearby other "on" cells, with a random factor to which bits are actually turned off
that still ensures exactly half of the bits are kept as-is (the one exception is when height is an odd number,
which makes the bottom row slightly random).
|
GreasedRegion |
empty()
Equivalent to
clear() , setting all cells to "off," but also returns this for chaining. |
boolean |
equals(java.lang.Object o) |
GreasedRegion |
expand()
Takes the "on" cells in this GreasedRegion and expands them by one cell in the 4 orthogonal directions, making
each "on" cell take up a plus-shaped area that may overlap with other "on" cells (which is just a normal "on"
cell then).
|
GreasedRegion |
expand(int amount)
Takes the "on" cells in this GreasedRegion and expands them by amount cells in the 4 orthogonal directions,
making each "on" cell take up a plus-shaped area that may overlap with other "on" cells (which is just a normal
"on" cell then).
|
GreasedRegion |
expand8way() |
GreasedRegion |
expand8way(int amount)
Expands this Zone in the four cardinal and four diagonal directions, performing the expansion consecutively
distance times. |
GreasedRegion[] |
expandSeries(int amount)
Takes the "on" cells in this GreasedRegion and produces amount GreasedRegions, each one expanded by 1 cell in
the 4 orthogonal directions relative to the previous GreasedRegion, making each "on" cell take up a plus-shaped
area that may overlap with other "on" cells (which is just a normal "on" cell then).
|
GreasedRegion[] |
expandSeries8way(int amount) |
java.util.ArrayList<GreasedRegion> |
expandSeriesToLimit() |
java.util.ArrayList<GreasedRegion> |
expandSeriesToLimit8way() |
GreasedRegion |
extend()
Gets a new Zone that contains all the Coords in
this plus all
neighboring Coords, which can be orthogonally or diagonally adjacent
to any Coord this has in it. |
GreasedRegion |
fill(boolean contents)
Sets all cells in this to "on" if contents is true, or "off" if contents is false.
|
Coord |
first()
Gets the first Coord in the iteration order, or (-1,-1) if this GreasedRegion is empty.
|
int |
firstTight() |
Coord |
fit(double xFraction,
double yFraction) |
int[][] |
fit(int[][] basis,
int defaultValue) |
GreasedRegion |
flip(boolean leftRight,
boolean upDown) |
GreasedRegion |
flood(GreasedRegion bounds)
Like
expand() , but limits expansion to the "on" cells of bounds . |
GreasedRegion |
flood(GreasedRegion bounds,
int amount)
Like
expand(int) , but limits expansion to the "on" cells of bounds . |
GreasedRegion |
flood8way(GreasedRegion bounds)
Like
expand8way() , but limits expansion to the "on" cells of bounds . |
GreasedRegion |
flood8way(GreasedRegion bounds,
int amount)
Like
expand8way(int) , but limits expansion to the "on" cells of bounds . |
GreasedRegion[] |
floodSeries(GreasedRegion bounds,
int amount)
Repeatedly calls
flood(GreasedRegion) amount times and returns the intermediate steps in a
GreasedRegion array of size amount . |
GreasedRegion[] |
floodSeries8way(GreasedRegion bounds,
int amount)
Repeatedly calls
flood8way(GreasedRegion) amount times and returns the intermediate steps in a
GreasedRegion array of size amount . |
java.util.ArrayList<GreasedRegion> |
floodSeriesToLimit(GreasedRegion bounds)
Repeatedly generates new GreasedRegions, each one cell expanded in 4 directions from the previous GreasedRegion
and staying inside the "on" cells of
bounds , until it can't expand any more. |
java.util.ArrayList<GreasedRegion> |
floodSeriesToLimit8way(GreasedRegion bounds)
Repeatedly generates new GreasedRegions, each one cell expanded in 8 directions from the previous GreasedRegion
and staying inside the "on" cells of
bounds , until it can't expand any more. |
GreasedRegion |
fray(double fractionKept)
Like
retract() , this removes the "on" cells that are 4-way-adjacent to any "off" cell, but unlike that
method it keeps a fraction of those surface cells, quasi-randomly selecting them. |
GreasedRegion |
fray(RandomnessSource random,
double fractionKept)
Like
retract() , this removes the "on" cells that are 4-way-adjacent to any "off" cell, but unlike that
method it keeps a fraction of those surface cells, randomly selecting them. |
GreasedRegion |
fringe()
Takes the "on" cells in this GreasedRegion and expands them by one cell in the 4 orthogonal directions, producing
a diamoond shape, then removes the original area before expansion, producing only the cells that were "off" in
this and within 1 cell (orthogonal-only) of an "on" cell.
|
GreasedRegion |
fringe(int amount)
Takes the "on" cells in this GreasedRegion and expands them by amount cells in the 4 orthogonal directions
(iteratively, producing a diamond shape), then removes the original area before expansion, producing only the
cells that were "off" in this and within amount cells (orthogonal-only) of an "on" cell.
|
GreasedRegion |
fringe8way() |
GreasedRegion |
fringe8way(int amount) |
GreasedRegion[] |
fringeSeries(int amount)
Takes the "on" cells in this GreasedRegion and produces amount GreasedRegions, each one expanded by 1 cell in
the 4 orthogonal directions relative to the previous GreasedRegion, making each "on" cell take up a diamond-
shaped area.
|
GreasedRegion[] |
fringeSeries8way(int amount) |
java.util.ArrayList<GreasedRegion> |
fringeSeriesToLimit() |
java.util.ArrayList<GreasedRegion> |
fringeSeriesToLimit8way() |
java.util.List<Coord> |
getAll() |
double |
getDiagonal()
Gets the diagonal distance from the point combining the lowest x-value present in this GreasedRegion with the
lowest y-value in this, to the point combining the highest x-value and the highest y-value.
|
GreasedRegion |
getExternalBorder()
Gets a Collection of Coord values that are not in this GreasedRegion, but are
adjacent to it, either orthogonally or diagonally.
|
int |
getHeight()
Gets the distance between the minimum y-value contained in this GreasedRegion and the maximum y-value in it.
|
GreasedRegion |
getInternalBorder() |
int |
getWidth()
Gets the distance between the minimum x-value contained in this GreasedRegion and the maximum x-value in it.
|
long |
hash64() |
long |
hash64(long seed)
Computes a 64-bit hash code of this GreasedRegion given a 64-bit seed; even if given two very similar seeds,
this should produce very different hash codes for the same GreasedRegion.
|
int |
hashCode() |
GreasedRegion |
insert(Coord point)
Sets the cell at point to "on".
|
GreasedRegion |
insert(int tight)
Sets the given cell, "tightly" encoded for a specific width/height as by
asTightEncoded() , to "on". |
GreasedRegion |
insert(int x,
int y)
Sets the cell at x,y to "on".
|
GreasedRegion |
insert(int x,
int y,
GreasedRegion other)
Takes another GreasedRegion, called other, with potentially different size and inserts its "on" cells into thi
GreasedRegion at the given x,y offset, allowing negative x and/or y to put only part of other in this.
|
GreasedRegion |
insertCircle(Coord center,
int radius) |
GreasedRegion |
insertRectangle(int startX,
int startY,
int rectangleWidth,
int rectangleHeight) |
GreasedRegion |
insertSeveral(Coord... points) |
GreasedRegion |
insertSeveral(int[] points) |
GreasedRegion |
insertSeveral(java.lang.Iterable<Coord> points) |
GreasedRegion |
insertTranslation(int x,
int y)
Adds to this GreasedRegion with a moved set of its own "on" cells, moved to the given x and y offset.
|
static int |
interleaveBits(int x,
int y)
Narrow-purpose; takes an x and a y value, each between 0 and 65535 inclusive, and interleaves their bits so the
least significant bit and every other bit after it are filled with the bits of x, while the
second-least-significant bit and every other bit after that are filled with the bits of y.
|
boolean |
intersects(GreasedRegion other)
Returns true if any cell is "on" in both this GreasedRegion and in other; returns false otherwise.
|
boolean |
intersectsWith(Zone other) |
char[][] |
intoChars(char[][] chars,
char on)
Fills this GreasedRegion's data into the given 2D char array, modifying it and returning it, with "on" cells
filled with the char parameter
on and "off" cells left as-is. |
char[][] |
intoChars(char[][] chars,
char on,
char off)
Fills this GreasedRegion's data into the given 2D char array, modifying it and returning it, with "on" cells
filled with the char parameter
on and "off" cells with the parameter off . |
char[][] |
inverseMask(char[][] map,
char toWrite)
Returns a copy of map where if a cell is "off" in this GreasedRegion, this keeps the value in map intact,
and where a cell is "on", it instead writes the char toWrite.
|
boolean |
isEmpty() |
java.util.Iterator<Coord> |
iterator() |
GreasedRegion |
largestPart()
Finds the largest contiguous area of "on" cells in this GreasedRegion and returns it; does not modify this
GreasedRegion.
|
GreasedRegion |
largestPart8way()
Finds the largest contiguous area of "on" cells in this GreasedRegion and returns it; does not modify this
GreasedRegion.
|
Coord |
last()
Gets the last Coord in the iteration order, or (-1,-1) if this GreasedRegion is empty.
|
int |
lastTight() |
char[][] |
mask(char[][] map,
char filler)
Returns a copy of map where if a cell is "on" in this GreasedRegion, this keeps the value in map intact,
and where a cell is "off", it instead writes the char filler.
|
short[][] |
mask(short[][] map,
short filler)
Returns a copy of map where if a cell is "on" in this GreasedRegion, this keeps the value in map intact,
and where a cell is "off", it instead writes the short filler.
|
GreasedRegion |
mirrorY()
Returns a new GreasedRegion that has been mirrored along the rightmost edge, parallel to the y-axis.
|
GreasedRegion |
mixedRandomRegion(double fraction)
Modifies this GreasedRegion so it contains a deterministic but random-seeming subset of its previous contents,
choosing cells so that the
size() matches the given fraction of the total amount of "on" cells
in this. |
GreasedRegion |
mixedRandomRegion(double fraction,
int limit)
Modifies this GreasedRegion so it contains a deterministic but random-seeming subset of its previous contents,
choosing cells so that the
size() matches the given fraction of the total amount of "on" cells
in this. |
GreasedRegion |
mixedRandomRegion(double fraction,
int limit,
long seed)
Modifies this GreasedRegion so it contains a deterministic but random-seeming subset of its previous contents,
choosing cells so that the
size() matches the given fraction of the total amount of "on" cells
in this. |
Coord[] |
mixedRandomSeparated(double fraction)
Gets a Coord array from the "on" contents of this GreasedRegion, using a deterministic but random-seeming
scattering of chosen cells with a count that matches the given
fraction of the total amount of "on" cells
in this. |
Coord[] |
mixedRandomSeparated(double fraction,
int limit)
Gets a Coord array from the "on" contents of this GreasedRegion, using a deterministic but random-seeming
scattering of chosen cells with a count that matches the given
fraction of the total amount of "on" cells
in this. |
Coord[] |
mixedRandomSeparated(double fraction,
int limit,
long seed)
Gets a Coord array from the "on" contents of this GreasedRegion, using a deterministic but random-seeming
scattering of chosen cells with a count that matches the given
fraction of the total amount of "on" cells
in this. |
Coord[] |
mixedRandomSeparatedAlt(double fraction,
int limit,
long seed)
Gets a Coord array from the "on" contents of this GreasedRegion, using a deterministic but random-seeming
scattering of chosen cells with a count that matches the given
fraction of the total amount of "on" cells
in this. |
GreasedRegion |
neighborDown()
Modifies this GreasedRegion so the only cells that will be "on" have a neighbor downwards when this is called.
|
GreasedRegion |
neighborDownLeft()
Modifies this GreasedRegion so the only cells that will be "on" have a neighbor downwards and to the left when
this is called.
|
GreasedRegion |
neighborDownRight()
Modifies this GreasedRegion so the only cells that will be "on" have a neighbor downwards and to the right when
this is called.
|
GreasedRegion |
neighborLeft()
Modifies this GreasedRegion so the only cells that will be "on" have a neighbor to the left when this is called.
|
GreasedRegion |
neighborRight()
Modifies this GreasedRegion so the only cells that will be "on" have a neighbor to the right when this is called.
|
GreasedRegion |
neighborUp()
Modifies this GreasedRegion so the only cells that will be "on" have a neighbor upwards when this is called.
|
GreasedRegion |
neighborUpLeft()
Modifies this GreasedRegion so the only cells that will be "on" have a neighbor upwards and to the left when this
is called.
|
GreasedRegion |
neighborUpRight()
Modifies this GreasedRegion so the only cells that will be "on" have a neighbor upwards and to the right when
this is called.
|
GreasedRegion |
not()
Negates this GreasedRegion, turning "on" to "off" and "off" to "on."
|
GreasedRegion |
notAnd(GreasedRegion other)
Like andNot, but subtracts this GreasedRegion from other and stores the result in this GreasedRegion, without
mutating other.
|
Coord |
nth(int index) |
Coord |
nthZCurve(int index)
Like
nth(int) , this gets the Coord at a given index along a path through the GreasedRegion, but unlike
nth(), this traverses the path in a zig-zag pattern called the Z-Order Curve. |
int |
nthZCurveTight(int index)
Like
nth(int) , this finds a given index along a path through the GreasedRegion, but unlike nth(), this
traverses the path in a zig-zag pattern called the Z-Order Curve, and unlike nthZCurve(int) , this does
not return a Coord and instead produces a "tight"-encoded int. |
static GreasedRegion |
of(int width,
int height,
long... data)
Constructs a GreasedRegion using a vararg for data.
|
GreasedRegion |
or(GreasedRegion other)
Union of two GreasedRegions, assigning the result into this GreasedRegion.
|
void |
perceptualHashQuick(long[] into,
int[] working)
Calculates a perceptual hash for this GreasedRegion using a method that is only precise for some sizes of
GreasedRegion; it writes a result to into, and uses working as a temporary buffer.
|
GreasedRegion |
quasiRandomRegion(double fraction)
Modifies this GreasedRegion so it contains a quasi-random subset of its previous contents, choosing cells so that
the
size() matches the given fraction of the total amount of "on" cells in this. |
GreasedRegion |
quasiRandomRegion(double fraction,
int limit)
Modifies this GreasedRegion so it contains a quasi-random subset of its previous contents, choosing cells so that
the
size() matches the given fraction of the total amount of "on" cells in this. |
Coord[] |
quasiRandomSeparated(double fraction)
Gets a Coord array from the "on" contents of this GreasedRegion, using a quasi-random scattering of chosen cells
with a count that matches the given
fraction of the total amount of "on" cells in this. |
Coord[] |
quasiRandomSeparated(double fraction,
int limit)
Gets a Coord array from the "on" contents of this GreasedRegion, using a quasi-random scattering of chosen cells
with a count that matches the given
fraction of the total amount of "on" cells in this. |
static long |
randomInterleave(RandomnessSource random)
Gets a somewhat-random long with exactly 32 bits set; in each pair of bits starting at bit 0 and bit 1, then bit
2 and bit 3, up to bit 62 and bit 3, one bit will be 1 and one bit will be 0 in each pair.
|
Coord[] |
randomPortion(IRNG rng,
int size) |
GreasedRegion |
randomRegion(IRNG rng,
int size) |
GreasedRegion |
randomScatter(IRNG rng,
int minimumDistance)
Modifies this GreasedRegion so it contains a random subset of its previous contents, choosing cells so that the
distance between any two "on" cells is at least
minimumDistance , with at least one cell as "on" if any
were "on" in this originally. |
GreasedRegion |
randomScatter(IRNG rng,
int minimumDistance,
int limit)
Modifies this GreasedRegion so it contains a random subset of its previous contents, choosing cells so that the
distance between any two "on" cells is at least
minimumDistance , with at least one cell as "on" if any
were "on" in this originally. |
Coord[] |
randomSeparated(double fraction,
IRNG rng)
Don't use this in new code; prefer
mixedRandomSeparated(double, int, long) with a random long as the
last parameter. |
Coord[] |
randomSeparated(double fraction,
IRNG rng,
int limit)
Don't use this in new code; prefer
mixedRandomSeparated(double, int, long) with a random long as the
last parameter. |
double |
rateDensity() |
double |
rateRegularity() |
GreasedRegion |
refill(boolean[][] map)
Reassigns this GreasedRegion with the given rectangular boolean array, reusing the current data storage (without
extra allocations) if this.width == map.length and this.height == map[0].length.
|
GreasedRegion |
refill(boolean[] bits,
int width,
int height)
Reassigns this GreasedRegion with the given 1D boolean array, reusing the current data storage (without
extra allocations) if this.width == width and this.height == height, where an [x][y]
position is obtained from bits given an index n with x = n / height, y = n % height, any value of true
considered "on", and any value of false considered "off."
|
GreasedRegion |
refill(byte[][] map,
int lower,
int upper)
Reassigns this GreasedRegion with the given rectangular byte array, reusing the current data storage (without
extra allocations) if this.width == map.length and this.height == map[0].length.
|
GreasedRegion |
refill(char[][] map,
char yes)
Reassigns this GreasedRegion with the given rectangular char array, reusing the current data storage (without
extra allocations) if this.width == map.length and this.height == map[0].length.
|
GreasedRegion |
refill(char[][] map,
char[] yes)
Reassigns this GreasedRegion with the given rectangular char array, reusing the current data storage (without
extra allocations) if this.width == map.length and this.height == map[0].length.
|
GreasedRegion |
refill(double[][] map,
double upperBound)
Reassigns this GreasedRegion with the given rectangular double array, reusing the current data storage (without
extra allocations) if this.width == map.length and this.height == map[0].length.
|
GreasedRegion |
refill(double[][] map,
double lower,
double upper)
Reassigns this GreasedRegion with the given rectangular double array, reusing the current data storage (without
extra allocations) if this.width == map.length and this.height == map[0].length.
|
GreasedRegion |
refill(double[][] map,
double lowerBound,
double upperBound,
int scale)
Reassigns this GreasedRegion with the given rectangular double array, reusing the current data storage (without
extra allocations) if
this.width == map.length * scale && this.height == map[0].length * scale . |
GreasedRegion |
refill(int[][] map,
int yes)
Reassigns this GreasedRegion with the given rectangular int array, reusing the current data storage (without
extra allocations) if this.width == map.length and this.height == map[0].length.
|
GreasedRegion |
refill(int[][] map,
int lower,
int upper)
Reassigns this GreasedRegion with the given rectangular int array, reusing the current data storage (without
extra allocations) if this.width == map.length and this.height == map[0].length.
|
GreasedRegion |
refill(IRNG random,
int width,
int height)
Reassigns this GreasedRegion by filling it with random values from random, reusing the current data storage
(without extra allocations) if this.width == width and this.height == height, and typically assigning
approximately half of the cells in this to "on" and the rest to off.
|
GreasedRegion |
refill(long[] data2,
int dataWidth,
int dataHeight,
int width,
int height)
Primarily for internal use, this method copies data2 into the internal long array the new GreasedRegion will
use, but treats data2 as having the dimensions [dataWidth][dataHeight], and uses the potentially-different
dimensions [width][height] for this GreasedRegion, potentially re-allocating the internal data this uses if width
and/or height are different from what they were.
|
GreasedRegion |
refill(RandomnessSource random,
double fraction,
int width,
int height)
Reassigns this GreasedRegion randomly, reusing the current data storage (without extra allocations) if this.width
== width and this.height == height, while trying to set the given fraction of cells to on.
|
GreasedRegion |
refill(RandomnessSource random,
int width,
int height)
Reassigns this GreasedRegion by filling it with random values from random, reusing the current data storage
(without extra allocations) if this.width == width and this.height == height, and typically assigning
approximately half of the cells in this to "on" and the rest to off.
|
GreasedRegion |
refill(short[][] map,
int lower,
int upper)
Reassigns this GreasedRegion with the given rectangular short array, reusing the current data storage (without
extra allocations) if this.width == map.length and this.height == map[0].length.
|
GreasedRegion |
refill(java.lang.String[] map,
char yes)
Weird refill method that takes a String array, _as it would be printed_, so each String is a row and indexing
would be done with y, x instead of the normal x, y.
|
GreasedRegion |
remake(GreasedRegion other)
A useful method for efficiency, remake() reassigns this GreasedRegion to have its contents replaced by other.
|
GreasedRegion |
remove(Coord point) |
GreasedRegion |
remove(int x,
int y) |
GreasedRegion |
remove(int x,
int y,
GreasedRegion other)
Takes another GreasedRegion, called other, with potentially different size and removes its "on" cells from this
GreasedRegion at the given x,y offset, allowing negative x and/or y to remove only part of other in this.
|
boolean |
remove(java.lang.Object o) |
boolean |
removeAll(java.util.Collection<?> c) |
GreasedRegion |
removeCircle(Coord center,
int radius) |
GreasedRegion |
removeCorners()
Where a cell is "on" but forms a right-angle with exactly two orthogonally-adjacent "on" cells and exactly two
orthogonally-adjacent "off" cells, this turns each of those cells "off." This won't affect east-west lines of
flat "on" cells, nor north-south lines.
|
GreasedRegion |
removeEdges()
Turns all cells that are adjacent to the boundaries of the GreasedRegion to "off".
|
GreasedRegion |
removeIsolated() |
GreasedRegion |
removeRectangle(int startX,
int startY,
int rectangleWidth,
int rectangleHeight)
Removes all "on" cells from (startX, startY) inclusive
to (startX+rectangleWidth, startY+rectangleHeight) exclusive, removing a total width of rectangleWidth and a
total height of rectangleHeight in cells.
|
GreasedRegion |
removeSeveral(Coord... points) |
GreasedRegion |
removeSeveral(java.lang.Iterable<Coord> points) |
GreasedRegion |
resizeAndEmpty(int width,
int height)
If this GreasedRegion has the same width and height passed as parameters, this acts the same as
empty() ,
makes no allocations, and returns this GreasedRegion with its contents all "off"; otherwise, this does allocate
a differently-sized amount of internal data to match the new width and height, sets the fields to all match the
new width and height, and returns this GreasedRegion with its new width and height, with all contents "off". |
boolean |
retainAll(java.util.Collection<?> c) |
GreasedRegion |
retract()
Takes the "on" cells in this GreasedRegion and retracts them by one cell in the 4 orthogonal directions,
making each "on" cell that was orthogonally adjacent to an "off" cell into an "off" cell.
|
GreasedRegion |
retract(int amount)
Takes the "on" cells in this GreasedRegion and retracts them by one cell in the 4 orthogonal directions, doing
this iteeratively amount times, making each "on" cell that was within amount orthogonal distance to an "off" cell
into an "off" cell.
|
GreasedRegion |
retract8way() |
GreasedRegion |
retract8way(int amount) |
GreasedRegion[] |
retractSeries(int amount) |
GreasedRegion[] |
retractSeries8way(int amount) |
java.util.ArrayList<GreasedRegion> |
retractSeriesToLimit() |
java.util.ArrayList<GreasedRegion> |
retractSeriesToLimit8way() |
Coord[] |
separatedBlue(double fraction)
Gets a Coord array from the "on" contents of this GreasedRegion, using a quasi-random scattering of chosen cells
with a count that matches the given
fraction of the total amount of "on" cells in this. |
Coord[] |
separatedBlue(double fraction,
int limit)
Gets a Coord array from the "on" contents of this GreasedRegion, using a quasi-random scattering of chosen cells
with a count that matches the given
fraction of the total amount of "on" cells in this. |
Coord[] |
separatedPortion(double fraction)
Don't use this in new code; prefer
mixedRandomSeparated(double) , quasiRandomSeparated(double) ,
or separatedZCurve(double) . |
GreasedRegion |
separatedRegionBlue(double fraction)
Modifies this GreasedRegion so it contains a quasi-random subset of its previous contents, choosing cells so that
the
size() matches the given fraction of the total amount of "on" cells in this. |
GreasedRegion |
separatedRegionBlue(double fraction,
int limit)
Modifies this GreasedRegion so it contains a quasi-random subset of its previous contents, choosing cells so that
the
size() matches the given fraction of the total amount of "on" cells in this. |
GreasedRegion |
separatedRegionZCurve(double fraction)
Modifies this GreasedRegion so it contains a quasi-random subset of its previous contents, choosing cells so that
the
size() matches the given fraction of the total amount of "on" cells in this. |
GreasedRegion |
separatedRegionZCurve(double fraction,
int limit)
Modifies this GreasedRegion so it contains a quasi-random subset of its previous contents, choosing cells so that
the
size() matches the given fraction of the total amount of "on" cells in this. |
Coord[] |
separatedZCurve(double fraction)
Gets a Coord array from the "on" contents of this GreasedRegion, using a quasi-random scattering of chosen cells
with a count that matches the given
fraction of the total amount of "on" cells in this. |
Coord[] |
separatedZCurve(double fraction,
int limit)
Gets a Coord array from the "on" contents of this GreasedRegion, using a quasi-random scattering of chosen cells
with a count that matches the given
fraction of the total amount of "on" cells in this. |
java.lang.String |
serializeToString() |
GreasedRegion |
set(boolean value,
Coord point)
Sets the cell at point to on if value is true or off if value is false.
|
GreasedRegion |
set(boolean value,
int x,
int y)
Sets the cell at x,y to on if value is true or off if value is false.
|
java.lang.StringBuilder |
show(char on,
char off)
Returns this GreasedRegion's data as a StringBuilder, with each row made of the parameter on for "on" cells and
the parameter off for "off" cells, separated by newlines, with no trailing newline at the end.
|
Coord |
singleRandom(IRNG rng)
Gets a single random Coord from the "on" positions in this GreasedRegion, or the Coord (-1,-1) if this is empty.
|
int |
singleRandomTight(IRNG rng) |
int |
size() |
GreasedRegion |
spill(GreasedRegion bounds,
int volume,
IRNG rng)
A randomized flood-fill that modifies this GreasedRegion so it randomly adds adjacent cells while staying inside
the "on" cells of
bounds , until size() is equal to volume or there are no more cells
this can expand into. |
java.util.ArrayList<GreasedRegion> |
split()
If this GreasedRegion stores multiple unconnected "on" areas, this finds each isolated area (areas that
are only adjacent diagonally are considered separate from each other) and returns it as an element in an
ArrayList of GreasedRegion, with one GreasedRegion per isolated area.
|
java.util.ArrayList<GreasedRegion> |
split8way()
If this GreasedRegion stores multiple unconnected "on" areas, this finds each isolated area (areas that
are only adjacent diagonally are considered one area with this) and returns it as an element in an
ArrayList of GreasedRegion, with one GreasedRegion per isolated area.
|
static int[][] |
sum(GreasedRegion... regions)
Generates a 2D int array from an array or vararg of GreasedRegions, starting at all 0 and adding 1 to the int at
a position once for every GreasedRegion that has that cell as "on." This means if you give 8 GreasedRegions to
this method, it can produce any number between 0 and 8 in a cell; if you give 16 GreasedRegions, then it can
produce any number between 0 and 16 in a cell.
|
static int[][] |
sum(java.util.List<GreasedRegion> regions)
Generates a 2D int array from a List of GreasedRegions, starting at all 0 and adding 1 to the int at
a position once for every GreasedRegion that has that cell as "on." This means if you give 8 GreasedRegions to
this method, it can produce any number between 0 and 8 in a cell; if you give 16 GreasedRegions, then it can
produce any number between 0 and 16 in a cell.
|
static double[][] |
sumDouble(GreasedRegion... regions)
Generates a 2D double array from an array or vararg of GreasedRegions, starting at all 0 and adding 1 to the double at
a position once for every GreasedRegion that has that cell as "on." This means if you give 8 GreasedRegions to
this method, it can produce any number between 0 and 8 in a cell; if you give 16 GreasedRegions, then it can
produce any number between 0 and 16 in a cell.
|
static double[][] |
sumDouble(java.util.List<GreasedRegion> regions)
Generates a 2D double array from a List of GreasedRegions, starting at all 0 and adding 1 to the double at
a position once for every GreasedRegion that has that cell as "on." This means if you give 8 GreasedRegions to
this method, it can produce any number between 0 and 8 in a cell; if you give 16 GreasedRegions, then it can
produce any number between 0 and 16 in a cell.
|
static int[][] |
sumInto(int[][] existing,
GreasedRegion... regions)
Adds to an existing 2D int array with an array or vararg of GreasedRegions, adding 1 to the int in existing at
a position once for every GreasedRegion that has that cell as "on." This means if you give 8 GreasedRegions to
this method, it can increment by any number between 0 and 8 in a cell; if you give 16 GreasedRegions, then it can
increase the value in existing by any number between 0 and 16 in a cell.
|
static double[][] |
sumIntoDouble(double[][] existing,
GreasedRegion... regions)
Adds to an existing 2D double array with an array or vararg of GreasedRegions, adding 1 to the double in existing
at a position once for every GreasedRegion that has that cell as "on." This means if you give 8 GreasedRegions to
this method, it can increment by any number between 0 and 8 in a cell; if you give 16 GreasedRegions, then it can
increase the value in existing by any number between 0 and 16 in a cell.
|
static int[][] |
sumWeighted(GreasedRegion[] regions,
int[] weights)
Generates a 2D int array from an array of GreasedRegions and an array of weights, starting the 2D result at all 0
and, for every GreasedRegion that has that cell as "on," adding the int in the corresponding weights array at
the position of that cell.
|
static double[][] |
sumWeightedDouble(GreasedRegion[] regions,
double[] weights)
Generates a 2D double array from an array of GreasedRegions and an array of weights, starting the 2D result at
all 0 and, for every GreasedRegion that has that cell as "on," adding the double in the corresponding weights
array at the position of that cell.
|
GreasedRegion |
surface() |
GreasedRegion |
surface(int amount) |
GreasedRegion |
surface8way() |
GreasedRegion |
surface8way(int amount) |
GreasedRegion[] |
surfaceSeries(int amount) |
GreasedRegion[] |
surfaceSeries8way(int amount) |
java.util.ArrayList<GreasedRegion> |
surfaceSeriesToLimit() |
java.util.ArrayList<GreasedRegion> |
surfaceSeriesToLimit8way() |
GreasedRegion |
thin()
Like
retract() , this reduces the width of thick areas of this GreasedRegion, but thin() will not remove
areas that would be identical in a subsequent call to retract(), such as if the area would be eliminated. |
GreasedRegion |
thin8way()
Like
retract8way() , this reduces the width of thick areas of this GreasedRegion, but thin8way() will not
remove areas that would be identical in a subsequent call to retract8way(), such as if the area would be
eliminated. |
GreasedRegion |
thinFully()
Calls
thin() repeatedly, until the result is unchanged from the last call. |
GreasedRegion |
thinFully8way()
Calls
thin8way() repeatedly, until the result is unchanged from the last call. |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
char[][] |
toChars()
Returns this GreasedRegion's data as a 2D char array, [width][height] in size, with "on" cells filled with '.'
and "off" cells with '#'.
|
char[][] |
toChars(char on,
char off)
Returns this GreasedRegion's data as a 2D char array, [width][height] in size, with "on" cells filled with the
char parameter on and "off" cells with the parameter off.
|
java.lang.String |
toCompressedString()
Compresses this GreasedRegion into a UTF-16 String and returns the String without modifying this GreasedRegion.
|
GreasedRegion |
toggle(int x,
int y)
Changes the on/off state of the cell with the given x and y, making an on cell into an off cell, or an off cell
into an on cell.
|
java.lang.String |
toString()
Returns a legible String representation of this that can be printed over multiple lines, with all "on" cells
represented by '.' and all "off" cells by '#', in roguelike floors-on walls-off convention, separating each row
by newlines (without a final trailing newline, so you could append text right after this).
|
GreasedRegion |
translate(Coord c)
Translates a copy of
this by the x,y values in c . |
GreasedRegion |
translate(int x,
int y)
Moves the "on" cells in this GreasedRegion to the given x and y offset, removing cells that move out of bounds.
|
static GreasedRegion |
unpackString(java.lang.String packed)
Unpacks a String returned by
appendPackedString(StringBuilder) , returning a new GreasedRegion with
identical width, height, and contents to the GreasedRegion before packing. |
static OrderedSet<GreasedRegion> |
whichContain(int x,
int y,
java.util.Collection<GreasedRegion> packed) |
static OrderedSet<GreasedRegion> |
whichContain(int x,
int y,
GreasedRegion... packed) |
char[][] |
writeCharsInto(char[][] map,
char toWrite)
Like
inverseMask(char[][], char) , but modifies map in-place and returns it. |
double[][] |
writeDoubles(double[][] map,
double toWrite)
"Inverse mask for doubles;" returns a copy of map where if a cell is "off" in this GreasedRegion, this keeps
the value in map intact, and where a cell is "on", it instead writes the double toWrite.
|
double[][] |
writeDoublesInto(double[][] map,
double toWrite)
"Inverse mask for doubles;" returns a copy of map where if a cell is "off" in this GreasedRegion, this keeps
the value in map intact, and where a cell is "on", it instead writes the double toWrite.
|
int[][] |
writeInts(int[][] map,
int toWrite)
"Inverse mask for ints;" returns a copy of map where if a cell is "off" in this GreasedRegion, this keeps
the value in map intact, and where a cell is "on", it instead writes the int toWrite.
|
int[][] |
writeIntsInto(int[][] map,
int toWrite)
"Inverse mask for ints;" returns a copy of map where if a cell is "off" in this GreasedRegion, this keeps
the value in map intact, and where a cell is "on", it instead writes the int toWrite.
|
int |
xBound(boolean smallestBound) |
GreasedRegion |
xor(GreasedRegion other)
Symmetric difference (more commonly known as exclusive or, hence the name) of two GreasedRegions, assigning the
result into this GreasedRegion.
|
int |
yBound(boolean smallestBound) |
GreasedRegion |
zoom(int x,
int y)
Effectively doubles the x and y values of each cell this contains (not scaling each cell to be larger, so each
"on" cell will be surrounded by "off" cells), and re-maps the positions so the given x and y in the doubled space
become 0,0 in the resulting GreasedRegion (which is this, assigning to itself).
|
getCenter
public GreasedRegion()
public GreasedRegion(boolean[][] bits)
bits
- a rectangular 2D boolean array where true is on and false is offpublic GreasedRegion(char[][] map, char yes)
map
- a rectangular 2D char array where yes is on and everything else is offyes
- which char to encode as "on"public GreasedRegion(char[][] map, char[] yes)
map
- a rectangular 2D char array where yes is on and everything else is offyes
- which char to encode as "on"public GreasedRegion(java.lang.String[] map, char yes)
map
- String array (as printed, not the normal storage) where each String is a rowyes
- the char to consider "on" in the GreasedRegionpublic GreasedRegion(int[][] map, int yes)
map
- a rectangular 2D int array where an int == yes is on and everything else is offyes
- which int to encode as "on"public GreasedRegion(int[][] map, int lower, int upper)
map
- an int[][] that should have some ints between lower and upperlower
- lower bound, inclusive; all on cells will have values in map that are at least equal to lowerupper
- upper bound, exclusive; all on cells will have values in map that are less than upperpublic GreasedRegion(byte[][] map, int lower, int upper)
map
- a byte[][] that should have some bytes between lower and upperlower
- lower bound, inclusive; all on cells will have values in map that are at least equal to lowerupper
- upper bound, exclusive; all on cells will have values in map that are less than upperpublic GreasedRegion(short[][] map, int lower, int upper)
map
- a short[][] that should have some shorts between lower and upperlower
- lower bound, inclusive; all on cells will have values in map that are at least equal to lowerupper
- upper bound, exclusive; all on cells will have values in map that are less than upperpublic GreasedRegion(double[][] map, double upperBound)
DijkstraMap
) that only stores two relevant states: an "on" state for values less than
or equal to upperBound (inclusive), and an "off" state for anything else.map
- a double[][] that probably relates in some way to DijkstraMap.upperBound
- upper inclusive; any double greater than this will be off, any others will be onpublic GreasedRegion(double[][] map, double lowerBound, double upperBound)
DijkstraMap
) that only stores two relevant states: an "on" state for values between
lowerBound (inclusive) and upperBound (exclusive), and an "off" state for anything else.map
- a double[][] that probably relates in some way to DijkstraMap.lowerBound
- lower inclusive; any double lower than this will be off, any equal to or greater than this,
but less than upper, will be onupperBound
- upper exclusive; any double greater than or equal to this this will be off, any doubles both
less than this and equal to or greater than lower will be onpublic GreasedRegion(double[][] map, double lowerBound, double upperBound, int scale)
map
- a double[][]; depending on scale, the GreasedRegion may have different width and heightlowerBound
- lower inclusive; any double lower than this will be off, any equal to or greater than this,
but less than upper, will be onupperBound
- upper exclusive; any double greater than or equal to this this will be off, any doubles both
less than this and equal to or greater than lower will be onscale
- the size of the square of cells in this that each "on" value in map will correspond topublic GreasedRegion(boolean[] bits, int width, int height)
bits
- a 1D boolean array where true is on and false is offwidth
- the width of the desired GreasedRegion; width * height should equal bits.lengthheight
- the height of the desired GreasedRegion; width * height should equal bits.lengthpublic GreasedRegion(int width, int height)
width
- the maximum width for the GreasedRegionheight
- the maximum height for the GreasedRegionpublic GreasedRegion(Coord single, int width, int height)
single
- the one (x,y) point to store as "on" in this GreasedRegionwidth
- the maximum width for the GreasedRegionheight
- the maximum height for the GreasedRegionpublic GreasedRegion(int width, int height, Coord... points)
width
- the maximum width for the GreasedRegionheight
- the maximum height for the GreasedRegionpoints
- an array or vararg of Coord to store as "on" in this GreasedRegionpublic GreasedRegion(int width, int height, java.lang.Iterable<Coord> points)
width
- the maximum width for the GreasedRegionheight
- the maximum height for the GreasedRegionpoints
- an array or vararg of Coord to store as "on" in this GreasedRegionpublic GreasedRegion(RandomnessSource random, int width, int height)
random
- a RandomnessSource that should have a good nextLong() method; DiverRNG is excellent but Lathe32RNG is faster on GWT (only there)width
- the maximum width for the GreasedRegionheight
- the maximum height for the GreasedRegionpublic GreasedRegion(IRNG random, int width, int height)
GreasedRegion(RandomnessSource, int, int)
.random
- an IRNG, such as an RNG, that this will use to generate its contentswidth
- the maximum width for the GreasedRegionheight
- the maximum height for the GreasedRegionpublic GreasedRegion(RandomnessSource random, double fraction, int width, int height)
random
can be an object like a DiverRNG
, an RNG
backed by a well-distributed
RandomnessSource like its default, DiverRNG, a GWTRNG
(especially if you target GWT, where it will
perform much better than most alternatives), or any of various other RandomnessSource implementations that
distribute bits well for RandomnessSource.nextLong()
, but should not be intentionally-biased RNGs like
DharmaRNG
or EditRNG
, nor double-based QRNGs like VanDerCorputQRNG
or SobolQRNG
.random
- a RandomnessSource that should produce high-quality long values, like the defaults for RNG
fraction
- between 0.0 and 1.0 (clamped), only considering a precision of 1/64.0 (0.015625) between stepswidth
- the maximum width for the GreasedRegionheight
- the maximum height for the GreasedRegionpublic GreasedRegion(GreasedRegion other)
remake(GreasedRegion)
method on the variable instead, which will, if it has the same width and height
as the other GreasedRegion, avoid creating garbage and quickly fill the variable with the other's contents.other
- another GreasedRegion that will be copied into this new GreasedRegionfor a convenience method that just uses this constructor
public GreasedRegion(long[] data2, int width, int height)
data2
- a long array that is typically from another GreasedRegion, and would be hard to make otherwisewidth
- the width of the GreasedRegion to constructheight
- the height of the GreasedRegion to constructpublic GreasedRegion(long[] data2, int dataWidth, int dataHeight, int width, int height)
data2
- a long array that is typically from another GreasedRegion, and would be hard to make otherwisedataWidth
- the width to interpret data2 as havingdataHeight
- the height to interpret data2 as havingwidth
- the width of the GreasedRegion to constructheight
- the height of the GreasedRegion to constructpublic GreasedRegion refill(boolean[][] map)
map
- a rectangular 2D boolean array where true is on and false is offpublic GreasedRegion refill(char[][] map, char yes)
map
- a rectangular 2D char array where yes is on and everything else is offyes
- which char to encode as "on"public GreasedRegion refill(char[][] map, char[] yes)
map
- a rectangular 2D char array where yes is on and everything else is offyes
- which char to encode as "on"public GreasedRegion refill(java.lang.String[] map, char yes)
map
- String array (as printed, not the normal storage) where each String is a rowyes
- the char to consider "on" in the GreasedRegionpublic GreasedRegion refill(int[][] map, int yes)
map
- a rectangular 2D int array where an int == yes is on and everything else is offyes
- which int to encode as "on"public GreasedRegion refill(int[][] map, int lower, int upper)
map
- a rectangular 2D int array that should have some values between lower and upperlower
- lower bound, inclusive; all on cells will have values in map that are at least equal to lowerupper
- upper bound, exclusive; all on cells will have values in map that are less than upperpublic GreasedRegion refill(byte[][] map, int lower, int upper)
map
- a rectangular 2D byte array that should have some values between lower and upperlower
- lower bound, inclusive; all on cells will have values in map that are at least equal to lowerupper
- upper bound, exclusive; all on cells will have values in map that are less than upperpublic GreasedRegion refill(short[][] map, int lower, int upper)
map
- a rectangular 2D short array that should have some values between lower and upperlower
- lower bound, inclusive; all on cells will have values in map that are at least equal to lowerupper
- upper bound, exclusive; all on cells will have values in map that are less than upperpublic GreasedRegion refill(double[][] map, double upperBound)
map
- a rectangular 2D double array that should usually have some values less than or equal to upperBoundupperBound
- upper bound, inclusive; all on cells will have values in map that are less than or equal to thispublic GreasedRegion refill(double[][] map, double lower, double upper)
map
- a rectangular 2D double array that should have some values between lower and upperlower
- lower bound, inclusive; all on cells will have values in map that are at least equal to lowerupper
- upper bound, exclusive; all on cells will have values in map that are less than upperpublic GreasedRegion refill(double[][] map, double lowerBound, double upperBound, int scale)
this.width == map.length * scale && this.height == map[0].length * scale
. The
current values stored in this are always cleared, then cells are treated as on if they are greater than or equal
to lower and less than upper, or off otherwise, before considering scaling. This variant scales the input so each
"on" position in map produces a 2x2 on area if scale is 2, a 3x3 area if scale is 3, and so on.map
- a double[][]; depending on scale, the GreasedRegion may have different width and heightlowerBound
- lower inclusive; any double lower than this will be off, any equal to or greater than this,
but less than upper, will be onupperBound
- upper exclusive; any double greater than or equal to this this will be off, any doubles both
less than this and equal to or greater than lower will be onscale
- the size of the square of cells in this that each "on" value in map will correspond topublic GreasedRegion refill(boolean[] bits, int width, int height)
bits
- a 1D boolean array where true is on and false is offwidth
- the width of the desired GreasedRegion; width * height should equal bits.lengthheight
- the height of the desired GreasedRegion; width * height should equal bits.lengthpublic GreasedRegion resizeAndEmpty(int width, int height)
empty()
,
makes no allocations, and returns this GreasedRegion with its contents all "off"; otherwise, this does allocate
a differently-sized amount of internal data to match the new width and height, sets the fields to all match the
new width and height, and returns this GreasedRegion with its new width and height, with all contents "off". This
is meant for cases where a GreasedRegion may be reused effectively, but its size may not always be the same.width
- the width to potentially resize this GreasedRegion toheight
- the height to potentially resize this GreasedRegion topublic GreasedRegion refill(RandomnessSource random, int width, int height)
random
- a RandomnessSource that should have a good nextLong() method; DiverRNG is excellent but Lathe32RNG is faster on GWT (only there)width
- the width of the desired GreasedRegionheight
- the height of the desired GreasedRegionpublic GreasedRegion refill(IRNG random, int width, int height)
random
- an IRNG that should have a good nextLong() method; an RNG constructed with the default RandomnessSource will be finewidth
- the width of the desired GreasedRegionheight
- the height of the desired GreasedRegionpublic GreasedRegion refill(RandomnessSource random, double fraction, int width, int height)
random
can be an object like a DiverRNG
, an RNG
backed by a well-distributed RandomnessSource like its
default, DiverRNG, a GWTRNG
(especially if you target GWT, where it will perform much better than most
alternatives), or any of various other RandomnessSource implementations that distribute bits well for
RandomnessSource.nextLong()
, but should not be intentionally-biased RNGs like DharmaRNG
or
EditRNG
, nor double-based QRNGs like VanDerCorputQRNG
or SobolQRNG
.random
- a RandomnessSource that should produce high-quality long values, like the defaults for RNG
fraction
- between 0.0 and 1.0 (clamped), only considering a precision of 1/64.0 (0.015625) between stepswidth
- the maximum width for the GreasedRegionheight
- the maximum height for the GreasedRegionpublic GreasedRegion refill(long[] data2, int dataWidth, int dataHeight, int width, int height)
data2
- a long array that is typically from another GreasedRegion, and would be hard to make otherwisedataWidth
- the width to interpret data2 as havingdataHeight
- the height to interpret data2 as havingwidth
- the width to set this GreasedRegion to haveheight
- the height to set this GreasedRegion to havepublic GreasedRegion remake(GreasedRegion other)
other
- another GreasedRegion to replace the data in this GreasedRegion withpublic GreasedRegion alterBounds(int widthChange, int heightChange)
x == width - 1
and y == height - 1
. There isn't an especially efficient way to expand from the
other edges, but this method is able to copy data in bulk, so at least this method should be very fast. You can
use insert(int, int, GreasedRegion)
if you want to place one GreasedRegion inside another one,
potentially with a different size. The space created by any enlargement starts all off; shrinking doesn't change
the existing data where it isn't removed by the shrink.widthChange
- the amount to change width by; can be positive, negative, or zeroheightChange
- the amount to change height by; can be positive, negative, or zeropublic GreasedRegion copyRotated(int turns)
turns
times. If using y-down
coordinates, then these rotations are clockwise; otherwise, they are counter-clockwise. This uses a copy because
in many caseswhere the GreasedRegion has non-equal width and height, the rotated version has different
dimensions, and that requires allocating most of a new GreasedRegion anyway. This GreasedRegion is never modifed
as a result of this method.turns
- how many times to rotate the copy (clockwise if using y-down, counterclockwise otherwise)public GreasedRegion flip(boolean leftRight, boolean upDown)
public GreasedRegion set(boolean value, int x, int y)
value
- the value to set in the cellx
- the x-position of the celly
- the y-position of the cellpublic GreasedRegion set(boolean value, Coord point)
value
- the value to set in the cellpoint
- the x,y Coord of the cell to setpublic GreasedRegion insert(int x, int y)
set(boolean, int, int)
if you just need to set a cell to "on".x
- the x-position of the celly
- the y-position of the cellpublic GreasedRegion insert(int tight)
asTightEncoded()
, to "on".
Does nothing if the cell is out of bounds.tight
- a cell tightly encoded for this GreasedRegion's width and heightpublic GreasedRegion insert(Coord point)
set(boolean, Coord)
if you just need to set a cell to "on".point
- the x,y Coord of the cellpublic GreasedRegion insert(int x, int y, GreasedRegion other)
x
- the x offset to start inserting other at; may be negativey
- the y offset to start inserting other at; may be negativeother
- the other GreasedRegion to insertpublic GreasedRegion insertSeveral(Coord... points)
public GreasedRegion insertSeveral(int[] points)
public GreasedRegion insertSeveral(java.lang.Iterable<Coord> points)
public GreasedRegion insertRectangle(int startX, int startY, int rectangleWidth, int rectangleHeight)
public GreasedRegion insertCircle(Coord center, int radius)
public GreasedRegion remove(int x, int y)
public GreasedRegion remove(Coord point)
public GreasedRegion remove(int x, int y, GreasedRegion other)
insert(int, int, GreasedRegion)
except that where insert only adds
cells, this only removes cells. Essentially, insert() is to or(GreasedRegion)
as remove() is to
andNot(GreasedRegion)
.x
- the x offset to start removing other from; may be negativey
- the y offset to start removing other from; may be negativeother
- the other GreasedRegion to removepublic GreasedRegion removeSeveral(Coord... points)
public GreasedRegion removeSeveral(java.lang.Iterable<Coord> points)
public GreasedRegion removeRectangle(int startX, int startY, int rectangleWidth, int rectangleHeight)
startX
- left side x-coordinatestartY
- top side (or bottom if positive y is up) y-coordinaterectangleWidth
- how many cells wide the area to remove isrectangleHeight
- how many cells tal the area to remove ispublic GreasedRegion removeCircle(Coord center, int radius)
public GreasedRegion empty()
clear()
, setting all cells to "off," but also returns this for chaining.public GreasedRegion allOn()
public GreasedRegion fill(boolean contents)
contents
- true to set all cells to on, false to set all cells to offpublic GreasedRegion removeEdges()
public GreasedRegion copy()
public boolean[][] decode()
public char[][] intoChars(char[][] chars, char on, char off)
on
and "off" cells with the parameter off
.chars
- a 2D char array that will be modified; must not be null, nor can it contain null elementson
- the char to use for "on" cellsoff
- the char to use for "off" cellspublic char[][] intoChars(char[][] chars, char on)
on
and "off" cells left as-is.chars
- a 2D char array that will be modified; must not be null, nor can it contain null elementson
- the char to use for "on" cellspublic char[][] toChars(char on, char off)
on
- the char to use for "on" cellsoff
- the char to use for "off" cellspublic char[][] toChars()
public java.lang.StringBuilder show(char on, char off)
on
- the char to use for "on" cellsoff
- the char to use for "off" cellspublic java.lang.String toString()
toString
in class java.lang.Object
public char[][] mask(char[][] map, char filler)
map
- a 2D char array that will not be modifiedfiller
- the char to use where this GreasedRegion stores an "off" cellpublic short[][] mask(short[][] map, short filler)
mask(char[][], char)
is more likely to be useful.map
- a 2D short array that will not be modifiedfiller
- the short to use where this GreasedRegion stores an "off" cellpublic char[][] inverseMask(char[][] map, char toWrite)
map
- a 2D char array that will not be modifiedtoWrite
- the char to use where this GreasedRegion stores an "on" cellpublic int[][] writeInts(int[][] map, int toWrite)
map
- a 2D int array that will not be modifiedtoWrite
- the int to use where this GreasedRegion stores an "on" cellpublic int[][] writeIntsInto(int[][] map, int toWrite)
writeInts(int[][], int)
.map
- a 2D int array that will be modifiedtoWrite
- the int to use where this GreasedRegion stores an "on" cellpublic double[][] writeDoubles(double[][] map, double toWrite)
map
- a 2D double array that will not be modifiedtoWrite
- the double to use where this GreasedRegion stores an "on" cellpublic double[][] writeDoublesInto(double[][] map, double toWrite)
writeDoubles(double[][], double)
.map
- a 2D double array that will be modifiedtoWrite
- the double to use where this GreasedRegion stores an "on" cellpublic char[][] writeCharsInto(char[][] map, char toWrite)
inverseMask(char[][], char)
, but modifies map
in-place and returns it. If a cell is "off"
in this GreasedRegion, this keeps the value in map intact, and where a cell is "on", it instead writes the char
toWrite. Modifies map in-place, unlike inverseMask(char[][], char)
.map
- a 2D char array that will be modifiedtoWrite
- the char to use where this GreasedRegion stores an "on" cellpublic GreasedRegion or(GreasedRegion other)
other
- another GreasedRegion that will not be modifiedpublic GreasedRegion and(GreasedRegion other)
other
- another GreasedRegion that will not be modifiedpublic GreasedRegion andWrapping64(GreasedRegion other)
other
- another GreasedRegion that will not be modified but must be 64x64 in size; will act as if it tilespublic GreasedRegion andNot(GreasedRegion other)
other
- another GreasedRegion that will not be modifiednotAnd is a very similar method that acts sort-of in reverse of this method
public GreasedRegion notAnd(GreasedRegion other)
other
- another GreasedRegion that will not be modifiedandNot is a very similar method that acts sort-of in reverse of this method
public GreasedRegion xor(GreasedRegion other)
other
- another GreasedRegion that will not be modifiedpublic GreasedRegion not()
public GreasedRegion translate(int x, int y)
translate
in interface Zone
translate
in class Zone.Skeleton
x
- the x offset to translate by; can be negativey
- the y offset to translate by; can be negativepublic GreasedRegion insertTranslation(int x, int y)
x
- the x offset to translate by; can be negativey
- the y offset to translate by; can be negativepublic GreasedRegion zoom(int x, int y)
x
- in the doubled coordinate space, the x position that should become 0 x in the result; can be negativey
- in the doubled coordinate space, the y position that should become 0 y in the result; can be negativepublic GreasedRegion connect()
expand()
, retract()
, fringe()
, and surface()
) all perform
very well by operating in bulk on up to 64 cells at a time.public GreasedRegion connect8way()
expand()
, retract()
, fringe()
, and surface()
) all perform
very well by operating in bulk on up to 64 cells at a time.public GreasedRegion connectLines()
connect8way()
, where a right
angle would always get the inner corners filled because it was considered a diagonal.
expand()
, retract()
, fringe()
, and surface()
) all perform
very well by operating in bulk on up to 64 cells at a time.public GreasedRegion thin()
retract()
, this reduces the width of thick areas of this GreasedRegion, but thin() will not remove
areas that would be identical in a subsequent call to retract(), such as if the area would be eliminated. This
is useful primarily for adjusting areas so they do not exceed a width of 2 cells, though their length (the longer
of the two dimensions) will be unaffected by this. Especially wide, irregularly-shaped areas may have unintended
appearances if you call this repeatedly or use thinFully()
; consider using this sparingly, or primarily
when an area has just gotten thicker than desired.
thin8way()
, but it may be a good idea to try this method as well (some of the old behavior
had problems where it yielded significantly larger minimum widths in some areas).public GreasedRegion thinFully()
thin()
repeatedly, until the result is unchanged from the last call. Consider using the idiom
expand8way().retract().thinFully()
to help change a possibly-strange appearance when the GreasedRegion
this is called on touches the edges of the grid. In general, this method is likely to go too far when it tries to
thin a round or irregular area, and this often results in many diagonal lines spanning the formerly-thick area.
thinFully8way()
, but it may be a good idea to try this method as well (some of the old
behavior had problems where it yielded significantly larger minimum widths in some areas).public GreasedRegion thin8way()
retract8way()
, this reduces the width of thick areas of this GreasedRegion, but thin8way() will not
remove areas that would be identical in a subsequent call to retract8way(), such as if the area would be
eliminated. This is useful primarily for adjusting areas so they do not exceed a width of 2 cells, though their
length (the longer of the two dimensions) will be unaffected by this. Especially wide, irregularly-shaped areas
may have unintended appearances if you call this repeatedly or use thinFully8way()
; consider using this
sparingly, or primarily when an area has just gotten thicker than desired.
thin()
, but now that name refers to a variant that uses 4-way adjacency.public GreasedRegion thinFully8way()
thin8way()
repeatedly, until the result is unchanged from the last call. Consider using the idiom
expand8way().retract().thinFully8way()
to help change a strange appearance when the GreasedRegion this is
called on touches the edges of the grid. In general, this method is likely to go too far when it tries to thin a
round or irregular area, and this often results in many diagonal lines spanning the formerly-thick area.
thinFully()
, but now that name refers to a variant that uses 4-way adjacency.public GreasedRegion disperse()
public GreasedRegion disperse8way()
public GreasedRegion disperseRandom(RandomnessSource random)
random
- the RNG used for a random factorpublic static long approximateBits(RandomnessSource random, int bitCount)
RNG
or any RandomnessSource with good 64-bit generation quality.
Calling this with a parameter of 16 will have on average 16 of the 64 bits in the returned long set to '1',
distributed pseudo-randomly, while a parameter of 47 will have on average 47 bits set. This can be useful for
certain code that uses bits to represent data but needs a different ratio of set bits to unset bits than 1:1.
random
can be an object like a DiverRNG
, an RNG
backed by a
well-distributed RandomnessSource like its default, DiverRNG, a GWTRNG
(especially if you target GWT,
where it will perform much better than most alternatives), or any of various other RandomnessSource
implementations that distribute bits well for RandomnessSource.nextLong()
, but should not be
intentionally-biased RNGs like DharmaRNG
or EditRNG
, nor double-based QRNGs like
VanDerCorputQRNG
or SobolQRNG
.random
- used to determine random factors; likely to be an RNG
, DiverRNG
, or GWTRNG
bitCount
- an int, only considered if between 0 and 64, that is the average number of bits to setpublic static long randomInterleave(RandomnessSource random)
public GreasedRegion expand()
retract()
, fringe()
, and surface()
) all perform
very well by operating in bulk on up to 64 cells at a time.public GreasedRegion expand(int amount)
expand()
, retract()
, fringe()
, and surface()
) all perform
very well by operating in bulk on up to 64 cells at a time.expand
in interface MutableZone
amount
- the amount to expand outward using Manhattan distance (diamond shape)public GreasedRegion[] expandSeries(int amount)
expand()
, retract()
, fringe()
, and surface()
) all perform
very well by operating in bulk on up to 64 cells at a time.public java.util.ArrayList<GreasedRegion> expandSeriesToLimit()
public GreasedRegion fringe()
surface()
, but
surface finds cells inside the current GreasedRegion, while fringe finds cells outside it.
expand()
, retract()
, fringe()
, and surface()
) all perform
very well by operating in bulk on up to 64 cells at a time. The surface and fringe methods do allocate one
temporary GreasedRegion to store the original before modification, but the others generally don't.public GreasedRegion fringe(int amount)
surface()
, but surface finds cells inside the current GreasedRegion, while fringe finds cells outside
it.
expand()
, retract()
, fringe()
, and surface()
) all perform
very well by operating in bulk on up to 64 cells at a time. The surface and fringe methods do allocate one
temporary GreasedRegion to store the original before modification, but the others generally don't.public GreasedRegion[] fringeSeries(int amount)
expand()
, retract()
, fringe()
, and surface()
) all perform
very well by operating in bulk on up to 64 cells at a time.public java.util.ArrayList<GreasedRegion> fringeSeriesToLimit()
public GreasedRegion retract()
expand()
, retract(), fringe()
, and surface()
) all perform
very well by operating in bulk on up to 64 cells at a time.public GreasedRegion retract(int amount)
expand()
, retract()
, fringe()
, and surface()
) all perform
very well by operating in bulk on up to 64 cells at a time.public GreasedRegion[] retractSeries(int amount)
public java.util.ArrayList<GreasedRegion> retractSeriesToLimit()
public GreasedRegion surface()
public GreasedRegion surface(int amount)
public GreasedRegion[] surfaceSeries(int amount)
public java.util.ArrayList<GreasedRegion> surfaceSeriesToLimit()
public GreasedRegion expand8way()
public GreasedRegion expand8way(int amount)
MutableZone
distance
times. Modified this Zone in-place and returns it for chaining.expand8way
in interface MutableZone
amount
- the amount to expand outward using Chebyshev distance (square shape)public GreasedRegion[] expandSeries8way(int amount)
public java.util.ArrayList<GreasedRegion> expandSeriesToLimit8way()
public GreasedRegion fringe8way()
public GreasedRegion fringe8way(int amount)
public GreasedRegion[] fringeSeries8way(int amount)
public java.util.ArrayList<GreasedRegion> fringeSeriesToLimit8way()
public GreasedRegion retract8way()
public GreasedRegion retract8way(int amount)
public GreasedRegion[] retractSeries8way(int amount)
public java.util.ArrayList<GreasedRegion> retractSeriesToLimit8way()
public GreasedRegion surface8way()
public GreasedRegion surface8way(int amount)
public GreasedRegion[] surfaceSeries8way(int amount)
public java.util.ArrayList<GreasedRegion> surfaceSeriesToLimit8way()
public GreasedRegion flood(GreasedRegion bounds)
expand()
, but limits expansion to the "on" cells of bounds
. Expands in all 4-way directions
by one cell simultaneously, and only successfully affects the cells that are adjacent to this and are in bounds.bounds
- the set of "on" cells that limits where this can expand intopublic GreasedRegion flood(GreasedRegion bounds, int amount)
expand(int)
, but limits expansion to the "on" cells of bounds
. Repeatedly expands in the
4-way directions by one cell simultaneously, and only successfully affects the cells that are adjacent to the
previous expansion and are in bounds. This won't skip over gaps in bounds, even if amount is high enough that a
call to expand(int)
would reach past the gap; it will stop at the gap and only pass it if expansion
takes it around.bounds
- the set of "on" cells that limits where this can expand intoamount
- how far to expand this outward by, in cellspublic GreasedRegion[] floodSeries(GreasedRegion bounds, int amount)
flood(GreasedRegion)
amount
times and returns the intermediate steps in a
GreasedRegion array of size amount
. Doesn't modify this GreasedRegion, and doesn't return it in the array
(it may return a copy of it if and only if no flood8way() calls can expand the area). If this fills
bounds
as fully as possible and still has steps left, the remaining steps are all copies of the
fully-filled area.bounds
- the set of "on" cells that this will attempt to fill in stepsamount
- how many steps to flood outward, and the size of the array to returnamount
in size, containing larger and larger expansions of thispublic java.util.ArrayList<GreasedRegion> floodSeriesToLimit(GreasedRegion bounds)
bounds
, until it can't expand any more. Returns an ArrayList of the
GreasedRegion steps this generated; this list does not include this GreasedRegion (or any unmodified copy of this
GreasedRegion), and this method does not modify it.bounds
- the set of "on" cells that this will attempt to fill in stepsflood(GreasedRegion)
call to possibly many chained after itpublic GreasedRegion flood8way(GreasedRegion bounds)
expand8way()
, but limits expansion to the "on" cells of bounds
. Expands in all directions
by one cell simultaneously, and only successfully affects the cells that are adjacent to this and are in bounds.bounds
- the set of "on" cells that limits where this can expand intopublic GreasedRegion flood8way(GreasedRegion bounds, int amount)
expand8way(int)
, but limits expansion to the "on" cells of bounds
. Repeatedly expands in
all directions by one cell simultaneously, and only successfully affects the cells that are adjacent to the
previous expansion and are in bounds. This won't skip over gaps in bounds, even if amount is high enough that a
call to expand8way(int)
would reach past the gap; it will stop at the gap and only pass it if expansion
takes it around.bounds
- the set of "on" cells that limits where this can expand intoamount
- how far to expand this outward by, in cellspublic GreasedRegion[] floodSeries8way(GreasedRegion bounds, int amount)
flood8way(GreasedRegion)
amount
times and returns the intermediate steps in a
GreasedRegion array of size amount
. Doesn't modify this GreasedRegion, and doesn't return it in the array
(it may return a copy of it if and only if no flood8way() calls can expand the area). If this fills
bounds
as fully as possible and still has steps left, the remaining steps are all copies of the
fully-filled area.bounds
- the set of "on" cells that this will attempt to fill in stepsamount
- how many steps to flood outward, and the size of the array to returnamount
in size, containing larger and larger expansions of thispublic java.util.ArrayList<GreasedRegion> floodSeriesToLimit8way(GreasedRegion bounds)
bounds
, until it can't expand any more. Returns an ArrayList of the
GreasedRegion steps this generated; this list does not include this GreasedRegion (or any unmodified copy of this
GreasedRegion), and this method does not modify it.bounds
- the set of "on" cells that this will attempt to fill in stepsflood8way(GreasedRegion)
call to possibly many chained after itpublic GreasedRegion spill(GreasedRegion bounds, int volume, IRNG rng)
bounds
, until size()
is equal to volume
or there are no more cells
this can expand into. This GreasedRegion acts as the initial state, and often contains just one cell before this
is called. This method is useful for imitating the movement of fluids like water or smoke within some boundaries.bounds
- this GreasedRegion will only expand to cells that are "on" in bounds; bounds should overlap with thisvolume
- the maximum size()
this GreasedRegion can reach before this stops expandingrng
- a random number generator, like RNG
or GWTRNG
public GreasedRegion removeCorners()
public java.util.ArrayList<GreasedRegion> split()
split8way()
, which considers diagonally-adjacent cells as part of one region, while this method requires
cells to be orthogonally adjacent.
GreasedRegion floors = new GreasedRegion(map, '.'),
rooms = floors.copy().retract8way().flood(floors, 2),
corridors = floors.copy().andNot(rooms),
doors = rooms.copy().and(corridors.copy().fringe());
List<GreasedRegion> apart = split(rooms);
, or
substitute split(corridors)
to get the corridors. The room-finding technique works by shrinking floors
by a radius of 1 (8-way), which causes thin areas like corridors of 2 or less width to be removed, then
flood-filling the floors out from the area that produces by 2 cells (4-way this time) to restore the original
size of non-corridor areas (plus some extra to ensure odd shapes are kept). Corridors are obtained by removing
the rooms from floors. The example code also gets the doors (which overlap with rooms, not corridors) by finding
where the a room and a corridor are adjacent. This technique is used with some enhancements in the RoomFinder
class.for a class that uses this technique without exposing GreasedRegion
public java.util.ArrayList<GreasedRegion> split8way()
split()
, which is almost identical except that split() considers only orthogonal connections, while this
method considers both orthogonal and diagonal connections between cells as joining an area.
GreasedRegion floors = new GreasedRegion(map, '.'),
rooms = floors.copy().retract8way().flood(floors, 2),
corridors = floors.copy().andNot(rooms),
doors = rooms.copy().and(corridors.copy().fringe());
List<GreasedRegion> apart = split(rooms);
, or
substitute split(corridors)
to get the corridors. The room-finding technique works by shrinking floors
by a radius of 1 (8-way), which causes thin areas like corridors of 2 or less width to be removed, then
flood-filling the floors out from the area that produces by 2 cells (4-way this time) to restore the original
size of non-corridor areas (plus some extra to ensure odd shapes are kept). Corridors are obtained by removing
the rooms from floors. The example code also gets the doors (which overlap with rooms, not corridors) by finding
where the a room and a corridor are adjacent. This technique is used with some enhancements in the RoomFinder
class.for a class that uses this technique without exposing GreasedRegion
public GreasedRegion largestPart()
nth(int)
takes).
This may return an empty GreasedRegion if there are no "on" cells, but it will never return null.
Here, contiguous means adjacent on an orthogonal direction, and this doesn't consider diagonally-connected cells
as contiguous unless they also have an orthogonal connection.public GreasedRegion largestPart8way()
nth(int)
takes).
This may return an empty GreasedRegion if there are no "on" cells, but it will never return null.
Here, contiguous means adjacent on any 8-way direction, and considers cells as part of a contiguous area even if
all connections but one, which can be orthogonal or diagonal, are blocked by "off" cells.public GreasedRegion neighborUp()
public GreasedRegion neighborDown()
public GreasedRegion neighborLeft()
public GreasedRegion neighborRight()
public GreasedRegion neighborUpLeft()
public GreasedRegion neighborUpRight()
public GreasedRegion neighborDownLeft()
public GreasedRegion neighborDownRight()
public GreasedRegion removeIsolated()
public boolean intersects(GreasedRegion other)
other
- another GreasedRegion; its size does not have to match this GreasedRegion's sizepublic static OrderedSet<GreasedRegion> whichContain(int x, int y, GreasedRegion... packed)
public static OrderedSet<GreasedRegion> whichContain(int x, int y, java.util.Collection<GreasedRegion> packed)
public static java.util.Collection<GreasedRegion> appendContaining(java.util.Collection<GreasedRegion> into, int x, int y, GreasedRegion... packed)
into
.into
- a Collection of GreasedRegion that will be modified if this succeedsx
- the x-coordinate to look upy
- the y-coordinate to look uppacked
- the array or varargs of GreasedRegion to try to look up the given position ininto
, potentially modifiedpublic static java.util.Collection<GreasedRegion> appendContaining(java.util.Collection<GreasedRegion> into, int x, int y, java.util.Collection<GreasedRegion> packed)
into
.into
- a Collection of GreasedRegion that will be modified if this succeedsx
- the x-coordinate to look upy
- the y-coordinate to look uppacked
- the Collection of GreasedRegion to try to look up the given position ininto
, potentially modifiedpublic int size()
size
in interface java.util.Collection<Coord>
size
in interface Zone
size
in class Zone.Skeleton
Zone.getAll()
).public Coord fit(double xFraction, double yFraction)
public int[][] fit(int[][] basis, int defaultValue)
public Coord[] separatedPortion(double fraction)
mixedRandomSeparated(double)
, quasiRandomSeparated(double)
,
or separatedZCurve(double)
. This method has issues with being unable to fill the requested fraction, but
the others mentioned don't. See their documentation for what all these group of methods do.fraction
- between 0.0 and 1.0public Coord[] randomSeparated(double fraction, IRNG rng)
mixedRandomSeparated(double, int, long)
with a random long as the
last parameter. This method has issues with being unable to fill the requested fraction, but mixedRandomSeparated
does not. See its documentation for what this method is supposed to do.fraction
- between 0.0 and 1.0rng
- an IRNG that will be used to get a random starting point in the Sobol sequence this uses internallypublic Coord[] randomSeparated(double fraction, IRNG rng, int limit)
mixedRandomSeparated(double, int, long)
with a random long as the
last parameter. This method has issues with being unable to fill the requested fraction, but mixedRandomSeparated
does not. See its documentation for what this method is supposed to do.fraction
- between 0.0 and 1.0rng
- an IRNG that will be used to get a random starting point in the Sobol sequence this uses internallylimit
- how many Coord values this should return, at most; typically this will return lesspublic Coord[] mixedRandomSeparated(double fraction)
fraction
of the total amount of "on" cells
in this. This is pseudo-random with a fixed seed, but is very good at avoiding overlap (just as good as
separatedRegionZCurve(double, int)
, and probably faster). If you request too many cells (too high of a
value for fraction), it will start to overlap, but a fraction value of 0.4 reliably has had no overlap in
testing. Does not restrict the size of the returned array other than only using up to
fraction * size()
cells.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0public Coord[] mixedRandomSeparated(double fraction, int limit)
fraction
of the total amount of "on" cells
in this. This is pseudo-random with a fixed seed, but is very good at avoiding overlap (just as good as
separatedRegionZCurve(double, int)
, and probably faster). If you request too many cells (too high of a
value for fraction), it will start to overlap, but a fraction value of 0.4 reliably has had no overlap in
testing. Restricts the total size of the returned array to a maximum of limit
(minimum is 0 if no cells
are "on"). If limit is negative, this will not restrict the size.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0limit
- the maximum size of the array to returnpublic Coord[] mixedRandomSeparated(double fraction, int limit, long seed)
fraction
of the total amount of "on" cells
in this. This is pseudo-random with the given seed (which will be made into an odd number if it is not one
already), and is very good at avoiding overlap (just as good as separatedZCurve(double, int)
, and
probably faster). If you request too many cells (too high of a value for fraction), it will start to overlap, but
a fraction value of 0.4 reliably has had no overlap in testing. Restricts the total size of the returned array to
a maximum of limit
(minimum is 0 if no cells are "on"). If limit is negative, this will not restrict the
size.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0limit
- the maximum size of the array to returnseed
- a long seed to change the points; the most significant 21 bits (except the sign bit) and least significant bit are ignoredpublic GreasedRegion mixedRandomRegion(double fraction)
size()
matches the given fraction
of the total amount of "on" cells
in this. This is pseudo-random with a fixed seed, and is very good at avoiding overlap (just as good as
separatedRegionZCurve(double, int)
, and probably faster). If you request too many cells (too high of a
value for fraction), it will start to overlap, but a fraction value of 0.4 reliably has had no overlap in
testing. Does not restrict the count of "on" cells after this returns other than by only using up to
fraction * size()
cells.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0public GreasedRegion mixedRandomRegion(double fraction, int limit)
size()
matches the given fraction
of the total amount of "on" cells
in this. This is pseudo-random with a fixed seed, and is very good at avoiding overlap (just as good as
separatedRegionZCurve(double, int)
, and probably faster). If you request too many cells (too high of a
value for fraction), it will start to overlap, but a fraction value of 0.4 reliably has had no overlap in
testing. Restricts the total count of "on" cells after this returns to a maximum of limit
(minimum is 0
if no cells are "on"). If limit is negative, this will not restrict the count.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0limit
- the maximum count of "on" cells to keeppublic GreasedRegion mixedRandomRegion(double fraction, int limit, long seed)
size()
matches the given fraction
of the total amount of "on" cells
in this. This is pseudo-random with the given seed (which will be made into an odd number if it is not one
already), and is very good at avoiding overlap (just as good as separatedZCurve(double, int)
, and
probably faster). If you request too many cells (too high of a value for fraction), it will start to overlap, but
a fraction value of 0.4 reliably has had no overlap in testing. Restricts the total count of "on" cells after
this returns to a maximum of limit
(minimum is 0 if no cells are "on"). If limit is negative, this will
not restrict the count.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0limit
- the maximum count of "on" cells to keeppublic Coord[] quasiRandomSeparated(double fraction)
fraction
of the total amount of "on" cells in this. This is quasi-
random instead of pseudo-random because it is somewhat less likely to produce nearby cells in the result. If you
request too many cells (too high of a value for fraction), it will start to overlap, however.
Does not restrict the size of the returned array other than only using up to fraction * size()
cells.
mixedRandomSeparated(double)
, separatedZCurve(double)
,
separatedBlue(double)
, and this method, where all are quasi-random, mixedRandom and
separatedBlue are probably fastest, ZCurve and separatedBlue may have better 2-dimensional gaps
between cells, and this method is somewhere in the middle.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0public Coord[] quasiRandomSeparated(double fraction, int limit)
fraction
of the total amount of "on" cells in this. This is quasi-
random instead of pseudo-random because it is somewhat less likely to produce nearby cells in the result. If you
request too many cells (too high of a value for fraction), it will start to overlap, however.
Restricts the total size of the returned array to a maximum of limit
(minimum is 0 if no cells are "on").
If limit is negative, this will not restrict the size.
mixedRandomSeparated(double)
, separatedZCurve(double)
,
separatedBlue(double)
, and this method, where all are quasi-random, mixedRandom and
separatedBlue are probably fastest, ZCurve and separatedBlue may have better 2-dimensional gaps
between cells, and this method is somewhere in the middle.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0limit
- the maximum size of the array to returnpublic GreasedRegion quasiRandomRegion(double fraction)
size()
matches the given fraction
of the total amount of "on" cells in this. This is quasi-
random instead of pseudo-random because it is somewhat less likely to produce nearby cells in the result. If you
request too many cells (too high of a value for fraction), it will start to overlap, however.
Does not restrict the count of "on" cells after this returns other than by only using up to
fraction * size()
cells.
mixedRandomRegion(double)
, separatedRegionZCurve(double)
,
separatedRegionBlue(double)
, and this method, where all are quasi-random, mixedRandom and
separatedRegionBlue are probably fastest, ZCurve and separatedRegionBlue may have better 2-dimensional gaps
between cells, and this method is somewhere in the middle.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0public GreasedRegion quasiRandomRegion(double fraction, int limit)
size()
matches the given fraction
of the total amount of "on" cells in this. This is quasi-
random instead of pseudo-random because it is somewhat less likely to produce nearby cells in the result. If you
request too many cells (too high of a value for fraction), it will start to overlap, however.
Restricts the total count of "on" cells after this returns to a maximum of limit
(minimum is 0 if no
cells are "on"). If limit is negative, this will not restrict the count.
mixedRandomRegion(double)
, separatedRegionZCurve(double)
,
separatedRegionBlue(double)
, and this method, where all are quasi-random, mixedRandom and
separatedRegionBlue are probably fastest, ZCurve and separatedRegionBlue may have better 2-dimensional gaps
between cells, and this method is somewhere in the middle.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0limit
- the maximum count of "on" cells to keeppublic GreasedRegion fray(double fractionKept)
retract()
, this removes the "on" cells that are 4-way-adjacent to any "off" cell, but unlike that
method it keeps a fraction of those surface cells, quasi-randomly selecting them. This can be thought of as
running surface()
on a copy of this GreasedRegion, running separatedRegionBlue(double)
on that
surface with the given fractionKept, taking the original GreasedRegion and removing its whole surface with
retract()
, then inserting the quasi-randomly-removed surface into this GreasedRegion to replace its
surface with a randomly "damaged" one.fractionKept
- the fraction between 0.0 and 1.0 of how many cells on the outer surface of this to keep "on"public GreasedRegion fray(RandomnessSource random, double fractionKept)
retract()
, this removes the "on" cells that are 4-way-adjacent to any "off" cell, but unlike that
method it keeps a fraction of those surface cells, randomly selecting them. This can be thought of as running
surface()
on a copy of this GreasedRegion, running deteriorate(RandomnessSource, double)
on
that surface with the given fractionKept, taking the original GreasedRegion and removing its whole surface with
retract()
, then inserting the randomly-removed surface into this GreasedRegion to replace its surface
with a randomly "damaged" one.public GreasedRegion randomScatter(IRNG rng, int minimumDistance)
minimumDistance
, with at least one cell as "on" if any
were "on" in this originally. Does not limit the count of "on" cells in the result.rng
- used to generate random positionsminimumDistance
- the minimum distance between "on" cells in the resultpublic GreasedRegion randomScatter(IRNG rng, int minimumDistance, int limit)
minimumDistance
, with at least one cell as "on" if any
were "on" in this originally.
Restricts the total count of "on" cells after this returns to a maximum of limit
(minimum is 0 if no
cells are "on"). If limit is negative, this will not restrict the count.rng
- used to generate random positionsminimumDistance
- the minimum distance between "on" cells in the resultlimit
- the maximum count of "on" cells to keeppublic double rateDensity()
public double rateRegularity()
public void perceptualHashQuick(long[] into, int[] working)
into
- should be a long array of length 1 or 4; the contents don't matter and this will be where output is written toworking
- should be an int array of length 64 (if into has length 1) or 256 (if into has length 4); may be null if you like garbage collectionpublic Coord[] asCoords()
public int[] asEncoded()
public int[] asTightEncoded()
public java.util.List<Coord> getAll()
public Coord first()
public int firstTight()
public Coord last()
public int lastTight()
public Coord nth(int index)
public Coord atFraction(double fraction)
public int atFractionTight(double fraction)
public Coord singleRandom(IRNG rng)
asCoords()
and call IRNG.getRandomElement(Object[])
with that array as the parameter. If you
take the asCoords() call out of consideration, getting random elements out of an array (especially a large one)
can be hundreds of times faster.public int singleRandomTight(IRNG rng)
public static int interleaveBits(int x, int y)
a b c
for x and R S T
for y and makes a number with
those bits arranged like R a S b T c
.x
- an int between 0 and 65535, inclusivey
- an int between 0 and 65535, inclusivepublic static int disperseBits(int n)
(n & 0xffff)
to obtain) and its y component is
stored in the upper 16 bits (use (n >>> 16)
to obtain). This may be useful for ordering traversals of all
points in a GreasedRegion less predictably.n
- an int that has already been interleaved, though this can really be any intx = n & 0xffff;
) and y in its upper bits (y = n >>> 16;
)public Coord nthZCurve(int index)
nth(int)
, this gets the Coord at a given index along a path through the GreasedRegion, but unlike
nth(), this traverses the path in a zig-zag pattern called the Z-Order Curve. This method is often not very fast
compared to nth(), but this different path can help if iteration needs to seem less regular while still covering
all "on" cells in the GresedRegion eventually.index
- the distance along the Z-order curve to travel, only counting "on" cells in this GreasedRegion.public int nthZCurveTight(int index)
nth(int)
, this finds a given index along a path through the GreasedRegion, but unlike nth(), this
traverses the path in a zig-zag pattern called the Z-Order Curve, and unlike nthZCurve(int)
, this does
not return a Coord and instead produces a "tight"-encoded int. This method is often not very fast compared to
nth(), but this different path can help if iteration needs to seem less regular while still covering all "on"
cells in the GreasedRegion eventually, and the tight encoding may be handy if you need to use ints.index
- the distance along the Z-order curve to travel, only counting "on" cells in this GreasedRegion.public Coord[] separatedZCurve(double fraction)
fraction
of the total amount of "on" cells in this. This is quasi-
random instead of pseudo-random because it is somewhat less likely to produce nearby cells in the result. If you
request too many cells (too high of a value for fraction), it will start to overlap, however. Contrast with
mixedRandomSeparated(double, int)
, which tends to overlap more frequently. This method seems to work
well because it chooses quasi-random points by their index in the Z-Order Curve as opposed to the simpler
approach mixedRandomSeparated uses to traverse points (which just runs through the "on" cells a column at a time,
not caring if two points are in adjacent cells as long as they are in different columns). Testing with a dungeon
layout of mostly-on cells, this method has no overlap with a fraction of 0.4, while mixedRandomSeparated has
overlap as early as 0.15 for fraction, and it only gets worse at higher values. A change to the algorithm used by
quasiRandomSeparated(double)
has it overlapping at the same rate as this method, though it should be
much faster. This method can be especially slow, since each Z-Order traversal may need to try many cells that are
outside the GreasedRegion but are on the Z-Order Curve.
Does not restrict the size of the returned array other than only using up to fraction * size()
cells.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0public Coord[] separatedZCurve(double fraction, int limit)
fraction
of the total amount of "on" cells in this. This is quasi-
random instead of pseudo-random because it is somewhat less likely to produce nearby cells in the result. If you
request too many cells (too high of a value for fraction), it will start to overlap, however. Contrast with
mixedRandomSeparated(double, int)
, which tends to overlap more frequently. This method seems to work
well because it chooses quasi-random points by their index in the Z-Order Curve as opposed to the simpler
approach mixedRandomSeparated uses to traverse points (which just runs through the "on" cells a column at a time,
not caring if two points are in adjacent cells as long as they are in different columns). Testing with a dungeon
layout of mostly-on cells, this method has no overlap with a fraction of 0.4, while mixedRandomSeparated has
overlap as early as 0.15 for fraction, and it only gets worse at higher values. A change to the algorithm used by
quasiRandomSeparated(double, int)
has it overlapping at the same rate as this method, though it should
be much faster. This method can be especially slow, since each Z-Order traversal may need to try many cells that
are outside the GreasedRegion but are on the Z-Order Curve.
Restricts the total size of the returned array to a maximum of limit
(minimum is 0 if no cells are "on").
If limit is negative, this will not restrict the size.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0limit
- the maximum size of the array to returnpublic GreasedRegion separatedRegionZCurve(double fraction)
size()
matches the given fraction
of the total amount of "on" cells in this. This is quasi-
random instead of pseudo-random because it is somewhat less likely to produce nearby cells in the result. If you
request too many cells (too high of a value for fraction), it will start to overlap, however. Contrast with
mixedRandomRegion(double)
, which tends to overlap more frequently. This method seems to work
well because it chooses quasi-random points by their index in the Z-Order Curve as opposed to the simpler
approach mixedRandomRegion uses to traverse points (which just runs through the "on" cells a column at a time,
not caring if two points are in adjacent cells as long as they are in different columns). Testing with a dungeon
layout of mostly-on cells, this method has no overlap with a fraction of 0.4, while mixedRandomRegion has
overlap as early as 0.15 for fraction, and it only gets worse at higher values. A change to the algorithm used by
quasiRandomRegion(double)
has it overlapping at the same rate as this method, though it should be much
faster. This method can be especially slow, since each Z-Order traversal may need to try many cells that are
outside the GreasedRegion but are on the Z-Order Curve.
Does not restrict the size of the returned array other than only using up to fraction * size()
cells.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0public GreasedRegion separatedRegionZCurve(double fraction, int limit)
size()
matches the given fraction
of the total amount of "on" cells in this. This is quasi-
random instead of pseudo-random because it is somewhat less likely to produce nearby cells in the result. If you
request too many cells (too high of a value for fraction), it will start to overlap, however. Contrast with
mixedRandomRegion(double, int)
, which tends to overlap more frequently. This method seems to work
well because it chooses quasi-random points by their index in the Z-Order Curve as opposed to the simpler
approach mixedRandomRegion uses to traverse points (which just runs through the "on" cells a column at a time,
not caring if two points are in adjacent cells as long as they are in different columns). Testing with a dungeon
layout of mostly-on cells, this method has no overlap with a fraction of 0.4, while mixedRandomRegion has
overlap as early as 0.15 for fraction, and it only gets worse at higher values. A change to the algorithm used by
quasiRandomRegion(double, int)
has it overlapping at the same rate as this method, though it should be
much faster. This method can be especially slow, since each Z-Order traversal may need to try many cells that
are outside the GreasedRegion but are on the Z-Order Curve.
Restricts the total size of the returned array to a maximum of limit
(minimum is 0 if no cells are "on").
If limit is negative, this will not restrict the size.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0limit
- the maximum size of the array to returnpublic Coord[] separatedBlue(double fraction)
fraction
of the total amount of "on" cells in this. This is quasi-
random instead of pseudo-random because it uses blue noise to sharply limit the likelihood of nearby points being
chosen when fraction is small. If you request too many cells (too high of a value for fraction), it will start to
have nearby cells, however. Does not restrict the size of the returned array other than only using up to
fraction * size()
cells.
separatedZCurve(double, int)
, quasiRandomSeparated(double, int)
,
mixedRandomSeparated(double, int, long)
, and separatedRegionBlue(double, int)
. Internally, this
is a thin wrapper around separatedRegionBlue(double, int)
, and won't be more efficient than that method.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0public Coord[] separatedBlue(double fraction, int limit)
fraction
of the total amount of "on" cells in this. This is quasi-
random instead of pseudo-random because it uses blue noise to sharply limit the likelihood of nearby points being
chosen when fraction is small. If you request too many cells (too high of a value for fraction), it will start to
have nearby cells, however. Restricts the total size of the returned array to a maximum of limit
(minimum
is 0 if no cells are "on"). If limit is negative, this will not restrict the size.
separatedZCurve(double, int)
, quasiRandomSeparated(double, int)
,
mixedRandomSeparated(double, int, long)
, and separatedRegionBlue(double, int)
. Internally, this
is a thin wrapper around separatedRegionBlue(double, int)
, and won't be more efficient than that method.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0limit
- the maximum size of the array to return; may return lesspublic GreasedRegion separatedRegionBlue(double fraction)
size()
matches the given fraction
of the total amount of "on" cells in this. This is quasi-
random instead of pseudo-random because it uses blue noise to sharply limit the likelihood of nearby points being
chosen when fraction is small. If you request too many cells (too high of a value for fraction), it will start to
have nearby cells, however. Does not restrict the size of the returned GreasedRegion other than only using up to
fraction * size()
cells.
separatedRegionZCurve(double, int)
, quasiRandomRegion(double, int)
,
mixedRandomRegion(double, int, long)
, and separatedBlue(double, int)
.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0public GreasedRegion separatedRegionBlue(double fraction, int limit)
size()
matches the given fraction
of the total amount of "on" cells in this. This is quasi-
random instead of pseudo-random because it uses blue noise to sharply limit the likelihood of nearby points being
chosen when fraction is small. If you request too many cells (too high of a value for fraction), it will start to
have nearby cells, however. Restricts the total size of the returned GreasedRegion to a maximum of limit
(minimum is 0 if no cells are "on"). If limit is negative, this will not restrict the size.
separatedRegionZCurve(double, int)
, quasiRandomRegion(double, int)
,
mixedRandomRegion(double, int, long)
, and separatedBlue(double, int)
.fraction
- the fraction of "on" cells to quasi-randomly select, between 0.0 and 1.0limit
- the maximum size of the array to return; may return lesspublic GreasedRegion randomRegion(IRNG rng, int size)
public boolean contains(int x, int y)
contains
in interface Zone
contains
in class Zone.Skeleton
public boolean isEmpty()
public static int[][] sum(GreasedRegion... regions)
regions
- an array or vararg of GreasedRegions; must all have the same width and heightpublic static int[][] sum(java.util.List<GreasedRegion> regions)
regions
- a List of GreasedRegions; must all have the same width and heightpublic static double[][] sumDouble(GreasedRegion... regions)
regions
- an array or vararg of GreasedRegions; must all have the same width and heightpublic static double[][] sumDouble(java.util.List<GreasedRegion> regions)
regions
- a List of GreasedRegions; must all have the same width and heightpublic static int[][] sumWeighted(GreasedRegion[] regions, int[] weights)
1, 2, 3, 4
, it can produce a number between 0 and 10 in a cell (where 10 is used when all 4
GreasedRegions have a cell "on," since 1 + 2 + 3 + 4 == 10
); if the weights are instead
1, 10, 100, 1000
, then the results can vary between 0 and 1111, where 1111 is only if all GreasedRegions
have a cell as "on." The weights array must have a length at least equal to the length of the regions array.regions
- an array of GreasedRegions; must all have the same width and heightweights
- an array of ints; must have length at least equal to regions' lengthpublic static double[][] sumWeightedDouble(GreasedRegion[] regions, double[] weights)
1, 2, 3, 4
, it can produce a number between 0 and 10 in a cell (where 10 is used when all 4
GreasedRegions have a cell "on," since 1 + 2 + 3 + 4 == 10
); if the weights are instead
1, 10, 100, 1000
, then the results can vary between 0 and 1111, where 1111 is only if all GreasedRegions
have a cell as "on." The weights array must have a length at least equal to the length of the regions array.regions
- an array of GreasedRegions; must all have the same width and heightweights
- an array of doubles; must have length at least equal to regions' lengthpublic static int[][] sumInto(int[][] existing, GreasedRegion... regions)
existing
- a non-null 2D int array that will have each cell incremented by the sum of the GreasedRegionsregions
- an array or vararg of GreasedRegions; must all have the same width and heightpublic static double[][] sumIntoDouble(double[][] existing, GreasedRegion... regions)
existing
- a non-null 2D double array that will have each cell incremented by the sum of the GreasedRegionsregions
- an array or vararg of GreasedRegions; must all have the same width and heightpublic static double[][] dijkstraScan(char[][] map, Coord... goals)
DijkstraMap
and has less features.map
- a 2D char array where '#' is a wallgoals
- an array or vararg of Coord to get the distances towardpublic static double[][] dijkstraScan8way(char[][] map, Coord... goals)
DijkstraMap
and has less features.map
- a 2D char array where '#' is a wallgoals
- an array or vararg of Coord to get the distances towardpublic static int[][] bitSum(GreasedRegion... regions)
regions
- an array or vararg of GreasedRegions; must all have the same width and heightpublic boolean equals(java.lang.Object o)
equals
in interface java.util.Collection<Coord>
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface java.util.Collection<Coord>
hashCode
in class java.lang.Object
public long hash64()
public long hash64(long seed)
CrossHash.Yolk
's algorithm(s).seed
- a seed that will determine how the hashing algorithm works; all 64 bits are used.public java.lang.String serializeToString()
public static GreasedRegion deserializeFromString(java.lang.String s)
public static GreasedRegion of(int width, int height, long... data)
serializeToString()
produces a String that happens to be a valid parameter list for this method.width
- width of the GreasedRegion to produceheight
- height of the GreasedRegion to producedata
- array or vararg of long containing the exact data, probably from an existing GreasedRegionpublic java.lang.String toCompressedString()
CoordPacker
's algorithm and data to compress this GreasedRegion in 256x128 blocks, storing the
CoordPacker-like data as chars with values from 256 to 33023 (a concept also used in LZSEncoding
),
and using ASCII semicolons to separate them or store other info (just width and height, which are given first as
16 hex digits). This finishes by running the result through LZSEncoding
, a combination which typically
gets very good compression.decompress(String)
public java.lang.StringBuilder appendPackedString(java.lang.StringBuilder packing)
packing
.
Uses CoordPacker
's algorithm and data to compress this GreasedRegion in 256x128 blocks, storing the
CoordPacker-like data as chars with values from 256 to 33023 (a concept also used in LZSEncoding
),
and using ASCII semicolons to separate them or store other info (just width and height, which are given first as
16 hex digits). This does not compress the resulting StringBuilder further, to allow external code options for
how it wants to compress the String (such as with LZSPlus.compress(String, long[])
to garble
the compressed result, or some stronger compression like LZ4, ZStd, or Zopfli).packing
- a StringBuilder that will be appended todecompress(String)
public static GreasedRegion decompress(java.lang.String compressed)
toCompressedString()
, returning a new GreasedRegion with identical
width, height, and contents to the GreasedRegion before compression. This decompresses the LZSEncoding
applied to the data, then decompresses the CoordPacker
-type Hilbert Curve RLE data to get the original
GreasedRegion back.compressed
- a String that was compressed by toCompressedString()
, without changespublic static GreasedRegion unpackString(java.lang.String packed)
appendPackedString(StringBuilder)
, returning a new GreasedRegion with
identical width, height, and contents to the GreasedRegion before packing. This unpacks the
CoordPacker
-type Hilbert Curve RLE data to get the original GreasedRegion back.packed
- a String that was packed by appendPackedString(StringBuilder)
, without changespublic boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<Coord>
public java.util.Iterator<Coord> iterator()
iterator
in interface java.lang.Iterable<Coord>
iterator
in interface java.util.Collection<Coord>
iterator
in class Zone.Skeleton
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<Coord>
public <T> T[] toArray(T[] a)
toArray
in interface java.util.Collection<Coord>
public void clear()
clear
in interface java.util.Collection<Coord>
public boolean remove(java.lang.Object o)
remove
in interface java.util.Collection<Coord>
public boolean containsAll(java.util.Collection<?> c)
containsAll
in interface java.util.Collection<Coord>
public boolean addAll(java.util.Collection<? extends Coord> c)
addAll
in interface java.util.Collection<Coord>
public boolean removeAll(java.util.Collection<?> c)
removeAll
in interface java.util.Collection<Coord>
public boolean retainAll(java.util.Collection<?> c)
retainAll
in interface java.util.Collection<Coord>
public GreasedRegion deteriorate(RandomnessSource rng, int preservation)
rng
- used to determine random factorspreservation
- roughly what degree of points to remove (higher keeps more); removes about 1/(2^preservation)
pointspublic GreasedRegion deteriorate(RandomnessSource random, double preservation)
empty()
) and then return it. The parameter random
can be an object like a
DiverRNG
, an RNG
backed by a well-distributed RandomnessSource like its default, DiverRNG, a
GWTRNG
(especially if you target GWT, where it will perform much better than most alternatives), or any
of various other RandomnessSource implementations that distribute bits well for
RandomnessSource.nextLong()
, but should not be intentionally-biased RNGs like DharmaRNG
or
EditRNG
, nor double-based QRNGs like VanDerCorputQRNG
or SobolQRNG
.public GreasedRegion toggle(int x, int y)
x
- the x position of the cell to flipy
- the y position of the cell to flippublic GreasedRegion mirrorY()
this
, that is mirrored along the rightmost edgepublic boolean intersectsWith(Zone other)
intersectsWith
in interface Zone
intersectsWith
in class Zone.Skeleton
this
and other
have a common cell.public GreasedRegion translate(Coord c)
this
by the x,y values in c
.
Implemented with return copy().translate(c.x, c.y);
translate
in interface Zone
translate
in class Zone.Skeleton
this
copied and shifted by (c.x,c.y)
public GreasedRegion getExternalBorder()
return copy().fringe8way();
.getExternalBorder
in interface Zone
getExternalBorder
in class Zone.Skeleton
this
(orthogonally or diagonally) that
aren't in this
public GreasedRegion extend()
this
plus all
neighboring Coords, which can be orthogonally or diagonally adjacent
to any Coord this has in it. Related to the expand() methods in
CoordPacker and GreasedRegion, but guaranteed to use 8-way adjacency
and to return a new Zone. This implementation returns a GreasedRegion
produced simply by return copy().expand8way();
.extend
in interface Zone
extend
in class Zone.Skeleton
this
(orthogonally or diagonally) have been added to the "on" cells
in this
public boolean contains(Coord c)
c
is present in this GreasedRegion. Returns true if and only if c is present in this
GreasedRegion as an "on" cell. This will never be true if c is null, has negative x or y, has a value for x that
is equal to or greater than width
, or has a value for y that is equal to or greater than
height
, but none of those conditions will cause Exceptions to be thrown.contains
in interface Zone
contains
in class Zone.Skeleton
c
- a Coord to try to find in this GreasedRegion; if null this will always return falsec
is an "on" cell in this GreasedRegion, or false otherwise, including if c is nullpublic boolean contains(Zone other)
other
are also present in this
.
Requires that other
won't give a null Coord while this method iterates over it.contains
in interface Zone
contains
in class Zone.Skeleton
other
- another Zone, such as a GreasedRegion or a CoordPackerZone
public int xBound(boolean smallestBound)
xBound
in interface Zone
xBound
in class Zone.Skeleton
smallestBound
- if true, finds the smallest x-coordinate value;
if false, finds the biggest.this
that has the
smallest (or biggest) x-coordinate. Or -1 if the zone is empty.public int yBound(boolean smallestBound)
yBound
in interface Zone
yBound
in class Zone.Skeleton
smallestBound
- if true, finds the smallest y-coordinate value;
if false, finds the biggest.this
that has the
smallest (or biggest) y-coordinate. Or -1 if the zone is empty.public int getWidth()
width
on a GreasedRegion! The field will get the span of the space
that the GreasedRegion can use, including "on" and "off" cells. This method will only get the distance between
the furthest-separated "on" cells on the x-axis, and won't consider "off" cells. This method can return -1 if the
GreasedRegion is empty, 0 if the "on" cells are all in a vertical line (that is, when the minimum x is equal to
the maximum x), or a positive int in other cases with multiple x-values.getWidth
in interface Zone
getWidth
in class Zone.Skeleton
public int getHeight()
height
on a GreasedRegion! The field will get the span of the space
that the GreasedRegion can use, including "on" and "off" cells. This method will only get the distance between
the furthest-separated "on" cells on the y-axis, and won't consider "off" cells. This method can return -1 if the
GreasedRegion is empty, 0 if the "on" cells are all in a horizontal line (that is, when the minimum y is equal to
the maximum y), or a positive int in other cases with multiple y-values.getHeight
in interface Zone
getHeight
in class Zone.Skeleton
public double getDiagonal()
getDiagonal
in interface Zone
getDiagonal
in class Zone.Skeleton
public GreasedRegion getInternalBorder()
getInternalBorder
in interface Zone
getInternalBorder
in class Zone.Skeleton
this
that are adjacent to a cell not in
this
public Coord[] mixedRandomSeparatedAlt(double fraction, int limit, long seed)
fraction
of the total amount of "on" cells
in this. This is pseudo-random with the given seed (which will be made into an odd number if it is not one
already), and is very good at avoiding overlap (just as good as separatedZCurve(double, int)
, and
much faster). If you request too many cells (too high of a value for fraction), it will start to overlap, but
a fraction value of 0.4 reliably has had no overlap in testing. Restricts the total size of the returned array to
a maximum of limit
(minimum is 0 if no cells are "on"). If limit is negative, this will not restrict the
size.fraction
- the fraction of "on" cells to randomly select, between 0.0 and 1.0limit
- the maximum size of the array to returnseed
- a long seed to change the points; the most significant 21 bits (except the sign bit) and least significant bit are ignoredCopyright © Eben Howard 2012–2022. All rights reserved.