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
Fields 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
-
Method Summary
Modifier and TypeMethodDescriptionclone()
double
distance
(double x, double y) Returns the distance FROM this MutableInt2D TO the specified pointdouble
Returns the distance FROM this MutableInt2D TO the specified point.double
Returns the distance FROM this MutableInt2D TO the specified point.double
Returns the distance FROM this MutableInt2D TO the specified point.double
Returns the distance FROM this MutableInt2D TO the specified point.double
distanceSq
(double x, double y) Returns the squared distance FROM this MutableInt2D TO the specified pointdouble
Returns the squared distance FROM this MutableInt2D TO the specified pointdouble
Returns the squared distance FROM this MutableInt2D TO the specified point.double
distanceSq
(Int2D p) Returns the squared distance FROM this MutableInt2D TO the specified point.double
Returns the squared distance FROM this MutableInt2D TO the specified point.final boolean
Returns whether this NumberND is equivalent to some other NumberND.double
getVal
(int val) Returns the value at position VAL in this NumberND (val should 0, 1, or sometimes 2)final int
getX()
final int
getY()
final int
hashCode()
Provides a hashcode for this NumberND.long
manhattanDistance
(int x, int y) Returns the manhattan distance FROM this MutableInt2D TO the specified point.long
Returns the manhattan distance FROM this Int2D TO the specified point.long
Returns the manhattan distance FROM this MutableInt2D TO the specified point.long
Returns the manhattan distance FROM this MutableInt2D TO the specified point.boolean
mutable()
Returns whether this NumberND is mutable.int
Returns the number of dimensions of this NumberND (normally 2 or 3)void
setLocation
(int x, int y) Deprecated.use setTovoid
setLocation
(Point p) Deprecated.use setTovoid
setLocation
(Int2D p) Deprecated.use setTovoid
Deprecated.use setTovoid
setTo
(int x, int y) void
void
void
void
setVal
(int val, double to) final void
setX
(int val) final void
setY
(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
isMutable
Methods 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:NumberND
Returns whether this NumberND is mutable. This is equivalent to asking (instanceof val MutableNumberND) -
numDimensions
public int numDimensions()Description copied from class:NumberND
Returns the number of dimensions of this NumberND (normally 2 or 3)- Specified by:
numDimensions
in classNumberND
-
getVal
public double getVal(int val) Description copied from class:NumberND
Returns 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:
setVal
in classMutableNumberND
-
toBytes
public byte[] toBytes()Description copied from class:NumberND
Flattens 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:NumberND
Returns this NumberND as a nicely formatted String. -
toCoordinates
Description copied from class:NumberND
Returns this NumberND in mathematical coordinates as a formatted String.- Specified by:
toCoordinates
in classNumberND
-
toArrayAsDouble
public double[] toArrayAsDouble()- Specified by:
toArrayAsDouble
in classNumberND
-
clone
-
hashCode
public final int hashCode()Description copied from class:NumberND
Provides a hashcode for this NumberND. -
equals
Description copied from class:NumberND
Returns 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.
-