|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsim.util.Double2D
Double2D is more or less the same class as java.awt.geom.Point2D.Double, 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 Point2D? Because Point2D is broken with respect to hash tables. You use Point2D as a key in a hash table at your own peril. Try this: hash an object by a Point2D as key. Then change the x value of the original Point2D. Ta-da! The object is lost in the hash table.
One day in the far future, Double3D 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.
Double2D.equals(...) can compare by value against other Int2Ds and Double2Ds.
Field Summary | |
double |
x
|
double |
y
|
Constructor Summary | |
Double2D()
|
|
Double2D(double x,
double y)
|
|
Double2D(Int2D p)
|
|
Double2D(MutableDouble2D p)
|
|
Double2D(MutableInt2D p)
|
|
Double2D(java.awt.Point p)
|
|
Double2D(java.awt.geom.Point2D.Double p)
|
|
Double2D(java.awt.geom.Point2D.Float p)
|
|
Double2D(java.awt.geom.Point2D p)
Only included for completeness' sakes, in case a new Point2D subclass is created in the future. |
Method Summary | |
double |
distance(Double2D p)
Returns the distance FROM this Double2D TO the specified point. |
double |
distance(double x,
double y)
Returns the distance FROM this Double2D TO the specified point |
double |
distance(Int2D p)
Returns the distance FROM this Double2D TO the specified point. |
double |
distance(MutableInt2D p)
Returns the distance FROM this Double2D TO the specified point. |
double |
distance(java.awt.geom.Point2D p)
Returns the distance FROM this Double2D TO the specified point. |
double |
distanceSq(Double2D p)
Returns the distance FROM this Double2D TO the specified point. |
double |
distanceSq(double x,
double y)
Returns the distance FROM this Double2D TO the specified point |
double |
distanceSq(Int2D p)
Returns the distance FROM this Double2D TO the specified point. |
double |
distanceSq(MutableInt2D p)
Returns the distance FROM this Double2D TO the specified point. |
double |
distanceSq(java.awt.geom.Point2D p)
Returns the distance FROM this Double2D TO the specified point |
boolean |
equals(Double2D other)
|
boolean |
equals(Int2D other)
|
boolean |
equals(MutableDouble2D other)
|
boolean |
equals(MutableInt2D other)
|
boolean |
equals(java.lang.Object other)
|
double |
getX()
|
double |
getY()
|
int |
hashCode()
|
java.lang.String |
toCoordinates()
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public final double x
public final double y
Constructor Detail |
public Double2D()
public Double2D(Int2D p)
public Double2D(MutableInt2D p)
public Double2D(MutableDouble2D p)
public Double2D(java.awt.Point p)
public Double2D(java.awt.geom.Point2D.Double p)
public Double2D(java.awt.geom.Point2D.Float p)
public Double2D(java.awt.geom.Point2D p)
public Double2D(double x, double y)
Method Detail |
public final double getX()
public final double getY()
public java.lang.String toString()
public java.lang.String toCoordinates()
public final int hashCode()
public final boolean equals(Double2D other)
public final boolean equals(MutableDouble2D other)
public final boolean equals(Int2D other)
public final boolean equals(MutableInt2D other)
public boolean equals(java.lang.Object other)
public double distance(double x, double y)
public double distance(Double2D p)
public double distance(Int2D p)
public double distance(MutableInt2D p)
public double distance(java.awt.geom.Point2D p)
public double distanceSq(double x, double y)
public double distanceSq(Double2D p)
public double distanceSq(Int2D p)
public double distanceSq(MutableInt2D p)
public double distanceSq(java.awt.geom.Point2D p)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |