Enum Radius

java.lang.Object
java.lang.Enum<Radius>
squidpony.squidgrid.Radius
All Implemented Interfaces:
Serializable, Comparable<Radius>, Constable

public enum Radius
extends Enum<Radius>
Basic radius strategy implementations likely to be used for roguelikes.
Author:
Eben Howard - http://squidpony.com - howard@squidpony.com
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants 
    Enum Constant Description
    CIRCLE
    In an unobstructed area the FOV would be a circle.
    CUBE
    In an unobstructed area the FOV would be a cube.
    DIAMOND
    In an unobstructed area the FOV would be a diamond.
    OCTAHEDRON
    In an unobstructed area the FOV would be a octahedron.
    ROUGH_CIRCLE
    Like CIRCLE, but always uses a rough approximation of distance instead of a more expensive (but more accurate) Euclidean calculation.
    SPHERE
    In an unobstructed area the FOV would be a sphere.
    SQUARE
    In an unobstructed area the FOV would be a square.
  • Method Summary

    Modifier and Type Method Description
    boolean equals2D​(Radius other)
    Compares two Radius enums as if they are both in a 2D plane; that is, Radius.SPHERE is treated as equal to Radius.CIRCLE, Radius.CUBE is equal to Radius.SQUARE, and Radius.OCTAHEDRON is equal to Radius.DIAMOND.
    OrderedSet<Coord> expand​(int distance, int width, int height, Iterable<Coord> points)
    Given an Iterable of Coord (such as a List or Set), a distance to expand outward by (using this Radius), and the bounding height and width of the map, gets a "thickened" group of Coord as a Set where each Coord in points has been expanded out by an amount no greater than distance.
    Coord extend​(Coord center, Coord middle, int radiusLength, boolean surpassEdges, int width, int height)  
    static List<Coord> inCircle​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height)
    Gets a List of all Coord points within radiusLength of center using Euclidean measurement (making a circle).
    static List<Coord> inCircle​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height, List<Coord> buf)
    Gets a List of all Coord points within radiusLength of center using Euclidean measurement (making a circle).
    static List<Coord> inDiamond​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height)
    Gets a List of all Coord points within radiusLength of center using Manhattan measurement (making a diamond).
    static List<Coord> inDiamond​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height, List<Coord> buf)
    Gets a List of all Coord points within radiusLength of center using Manhattan measurement (making a diamond).
    boolean inRange​(int startx, int starty, int endx, int endy, int minRange, int maxRange)  
    static List<Coord> inSquare​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height)
    Gets a List of all Coord points within radiusLength of center using Chebyshev measurement (making a square).
    static List<Coord> inSquare​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height, List<Coord> buf)
    Gets a List of all Coord points within radiusLength of center using Chebyshev measurement (making a square).
    Measurement matchingMeasurement()
    Gets the appropriate Measurement to pass to a constructor if you already have a Radius.
    Coord onUnitShape​(double distance, IRNG rng)  
    Coord3D onUnitShape3D​(double distance, IRNG rng)  
    OrderedSet<Coord> perimeter​(Coord center, int radiusLength, boolean surpassEdges, int width, int height)  
    List<Coord> pointsInside​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height)  
    List<Coord> pointsInside​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height, List<Coord> buf)  
    List<Coord> pointsInside​(Coord center, int radiusLength, boolean surpassEdges, int width, int height)  
    double radius​(double dx, double dy)  
    double radius​(double dx, double dy, double dz)  
    double radius​(double startx, double starty, double endx, double endy)  
    double radius​(double startx, double starty, double startz, double endx, double endy, double endz)  
    double radius​(int dx, int dy)  
    double radius​(int dx, int dy, int dz)  
    double radius​(int startx, int starty, int endx, int endy)  
    double radius​(int startx, int starty, int startz, int endx, int endy, int endz)  
    double radius​(Coord end)  
    double radius​(Coord start, Coord end)  
    int roughDistance​(int xPos, int yPos)  
    static Radius valueOf​(String name)
    Returns the enum constant of this type with the specified name.
    static Radius[] values()
    Returns an array containing the constants of this enum type, in the order they are declared.
    double volume2D​(double radiusLength)  
    double volume3D​(double radiusLength)  

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • SQUARE

      public static final Radius SQUARE
      In an unobstructed area the FOV would be a square. This is the shape that would represent movement radius in an 8-way movement scheme with no additional cost for diagonal movement.
    • DIAMOND

      public static final Radius DIAMOND
      In an unobstructed area the FOV would be a diamond. This is the shape that would represent movement radius in a 4-way movement scheme.
    • CIRCLE

      public static final Radius CIRCLE
      In an unobstructed area the FOV would be a circle. This is the shape that would represent movement radius in an 8-way movement scheme with all movement cost the same based on distance from the source
    • CUBE

      public static final Radius CUBE
      In an unobstructed area the FOV would be a cube. This is the shape that would represent movement radius in an 8-way movement scheme with no additional cost for diagonal movement.
    • OCTAHEDRON

      public static final Radius OCTAHEDRON
      In an unobstructed area the FOV would be a octahedron. This is the shape that would represent movement radius in a 4-way movement scheme.
    • SPHERE

      public static final Radius SPHERE
      In an unobstructed area the FOV would be a sphere. This is the shape that would represent movement radius in an 8-way movement scheme with all movement cost the same based on distance from the source
    • ROUGH_CIRCLE

      public static final Radius ROUGH_CIRCLE
      Like CIRCLE, but always uses a rough approximation of distance instead of a more expensive (but more accurate) Euclidean calculation.
  • Method Details

    • values

      public static Radius[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static Radius valueOf​(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • radius

      public double radius​(int startx, int starty, int startz, int endx, int endy, int endz)
    • radius

      public double radius​(double startx, double starty, double startz, double endx, double endy, double endz)
    • radius

      public double radius​(int dx, int dy, int dz)
    • radius

      public double radius​(double dx, double dy, double dz)
    • radius

      public double radius​(int startx, int starty, int endx, int endy)
    • radius

      public double radius​(Coord start, Coord end)
    • radius

      public double radius​(Coord end)
    • radius

      public double radius​(double startx, double starty, double endx, double endy)
    • radius

      public double radius​(int dx, int dy)
    • radius

      public double radius​(double dx, double dy)
    • onUnitShape

      public Coord onUnitShape​(double distance, IRNG rng)
    • onUnitShape3D

      public Coord3D onUnitShape3D​(double distance, IRNG rng)
    • volume2D

      public double volume2D​(double radiusLength)
    • volume3D

      public double volume3D​(double radiusLength)
    • perimeter

      public OrderedSet<Coord> perimeter​(Coord center, int radiusLength, boolean surpassEdges, int width, int height)
    • extend

      public Coord extend​(Coord center, Coord middle, int radiusLength, boolean surpassEdges, int width, int height)
    • equals2D

      public boolean equals2D​(Radius other)
      Compares two Radius enums as if they are both in a 2D plane; that is, Radius.SPHERE is treated as equal to Radius.CIRCLE, Radius.CUBE is equal to Radius.SQUARE, and Radius.OCTAHEDRON is equal to Radius.DIAMOND.
      Parameters:
      other - the Radius to compare this to
      Returns:
      true if the 2D versions of both Radius enums are the same shape.
    • inRange

      public boolean inRange​(int startx, int starty, int endx, int endy, int minRange, int maxRange)
    • roughDistance

      public int roughDistance​(int xPos, int yPos)
    • pointsInside

      public List<Coord> pointsInside​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height)
    • pointsInside

      public List<Coord> pointsInside​(Coord center, int radiusLength, boolean surpassEdges, int width, int height)
    • pointsInside

      public List<Coord> pointsInside​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height, List<Coord> buf)
    • inSquare

      public static List<Coord> inSquare​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height)
      Gets a List of all Coord points within radiusLength of center using Chebyshev measurement (making a square). Appends Coords to buf if it is non-null, and returns either buf or a freshly-allocated List of Coord. If surpassEdges is false, which is the normal usage, this will not produce Coords with x or y less than 0 or greater than width or height; if surpassEdges is true, then it can produce any Coords in the actual radius.
      Parameters:
      centerX - the center Coord x
      centerY - the center Coord x
      radiusLength - the inclusive distance from (centerX,centerY) for Coords to use in the List
      surpassEdges - usually should be false; if true, can produce Coords with negative x/y or past width/height
      width - the width of the area this can place Coords (exclusive, not relative to center, usually map width)
      height - the height of the area this can place Coords (exclusive, not relative to center, usually map height)
      Returns:
      a new List containing the points within radiusLength of the center
    • inDiamond

      public static List<Coord> inDiamond​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height)
      Gets a List of all Coord points within radiusLength of center using Manhattan measurement (making a diamond). Appends Coords to buf if it is non-null, and returns either buf or a freshly-allocated List of Coord. If surpassEdges is false, which is the normal usage, this will not produce Coords with x or y less than 0 or greater than width or height; if surpassEdges is true, then it can produce any Coords in the actual radius.
      Parameters:
      centerX - the center Coord x
      centerY - the center Coord x
      radiusLength - the inclusive distance from (centerX,centerY) for Coords to use in the List
      surpassEdges - usually should be false; if true, can produce Coords with negative x/y or past width/height
      width - the width of the area this can place Coords (exclusive, not relative to center, usually map width)
      height - the height of the area this can place Coords (exclusive, not relative to center, usually map height)
      Returns:
      a new List containing the points within radiusLength of the center
    • inCircle

      public static List<Coord> inCircle​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height)
      Gets a List of all Coord points within radiusLength of center using Euclidean measurement (making a circle). Appends Coords to buf if it is non-null, and returns either buf or a freshly-allocated List of Coord. If surpassEdges is false, which is the normal usage, this will not produce Coords with x or y less than 0 or greater than width or height; if surpassEdges is true, then it can produce any Coords in the actual radius.
      Parameters:
      centerX - the center Coord x
      centerY - the center Coord x
      radiusLength - the inclusive distance from (centerX,centerY) for Coords to use in the List
      surpassEdges - usually should be false; if true, can produce Coords with negative x/y or past width/height
      width - the width of the area this can place Coords (exclusive, not relative to center, usually map width)
      height - the height of the area this can place Coords (exclusive, not relative to center, usually map height)
      Returns:
      a new List containing the points within radiusLength of the center
    • inSquare

      public static List<Coord> inSquare​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height, List<Coord> buf)
      Gets a List of all Coord points within radiusLength of center using Chebyshev measurement (making a square). Appends Coords to buf if it is non-null, and returns either buf or a freshly-allocated List of Coord. If surpassEdges is false, which is the normal usage, this will not produce Coords with x or y less than 0 or greater than width or height; if surpassEdges is true, then it can produce any Coords in the actual radius.
      Parameters:
      centerX - the center Coord x
      centerY - the center Coord x
      radiusLength - the inclusive distance from (centerX,centerY) for Coords to use in the List
      surpassEdges - usually should be false; if true, can produce Coords with negative x/y or past width/height
      width - the width of the area this can place Coords (exclusive, not relative to center, usually map width)
      height - the height of the area this can place Coords (exclusive, not relative to center, usually map height)
      buf - the List of Coord to append points to; may be null to create a new List
      Returns:
      buf, after appending Coords to it, or a new List if buf was null
    • inDiamond

      public static List<Coord> inDiamond​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height, List<Coord> buf)
      Gets a List of all Coord points within radiusLength of center using Manhattan measurement (making a diamond). Appends Coords to buf if it is non-null, and returns either buf or a freshly-allocated List of Coord. If surpassEdges is false, which is the normal usage, this will not produce Coords with x or y less than 0 or greater than width or height; if surpassEdges is true, then it can produce any Coords in the actual radius.
      Parameters:
      centerX - the center Coord x
      centerY - the center Coord x
      radiusLength - the inclusive distance from (centerX,centerY) for Coords to use in the List
      surpassEdges - usually should be false; if true, can produce Coords with negative x/y or past width/height
      width - the width of the area this can place Coords (exclusive, not relative to center, usually map width)
      height - the height of the area this can place Coords (exclusive, not relative to center, usually map height)
      buf - the List of Coord to append points to; may be null to create a new List
      Returns:
      buf, after appending Coords to it, or a new List if buf was null
    • inCircle

      public static List<Coord> inCircle​(int centerX, int centerY, int radiusLength, boolean surpassEdges, int width, int height, List<Coord> buf)
      Gets a List of all Coord points within radiusLength of center using Euclidean measurement (making a circle). Appends Coords to buf if it is non-null, and returns either buf or a freshly-allocated List of Coord. If surpassEdges is false, which is the normal usage, this will not produce Coords with x or y less than 0 or greater than width or height; if surpassEdges is true, then it can produce any Coords in the actual radius.
      Parameters:
      centerX - the center Coord x
      centerY - the center Coord x
      radiusLength - the inclusive distance from (centerX,centerY) for Coords to use in the List
      surpassEdges - usually should be false; if true, can produce Coords with negative x/y or past width/height
      width - the width of the area this can place Coords (exclusive, not relative to center, usually map width)
      height - the height of the area this can place Coords (exclusive, not relative to center, usually map height)
      buf - the List of Coord to append points to; may be null to create a new List
      Returns:
      buf, after appending Coords to it, or a new List if buf was null
    • expand

      public OrderedSet<Coord> expand​(int distance, int width, int height, Iterable<Coord> points)
      Given an Iterable of Coord (such as a List or Set), a distance to expand outward by (using this Radius), and the bounding height and width of the map, gets a "thickened" group of Coord as a Set where each Coord in points has been expanded out by an amount no greater than distance. As an example, you could call this on a line generated by Bresenham, OrthoLine, or an LOS object's getLastPath() method, and expand the line into a thick "brush stroke" where this Radius affects the shape of the ends. This will never produce a Coord with negative x or y, a Coord with x greater than or equal to width, or a Coord with y greater than or equal to height.
      Parameters:
      distance - the distance, as measured by this Radius, to expand each Coord on points up to
      width - the bounding width of the map (exclusive)
      height - the bounding height of the map (exclusive)
      points - an Iterable (such as a List or Set) of Coord that this will make a "thickened" version of
      Returns:
      a Set of Coord that covers a wider area than what points covers; each Coord will be unique (it's a Set)
    • matchingMeasurement

      Gets the appropriate Measurement to pass to a constructor if you already have a Radius. Matches SQUARE or CUBE to CHEBYSHEV, DIAMOND or OCTAHEDRON to MANHATTAN, and CIRCLE or SPHERE to EUCLIDEAN.
      Returns:
      a Measurement that matches this; SQUARE to CHEBYSHEV, DIAMOND to MANHATTAN, etc.
      See Also:
      an equivalent method in Measurement, a method to do the inverse of this and get a Radius from a Measurement