Package squidpony.squidmath
Class Coord3D
java.lang.Object
squidpony.squidmath.Coord
squidpony.squidmath.Coord3D
- All Implemented Interfaces:
Serializable
public class Coord3D extends Coord
Generic three dimensional coordinate class.
Not cached in a pool because it is rarely used internally.
- Author:
- Lewis Potter, Eben Howard - http://squidpony.com - howard@squidpony.com
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description int
z
-
Constructor Summary
Constructors Constructor Description Coord3D(int x, int y, int z)
Creates a three dimensional coordinate with the given location. -
Method Summary
Modifier and Type Method Description double
distance(Coord3D other)
Returns the linear distance between this coordinate point and the provided one.boolean
equals(Object o)
static Coord3D
get(int x, int y, int z)
int
hashCode()
Gets the hash code for this Coord; does not use the standard "auto-complete" style of hash that most IDEs will generate, but instead uses a highly-specific technique based on the Rosenberg-Strong pairing function, a Gray code, and two XLCG steps at the end.int
manhattanDistance(Coord3D other)
Returns the Manhattan distance between this point and the provided one.int
maxAxisDistance(Coord3D other)
Returns the largest difference between the two points along any one axis.double
squareDistance(Coord3D other)
Returns the square of the linear distance between this coordinate point and the provided one.String
toString()
Methods inherited from class squidpony.squidmath.Coord
add, add, add, average, cantorHashCode, decode, degrees, distance, distance, distanceSq, distanceSq, divide, divide, divide, divideRounding, encode, expandPool, expandPoolTo, get, getCacheHeight, getCacheWidth, getLocation, getX, getY, interpolate, isAdjacent, isWithin, isWithinRectangle, makeEven, makeOdd, multiply, multiply, multiply, pureEncode, rosenbergStrongHashCode, scale, scale, setX, setY, subtract, subtract, subtract, toGoTo, translate, translate, translateCapped, xoroHashCode
-
Field Details
-
Constructor Details
-
Coord3D
Creates a three dimensional coordinate with the given location.- Parameters:
x
-y
-z
-
-
-
Method Details
-
get
-
distance
Returns the linear distance between this coordinate point and the provided one.- Parameters:
other
-- Returns:
-
squareDistance
Returns the square of the linear distance between this coordinate point and the provided one.- Parameters:
other
-- Returns:
-
manhattanDistance
Returns the Manhattan distance between this point and the provided one. The Manhattan distance is the distance between each point on each separate axis all added together.- Parameters:
other
-- Returns:
-
maxAxisDistance
Returns the largest difference between the two points along any one axis.- Parameters:
other
-- Returns:
-
hashCode
Description copied from class:Coord
Gets the hash code for this Coord; does not use the standard "auto-complete" style of hash that most IDEs will generate, but instead uses a highly-specific technique based on the Rosenberg-Strong pairing function, a Gray code, and two XLCG steps at the end. It manages to get extremely low collision rates under many circumstances, and very frequently manages to avoid colliding on more than 25% of Coords (making the load factor of most hash-based collections fine at a default of 0.75) while often having 0 collisions with some data sets. It does much better when Coords are in the default pooled range of -3 or greater.
This gets slightly better collision rates than previous versions used by SquidLib, around 4% across a wide variety of rectangular areas (most earlier hashes got about-5%-range collision rates, and usingObjects.hash(Object...)
gives more than a 75% collision rate). The previous version, which is still available asCoord.cantorHashCode(int, int)
, has slightly better results when used for seeding procedural generation based on a Coord (a reasonable usage of this method), but both this hash code and the Cantor-based one have excellent randomness in the upper bits of the hash (so if you use a hashCode() result as a whole int, then it should be pretty good as a seed). The method before the Cantor-based one,Coord.xoroHashCode(int, int)
was structured a little like xoroshiro (XoRoRNG
uses the 64-bit version of xoroshiro), and while it had pretty low collision rates (low 5% range), its hash codes changed bits in large checkerboard patterns, leaving heavy square-shaped biases in generated results.
This changed at least 7 times in SquidLib's history. In general, you shouldn't rely on hashCodes to stay the same across platforms and versions, whether for the JDK or this library. SquidLib (tries to) never depend on the unpredictable ordering of some hash-based collections like HashSet and HashMap, instead using its ownOrderedSet
andOrderedMap
; if you use the ordered kinds, then the only things that matter about this hash code are that it's fast (it's fast enough), it's cross-platform compatible (this version avoids using long values, which are slow on GWT, and is carefully written to behave the same on GWT as desktop) and that it doesn't collide often (which is now much more accurate than in earlier versions of this method).- Overrides:
hashCode
in classCoord
- Returns:
- an int that should, for most different Coord values, be significantly different from the other hash codes
- See Also:
A static method that gets the same result as this method without involving a Coord
-
equals
-
toString
-