Class AreaUtils

java.lang.Object
com.github.yellowstonegames.path.technique.AreaUtils

public class AreaUtils extends Object
Static utilities for use in AOE and anything else that might need CoordFloatOrderedMaps.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.github.yellowstonegames.grid.CoordFloatOrderedMap
    arrayToMap(boolean[][] map)
    This takes a 2D boolean array and returns a CoordFloatOrderedMap, but will only use the value 1.0, and only for positions in map that have as their boolean element true.
    static com.github.yellowstonegames.grid.CoordFloatOrderedMap
    arrayToMap(float[][] map)
    This takes a 2D float array called map and returns a CoordFloatOrderedMap, and will have a key for every position in map that is greater than 0.0, with values equal to those in map.
    static com.github.yellowstonegames.grid.CoordFloatOrderedMap
    arrayToMap(float[][] map, float cutoff)
    This takes a 2D float array and returns a CoordFloatOrderedMap, but will only use the value 1.0, and only does this if the passed float[][] has a value at that position that is greater than cutoff.
    static com.github.yellowstonegames.grid.CoordFloatOrderedMap
    collectionToMap(Collection<com.github.yellowstonegames.grid.Coord> coll)
    This takes a Collection of Coord, such as a Region, and returns a CoordFloatOrderedMap, but will only use the value 1.0, and only for positions in coll.
    static com.github.yellowstonegames.grid.CoordFloatOrderedMap
    dijkstraToHashMap(float[][] map)
    This takes a DijkstraMap that has already completed a scan() and returns a CoordFloatOrderedMap, and will have a key for every position that was reached in the DijkstraMap, with 1.0 as the only value.
    static boolean
    verifyLimit(AimLimit limit, com.github.yellowstonegames.grid.Coord origin, com.github.yellowstonegames.grid.Coord end)
    Checks that the given end Coord can be targeted from the given origin Coord given the directional targeting rules specified by limit.
    static boolean
    verifyReach(Reach reach, com.github.yellowstonegames.grid.Coord origin, com.github.yellowstonegames.grid.Coord end)
    Checks that the given end Coord can be targeted from the given origin Coord given the complete targeting rules specified by reach.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AreaUtils

      public AreaUtils()
  • Method Details

    • arrayToMap

      public static com.github.yellowstonegames.grid.CoordFloatOrderedMap arrayToMap(boolean[][] map)
      This takes a 2D boolean array and returns a CoordFloatOrderedMap, but will only use the value 1.0, and only for positions in map that have as their boolean element true.
      Parameters:
      map - width by height
      Returns:
      a CoordFloatOrderedMap, but the only value used is 1.0
    • collectionToMap

      public static com.github.yellowstonegames.grid.CoordFloatOrderedMap collectionToMap(Collection<com.github.yellowstonegames.grid.Coord> coll)
      This takes a Collection of Coord, such as a Region, and returns a CoordFloatOrderedMap, but will only use the value 1.0, and only for positions in coll.
      Parameters:
      coll - any Collection of Coord, such as a Region
      Returns:
      a CoordFloatOrderedMap, but the only value used is 1.0
    • arrayToMap

      public static com.github.yellowstonegames.grid.CoordFloatOrderedMap arrayToMap(float[][] map)
      This takes a 2D float array called map and returns a CoordFloatOrderedMap, and will have a key for every position in map that is greater than 0.0, with values equal to those in map.
      Parameters:
      map - width by height, commonly generated by FOV methods
      Returns:
      a CoordFloatOrderedMap, with values all greater than 0.0
    • arrayToMap

      public static com.github.yellowstonegames.grid.CoordFloatOrderedMap arrayToMap(float[][] map, float cutoff)
      This takes a 2D float array and returns a CoordFloatOrderedMap, but will only use the value 1.0, and only does this if the passed float[][] has a value at that position that is greater than cutoff. For example, a cutoff of 0.3 will make all elements in the 2D array that are 0.3 or less be ignored and not put into the map, but all elements that are greater than 0.3 will be placed in as 1.0.
      Parameters:
      map - width by height, commonly generated by FOV methods
      cutoff - any elements greater than this will be 1.0 in the return, anything else will be ignored
      Returns:
      a CoordFloatOrderedMap, but the only value used is 1.0
    • dijkstraToHashMap

      public static com.github.yellowstonegames.grid.CoordFloatOrderedMap dijkstraToHashMap(float[][] map)
      This takes a DijkstraMap that has already completed a scan() and returns a CoordFloatOrderedMap, and will have a key for every position that was reached in the DijkstraMap, with 1.0 as the only value.
      Parameters:
      map - a float[][] returned by a DijkstraMap running its scan()
      Returns:
      a CoordFloatOrderedMap, with values of 1.0 only
    • verifyLimit

      public static boolean verifyLimit(AimLimit limit, com.github.yellowstonegames.grid.Coord origin, com.github.yellowstonegames.grid.Coord end)
      Checks that the given end Coord can be targeted from the given origin Coord given the directional targeting rules specified by limit. If any of the arguments are null, returns true (it assumes that any limits are not valid and don't restrict anything). The following AimLimit enum values for limit have the following meanings:
      • AimLimit.FREE makes no restrictions; it is equivalent here to passing null for limit.
      • AimLimit.EIGHT_WAY will only consider Points to be valid targets if they are along a straight line with an angle that is a multiple of 45 degrees, relative to the positive x axis. Essentially, this limits the points to those a queen could move to in chess.
      • AimLimit.ORTHOGONAL will cause the AOE to only consider Points to be valid targets if they are along a straight line with an angle that is a multiple of 90 degrees, relative to the positive x axis. Essentially, this limits the points to those a rook could move to in chess.
      • AimLimit.DIAGONAL will cause the AOE to only consider Points to be valid targets if they are along a straight line with an angle that is 45 degrees greater than a multiple of 90 degrees, relative to the positive x axis. Essentially, this limits the points to those a bishop could move to in chess.
      Parameters:
      limit - an AimLimit enum that restricts valid points unless it is AimLimit.FREE or null
      origin - where the user is
      end - where the point we want to verify is
      Returns:
      true if the point is a valid target or if the limits are invalid (non-restricting), false otherwise
    • verifyReach

      public static boolean verifyReach(Reach reach, com.github.yellowstonegames.grid.Coord origin, com.github.yellowstonegames.grid.Coord end)
      Checks that the given end Coord can be targeted from the given origin Coord given the complete targeting rules specified by reach. If any of the arguments are null, returns true (it assumes that any limits are not valid and don't restrict anything). If reach.limit is null, it treats it as equivalent to AimLimit.FREE. Otherwise, it uses the metric, minDistance, and maxDistance from reach to calculate if end is target-able from origin assuming an unobstructed playing field.
      Parameters:
      reach - a Reach object that, if non-null, gives limits for how targeting can proceed.
      origin - where the user is
      end - where the point we want to verify is
      Returns:
      true if the point is a valid target or if the limits are invalid (non-restricting), false otherwise