Package sim.util
Class Int3D
java.lang.Object
sim.util.NumberND
sim.util.Number3D
sim.util.Int3D
- All Implemented Interfaces:
Serializable
Int3D stores three values (x, y, and z) but it is immutable: once the x and y and z values are set, they cannot be changed (they're final). Like the others, Int3D is immutable primarily to prevent hash tables from breaking.
One day in the far future, Int3D should also be HIGHLY efficient; since it is immutable, it can be passed by value rather than by pointer by a smart compiler. Not today, though. But it's not bad.
This class has an elaborate hash code generation that is much more random than Sun's standard generator, but takes more time. For very large numbers of objects, this is a good idea, but we may change it to a simpler version in the future.
Int3D.equals(...) can compare by value against other Int3Ds, MutableInt2Ds, and Double3Ds.
- See Also:
-
Field Summary
FieldsFields inherited from class sim.util.NumberND
TYPE_DOUBLE_2D, TYPE_DOUBLE_3D, TYPE_INT_2D, TYPE_INT_3D, TYPE_MUTABLE_DOUBLE_2D, TYPE_MUTABLE_DOUBLE_3D, TYPE_MUTABLE_INT_2D, TYPE_MUTABLE_INT_3D -
Constructor Summary
ConstructorsConstructorDescriptionInt3D()Int3D(int x, int y, int z) Explicitly assumes the z value is set to 0Int3D(MutableInt2D p, int z) -
Method Summary
Modifier and TypeMethodDescriptionadd(double dx, double dy, double dz) add(int dx, int dy, int dz) doubledistance(double x, double y, double z) Returns the distance FROM this Int3D TO the specified pointdoubleReturns the distance FROM this Int3D TO the specified point.doubleReturns the distance FROM this Int3D TO the specified point.doubleReturns the distance FROM this Int3D TO the specified point.doubledistanceSq(double x, double y, double z) Returns the squared distance FROM this Int3D TO the specified pointdoubleReturns the squared distance FROM this Int3D TO the specified point.doubledistanceSq(Int3D p) Returns the squared distance FROM this Int3D TO the specified point.doubleReturns the squared distance FROM this Int3D TO the specified point.booleanReturns whether this NumberND is equivalent to some other NumberND.doublegetVal(int val) Returns the value at position VAL in this NumberND (val should 0, 1, or sometimes 2)final intgetX()final intgetY()final intgetZ()inthashCode()Provides a hashcode for this NumberND.longmanhattanDistance(int x, int y, int z) Returns the manhattan distance FROM this Int3D TO the specified point.longReturns the manhattan distance FROM this Int3D TO the specified point.longReturns the manhattan distance FROM this Int3D TO the specified point.intReturns the number of dimensions of this NumberND (normally 2 or 3)double[]byte[]toBytes()Flattens out the NumberND to an array of bytes, including the NumberND subtype.Returns this NumberND in mathematical coordinates as a formatted String.toString()Returns this NumberND as a nicely formatted String.Methods inherited from class sim.util.NumberND
doubleFromBytes, doubleToBytes, fromBytes, getDistanceSq, getOffsets, intFromBytes, intToBytes, main, mutable
-
Field Details
-
x
public final int x -
y
public final int y -
z
public final int z
-
-
Constructor Details
-
Int3D
public Int3D() -
Int3D
public Int3D(int x, int y, int z) -
Int3D
Explicitly assumes the z value is set to 0 -
Int3D
-
Int3D
-
Int3D
-
-
Method Details
-
numDimensions
public int numDimensions()Description copied from class:NumberNDReturns the number of dimensions of this NumberND (normally 2 or 3)- Specified by:
numDimensionsin classNumberND
-
getVal
public double getVal(int val) Description copied from class:NumberNDReturns the value at position VAL in this NumberND (val should 0, 1, or sometimes 2) -
toBytes
public byte[] toBytes()Description copied from class:NumberNDFlattens out the NumberND to an array of bytes, including the NumberND subtype. -
getX
public final int getX() -
getY
public final int getY() -
getZ
public final int getZ() -
toString
Description copied from class:NumberNDReturns this NumberND as a nicely formatted String. -
toCoordinates
Description copied from class:NumberNDReturns this NumberND in mathematical coordinates as a formatted String.- Specified by:
toCoordinatesin classNumberND
-
toArrayAsDouble
public double[] toArrayAsDouble()- Specified by:
toArrayAsDoublein classNumberND
-
hashCode
public int hashCode()Description copied from class:NumberNDProvides a hashcode for this NumberND. -
equals
Description copied from class:NumberNDReturns whether this NumberND is equivalent to some other NumberND. -
distance
public double distance(double x, double y, double z) Returns the distance FROM this Int3D TO the specified point -
distance
Returns the distance FROM this Int3D TO the specified point. -
distance
Returns the distance FROM this Int3D TO the specified point. -
distance
Returns the distance FROM this Int3D TO the specified point. -
distanceSq
public double distanceSq(double x, double y, double z) Returns the squared distance FROM this Int3D TO the specified point -
distanceSq
Returns the squared distance FROM this Int3D TO the specified point. -
distanceSq
Returns the squared distance FROM this Int3D TO the specified point. -
distanceSq
Returns the squared distance FROM this Int3D TO the specified point. -
manhattanDistance
public long manhattanDistance(int x, int y, int z) Returns the manhattan distance FROM this Int3D TO the specified point. -
manhattanDistance
Returns the manhattan distance FROM this Int3D TO the specified point. -
manhattanDistance
Returns the manhattan distance FROM this Int3D TO the specified point. -
add
-
add
-
add
-
subtract
-
add
-
subtract
-