public class Coord3D extends Coord
Modifier and Type | Field and Description |
---|---|
int |
z |
Constructor and Description |
---|
Coord3D(int x,
int y,
int z)
Creates a three dimensional coordinate with the given location.
|
Modifier and Type | Method and Description |
---|---|
double |
distance(Coord3D other)
Returns the linear distance between this coordinate point and the
provided one.
|
boolean |
equals(java.lang.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.
|
java.lang.String |
toString() |
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
public Coord3D(int x, int y, int z)
x
- y
- z
- public static Coord3D get(int x, int y, int z)
public double distance(Coord3D other)
other
- public double squareDistance(Coord3D other)
other
- public int manhattanDistance(Coord3D other)
other
- public int maxAxisDistance(Coord3D other)
other
- public int hashCode()
Coord
Objects.hash(Object...)
gives more than a 75% collision rate). The previous version, which is
still available as Coord.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.
OrderedSet
and OrderedMap
; 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).hashCode
in class Coord
A static method that gets the same result as this method without involving a Coord
Copyright © Eben Howard 2012–2022. All rights reserved.