Package sim.util
Class MutableInt2D
java.lang.Object
sim.util.NumberND
sim.util.MutableNumberND
sim.util.MutableInt2D
- All Implemented Interfaces:
Serializable,Cloneable
MutableInt2D is largely a class identical to java.awt.Point, except that it is hash-equivalent to Int2D.
It is used internally in SparseGrid2D and Continuous2D to do neighborhood lookups without having to
create an Int2D every time (which causes lots of garbage collection).
You use MutableInt2D as a STORED hash key at your peril: it has the same misfeature as Point, and you should read the warning in Int2D. However, you can look up Int2D-keyed objects in a hash table by passing in a MutableInt2D instead.
- 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()doubledistance(double x, double y) Returns the distance FROM this MutableInt2D TO the specified pointdoubleReturns the distance FROM this MutableInt2D TO the specified point.doubleReturns the distance FROM this MutableInt2D TO the specified point.doubleReturns the distance FROM this MutableInt2D TO the specified point.doubleReturns the distance FROM this MutableInt2D TO the specified point.doubledistanceSq(double x, double y) Returns the squared distance FROM this MutableInt2D TO the specified pointdoubleReturns the squared distance FROM this MutableInt2D TO the specified pointdoubleReturns the squared distance FROM this MutableInt2D TO the specified point.doubledistanceSq(Int2D p) Returns the squared distance FROM this MutableInt2D TO the specified point.doubleReturns the squared distance FROM this MutableInt2D TO the specified point.final 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 inthashCode()Provides a hashcode for this NumberND.longmanhattanDistance(int x, int y) Returns the manhattan distance FROM this MutableInt2D TO the specified point.longReturns the manhattan distance FROM this Int2D TO the specified point.longReturns the manhattan distance FROM this MutableInt2D TO the specified point.longReturns the manhattan distance FROM this MutableInt2D TO the specified point.booleanmutable()Returns whether this NumberND is mutable.intReturns the number of dimensions of this NumberND (normally 2 or 3)voidsetLocation(int x, int y) Deprecated.use setTovoidsetLocation(Point p) Deprecated.use setTovoidsetLocation(Int2D p) Deprecated.use setTovoidDeprecated.use setTovoidsetTo(int x, int y) voidvoidvoidvoidsetVal(int val, double to) final voidsetX(int val) final voidsetY(int val) 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.toPoint()toString()Returns this NumberND as a nicely formatted String.Methods inherited from class sim.util.MutableNumberND
isMutableMethods inherited from class sim.util.NumberND
doubleFromBytes, doubleToBytes, fromBytes, getDistanceSq, getOffsets, intFromBytes, intToBytes, main
-
Field Details
-
x
public int x -
y
public int y
-
-
Constructor Details
-
MutableInt2D
public MutableInt2D() -
MutableInt2D
-
MutableInt2D
-
MutableInt2D
public MutableInt2D(int x, int y) -
MutableInt2D
public MutableInt2D(int[] vals)
-
-
Method Details
-
mutable
public boolean mutable()Description copied from class:NumberNDReturns whether this NumberND is mutable. This is equivalent to asking (instanceof val MutableNumberND) -
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) -
setVal
public void setVal(int val, double to) - Specified by:
setValin classMutableNumberND
-
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() -
setX
public final void setX(int val) -
setY
public final void setY(int val) -
setTo
public void setTo(int x, int y) -
setTo
-
setTo
-
setTo
-
setLocation
public void setLocation(int x, int y) Deprecated.use setTo -
setLocation
Deprecated.use setTo -
setLocation
Deprecated.use setTo -
setLocation
Deprecated.use setTo -
toPoint2D
-
toPoint
-
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
-
clone
-
hashCode
public final 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) Returns the distance FROM this MutableInt2D TO the specified point -
distance
Returns the distance FROM this MutableInt2D TO the specified point. -
distance
Returns the distance FROM this MutableInt2D TO the specified point. -
distance
Returns the distance FROM this MutableInt2D TO the specified point. -
distance
Returns the distance FROM this MutableInt2D TO the specified point. -
distanceSq
public double distanceSq(double x, double y) Returns the squared distance FROM this MutableInt2D TO the specified point -
distanceSq
Returns the squared distance FROM this MutableInt2D TO the specified point. -
distanceSq
Returns the squared distance FROM this MutableInt2D TO the specified point -
distanceSq
Returns the squared distance FROM this MutableInt2D TO the specified point. -
distanceSq
Returns the squared distance FROM this MutableInt2D TO the specified point. -
manhattanDistance
public long manhattanDistance(int x, int y) Returns the manhattan distance FROM this MutableInt2D TO the specified point. -
manhattanDistance
Returns the manhattan distance FROM this MutableInt2D TO the specified point. -
manhattanDistance
Returns the manhattan distance FROM this MutableInt2D TO the specified point. -
manhattanDistance
Returns the manhattan distance FROM this Int2D TO the specified point.
-