Package sim.util

Class MutableInt2D

All Implemented Interfaces:
Serializable, Cloneable

public class MutableInt2D extends MutableNumberND
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 Details

    • x

      public int x
    • y

      public int y
  • Constructor Details

    • MutableInt2D

      public MutableInt2D()
    • MutableInt2D

      public MutableInt2D(Point p)
    • MutableInt2D

      public MutableInt2D(Int2D p)
    • 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)
      Overrides:
      mutable in class NumberND
    • 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 class NumberND
    • 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)
      Specified by:
      getVal in class NumberND
    • setVal

      public void setVal(int val, double to)
      Specified by:
      setVal in class MutableNumberND
    • toBytes

      public byte[] toBytes()
      Description copied from class: NumberND
      Flattens out the NumberND to an array of bytes, including the NumberND subtype.
      Specified by:
      toBytes in class NumberND
    • 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

      public void setTo(Point p)
    • setTo

      public void setTo(Int2D p)
    • setTo

      public void setTo(MutableInt2D p)
    • setLocation

      public void setLocation(int x, int y)
      Deprecated.
      use setTo
    • setLocation

      public void setLocation(Point p)
      Deprecated.
      use setTo
    • setLocation

      public void setLocation(Int2D p)
      Deprecated.
      use setTo
    • setLocation

      public void setLocation(MutableInt2D p)
      Deprecated.
      use setTo
    • toPoint2D

      public Point2D.Double toPoint2D()
    • toPoint

      public Point toPoint()
    • toString

      public String toString()
      Description copied from class: NumberND
      Returns this NumberND as a nicely formatted String.
      Specified by:
      toString in class NumberND
    • toCoordinates

      public String toCoordinates()
      Description copied from class: NumberND
      Returns this NumberND in mathematical coordinates as a formatted String.
      Specified by:
      toCoordinates in class NumberND
    • toArrayAsDouble

      public double[] toArrayAsDouble()
      Specified by:
      toArrayAsDouble in class NumberND
    • clone

      public Object clone()
      Overrides:
      clone in class Object
    • hashCode

      public final int hashCode()
      Description copied from class: NumberND
      Provides a hashcode for this NumberND.
      Specified by:
      hashCode in class NumberND
    • equals

      public final boolean equals(Object obj)
      Description copied from class: NumberND
      Returns whether this NumberND is equivalent to some other NumberND.
      Specified by:
      equals in class NumberND
    • distance

      public double distance(double x, double y)
      Returns the distance FROM this MutableInt2D TO the specified point
    • distance

      public double distance(Double2D p)
      Returns the distance FROM this MutableInt2D TO the specified point.
    • distance

      public double distance(MutableInt2D p)
      Returns the distance FROM this MutableInt2D TO the specified point.
    • distance

      public double distance(Int2D p)
      Returns the distance FROM this MutableInt2D TO the specified point.
    • distance

      public double distance(Point2D p)
      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

      public double distanceSq(Double2D p)
      Returns the squared distance FROM this MutableInt2D TO the specified point.
    • distanceSq

      public double distanceSq(Point2D p)
      Returns the squared distance FROM this MutableInt2D TO the specified point
    • distanceSq

      public double distanceSq(MutableInt2D p)
      Returns the squared distance FROM this MutableInt2D TO the specified point.
    • distanceSq

      public double distanceSq(Int2D p)
      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

      public long manhattanDistance(MutableInt2D p)
      Returns the manhattan distance FROM this MutableInt2D TO the specified point.
    • manhattanDistance

      public long manhattanDistance(Int2D p)
      Returns the manhattan distance FROM this MutableInt2D TO the specified point.
    • manhattanDistance

      public long manhattanDistance(Point p)
      Returns the manhattan distance FROM this Int2D TO the specified point.