public class GreasedZOI
extends java.lang.Object
implements java.io.Serializable
ZOI
, but should be
faster on large maps and produces much less garbage. The main reason to choose between ZOI and
GreasedZOI is whether your existing code uses GreasedRegions, like this class, or uses CoordPacker, like ZOI. If you
don't currently use either, GreasedZOI is probably preferable because the calculate()
method produces a
value that can be reasonably consumed by Collection-based APIs, while ZOI.calculate()
produces a
harder-to-use short[]
that must be read by CoordPacker. Repeated operations on CoordPacker's short[]
data will have to keep allocating more arrays and temporary internal data structures, while a GreasedRegion can be
reused many times and only rarely allocates more space.
Constructor and Description |
---|
GreasedZOI(java.util.Collection<Coord> influences,
char[][] map,
Radius radiusStrategy)
Constructs a Zone of Influence map.
|
GreasedZOI(Coord[][] influences,
char[][] map,
Radius radiusStrategy)
Constructs a Zone of Influence map.
|
GreasedZOI(Coord[] influences,
char[][] map,
Radius radiusStrategy)
Constructs a Zone of Influence map.
|
Modifier and Type | Method and Description |
---|---|
GreasedRegion[] |
calculate()
Finds the zones of influence for each of the influences (inner arrays of Coord) this was constructed with, and
returns all zones as a GreasedRegion array.
|
Coord[][] |
getInfluences()
Gets the influencing groups; ideally the result should not be changed without setting it back with setInfluences.
|
protected GreasedRegion |
increasing(double[][] dm,
Coord[] inf) |
IntVLA |
nearestInfluences(Coord point)
This can be given a Coord to check in the results of the latest calculate() call.
|
IntVLA |
nearestInfluences(GreasedRegion[] zones,
Coord point)
Given the zones resulting from this class'
calculate() method and a Coord to check, finds the indices of
all influencing groups in zones that have the Coord in their area, and returns all such indices as an IntVLA. |
void |
setInfluences(Coord[][] influences)
Changes the influencing groups.
|
public GreasedZOI(Coord[][] influences, char[][] map, Radius radiusStrategy)
calculate()
when you want information out of this.influences
- an outer array containing influencing groups, each an array containing Coords that influencemap
- a char[][] that is used as an area map; should be boundedradiusStrategy
- a Radius enum that corresponds to how distance should be measuredpublic GreasedZOI(Coord[] influences, char[][] map, Radius radiusStrategy)
calculate()
when you want information out of this.influences
- an array containing Coords that each have their own independent influencemap
- a char[][] that is used as an area map; should be boundedradiusStrategy
- a Radius enum that corresponds to how distance should be measuredPoissonDisk provides a good way to generate evenly spaced Coords
public GreasedZOI(java.util.Collection<Coord> influences, char[][] map, Radius radiusStrategy)
calculate()
when you want information out of this.influences
- A Collection of Coord, such as a GreasedRegion, where each Coord has independent influencemap
- a char[][] that is used as an area map; should be boundedradiusStrategy
- a Radius enum that corresponds to how distance should be measuredpublic GreasedRegion[] calculate()
GreasedRegion.and(GreasedRegion)
, and borders are typically between 1 and
2 cells wide. You can get a different region if you want region A without the overlapping areas it shares with
region B by using GreasedRegion.andNot(GreasedRegion)
. Merging two zones A and B can be done with
GreasedRegion.or(GreasedRegion)
. You can transform the data into a boolean[][] easily with
GreasedRegion.decode()
, where true is contained in the zone and false is not. The methods
GreasedRegion.fringe()
, GreasedRegion.expand()
, GreasedRegion.singleRandom(IRNG)
, and
GreasedRegion.separatedBlue(double)
are also potentially useful for this sort of data. You should save
the GreasedRegion[]
for later use if you want to call
nearestInfluences(GreasedRegion[], Coord)
.
protected GreasedRegion increasing(double[][] dm, Coord[] inf)
public IntVLA nearestInfluences(GreasedRegion[] zones, Coord point)
calculate()
method and a Coord to check, finds the indices of
all influencing groups in zones that have the Coord in their area, and returns all such indices as an IntVLA.zones
- a GreasedRegion[] returned by calculatepoint
- the Coord to testpublic IntVLA nearestInfluences(Coord point)
IntVLA
.
You can convert the IntVLA to an array with IntVLA.toArray()
if you want to match ZOI's behavior.point
- the Coord to testpublic Coord[][] getInfluences()
public void setInfluences(Coord[][] influences)
influences
- a jagged array of Coord arrays, where the inner arrays are groups of influencesCopyright © Eben Howard 2012–2022. All rights reserved.