public class ZOI
extends java.lang.Object
implements java.io.Serializable
ZOI
, but should be
slightly faster on large maps at the expense of usually using more memory. The main reason to choose between ZOI and
GreasedZOI is whether your existing code uses GreasedRegions, like GreasedZOI, or uses CoordPacker, like this class.
If you don't currently use either, GreasedZOI is probably preferable because the GreasedZOI.calculate()
method produces a value that can be reasonably consumed by Collection-based APIs, while calculate()
produces
a harder-to-use short[]
that must be read by CoordPacker; GreasedZOI is probably not significantly faster for
most applications, and the memory usage difference is probably under a megabyte.
Constructor and Description |
---|
ZOI(Coord[][] influences,
char[][] map,
Radius radiusStrategy)
Constructs a Zone of Influence map.
|
ZOI(Coord[] influences,
char[][] map,
Radius radiusStrategy)
Constructs a Zone of Influence map.
|
Modifier and Type | Method and Description |
---|---|
short[][] |
calculate()
Finds the zones of influence for each of the influences (inner arrays of Coord) this was constructed with, and
returns them as packed data (using CoordPacker, which can also be used to unpack the data, merge zones, get
shared borders, and all sorts of other tricks).
|
Coord[][] |
getInfluences()
Gets the influencing groups; ideally the result should not be changed without setting it back with setInfluences.
|
protected boolean[][] |
increasing(double[][] dm,
Coord[] inf) |
int[] |
nearestInfluences(Coord point)
This can be given a Coord to check in the results of the latest calculate() call.
|
int[] |
nearestInfluences(short[][] 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 int array.
|
void |
setInfluences(Coord[][] influences)
Changes the influencing groups.
|
public ZOI(Coord[][] influences, char[][] map, Radius radiusStrategy)
influences
- an outer array containing influencing groups, each an array containing Coords that influencemap
- a char[][] that is used as a map; should be boundedradiusStrategy
- a Radius enum that corresponds to how distance should be measuredpublic ZOI(Coord[] influences, char[][] map, Radius radiusStrategy)
influences
- an array containing Coords that each have their own independent influencemap
- a char[][] that is used as a map; should be boundedradiusStrategy
- a Radius enum that corresponds to how distance should be measuredfor a good way to generate evenly spaced Coords that can be used here
public short[][] calculate()
short[] different = CoordPacker.differencePacked(A, B)
. Merging two zones A and B
can be done with short[] merged = CoordPacker.unionPacked(A, B)
. You can unpack the data
into a boolean[][] easily with CoordPacker.unpack(), where true is contained in the zone and false is not.
The CoordPacker methods fringe(), expand(), singleRandom(), randomSample(), and randomPortion() are also
potentially useful for this sort of data. You should save the short[][] for later use if you want to call
nearestInfluences() in this class.
protected boolean[][] increasing(double[][] dm, Coord[] inf)
public int[] nearestInfluences(short[][] zones, Coord point)
zones
- a short[][] returned by calculate; not a multi-packed short[][] from CoordPacker !point
- the Coord to testpublic int[] nearestInfluences(Coord point)
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.