Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## sim.util
Class Int2D

    java.lang.Object
      sim.util.Int2D

All Implemented Interfaces:
  java.io.Serializable

    public final class Int2D

extends java.lang.Object
implements java.io.Serializable

Int2D is more or less the same class as java.awt.Point, but it is immutable: once the x and y values are set, they cannot be changed (they're final). Why use this immutable class when you could just use Point? Because Point is broken with respect to hash tables. You use Point as a key in a hash table at your own peril. Try this: hash an object by a Point as key. Then change the x value of the original Point. Ta-da! The object is lost in the hash table.

One day in the far future, Int2D 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.

Int2D.equals(...) can compare by value against other Int2Ds, MutableInt2Ds, Double2Ds, and MutableDouble2Ds.

See Also:
  Serialized Form

Field Summary
`int` | `x`
`int` | `y`

Constructor Summary
`Int2D()`
`Int2D(int x, int y)`
`Int2D(MutableInt2D p)`
`Int2D(java.awt.Point p)`

Method Summary
`double` | `distance(Double2D p)` Returns the distance FROM this MutableInt2D TO the specified point.
`double` | `distance(double x, double y)` Returns the distance FROM this MutableInt2D TO the specified point
`double` | `distance(Int2D p)` Returns the distance FROM this MutableInt2D TO the specified point.
`double` | `distance(MutableInt2D p)` Returns the distance FROM this MutableInt2D TO the specified point.
`double` | `distance(java.awt.geom.Point2D p)` Returns the distance FROM this MutableInt2D TO the specified point.
`double` | `distanceSq(Double2D p)` Returns the squared distance FROM this MutableInt2D TO the specified point.
`double` | `distanceSq(double x, double y)` 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` | `distanceSq(MutableInt2D p)` Returns the squared distance FROM this MutableInt2D TO the specified point.
`double` | `distanceSq(java.awt.geom.Point2D p)` Returns the squared distance FROM this MutableInt2D TO the specified point
`boolean` | `equals(java.lang.Object obj)`
`int` | `getX()`
`int` | `getY()`
`int` | `hashCode()`
`long` | `manhattanDistance(Int2D p)` Returns the manhattan distance FROM this MutableInt2D TO the specified point.
`long` | `manhattanDistance(int x, int y)` Returns the manhattan distance FROM this MutableInt2D TO the specified point.
`long` | `manhattanDistance(MutableInt2D p)` Returns the manhattan distance FROM this MutableInt2D TO the specified point.
`java.lang.String` | `toCoordinates()`
`java.awt.Point` | `toPoint()`
`java.lang.String` | `toString()`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### x

    public final int x

### y

    public final int y

Constructor Detail

### Int2D

    public Int2D()

### Int2D

    public Int2D(java.awt.Point p)

### Int2D

    public Int2D(MutableInt2D p)

### Int2D

    public Int2D(int x,
                 int y)

Method Detail

### getX

    public final int getX()

### getY

    public final int getY()

### toPoint

    public final java.awt.Point toPoint()

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

### toCoordinates

    public java.lang.String toCoordinates()

### hashCode

    public final int hashCode()

  Overrides:
    `hashCode` in class `java.lang.Object`

### equals

    public final boolean equals(java.lang.Object obj)

  Overrides:
    `equals` in class `java.lang.Object`

### 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(java.awt.geom.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(java.awt.geom.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.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD