Package squidpony.squidgrid
Enum Measurement
- All Implemented Interfaces:
Serializable
,Comparable<Measurement>
,Constable
public enum Measurement extends Enum<Measurement>
A way of measuring what cells are adjacent and how much further any adjacent cells are from other adjacent cells.
In practice, this is used for pathfinding first and foremost, with some other code using this to fill nearby cells in
some way. You will usually want to use either
MANHATTAN
through an entire codebase when only moves in
cardinal directions are allowed, EUCLIDEAN
when you want some things to look circular instead of always
diamond-shaped as with MANHATTAN (this allows diagonal movement for pathfinders only if it is the best option), or
maybe CHEBYSHEV
if you consider using EUCLIDEAN for pathfinding (CHEBYSHEV allows cardinal and diagonal
movement with equal cost, but this permits pathfinders to make very strange choices).-
Nested Class Summary
-
Enum Constant Summary
-
Method Summary
Modifier and Type Method Description int
directionCount()
double
heuristic(Direction target)
static Measurement
matchingMeasurement(Radius radius)
Gets the appropriate Measurement that matches a Radius enum.Radius
matchingRadius()
Gets the appropriate Radius corresponding to a Measurement.static Measurement
valueOf(String name)
Returns the enum constant of this type with the specified name.static Measurement[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
MANHATTAN
The distance it takes when only the four primary directions can be moved in. The default. -
CHEBYSHEV
The distance it takes when diagonal movement costs the same as cardinal movement. -
EUCLIDEAN
The distance it takes as the crow flies. This will NOT affect movement cost when calculating a path, only the preferred squares to travel to (resulting in drastically more reasonable-looking paths).
-
-
Method Details
-
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
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 nameNullPointerException
- if the argument is null
-
heuristic
-
directionCount
-
matchingMeasurement
Gets the appropriate Measurement that matches a Radius enum. Matches SQUARE or CUBE to CHEBYSHEV, DIAMOND or OCTAHEDRON to MANHATTAN, and CIRCLE or SPHERE to EUCLIDEAN.- Parameters:
radius
- the Radius to find the corresponding Measurement for- Returns:
- a Measurement that matches radius; SQUARE to CHEBYSHEV, DIAMOND to MANHATTAN, etc.
-
matchingRadius
Gets the appropriate Radius corresponding to a Measurement. Matches CHEBYSHEV to SQUARE, MANHATTAN to DIAMOND, and EUCLIDEAN to CIRCLE.- Returns:
- a Radius enum that matches this Measurement; CHEBYSHEV to SQUARE, MANHATTAN to DIAMOND, etc.
-