|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.hermit.geometry.Point
public class Point
An immutable point in the plane. This immutable class represents a point as an X and Y co-ordinate.
Field Summary | |
---|---|
static Point |
INFINITE
A constant representing a point at infinity. |
static Point |
UNKNOWN
A constant representing an unknown point (the 2-D equivalent of NaN). |
static int |
X_INDEX
Index value which specifies the X co-ordinate within a point. |
static int |
Y_INDEX
Index value which specifies the Y co-ordinate within a point. |
Constructor Summary | |
---|---|
Point(double x,
double y)
Create a Point from individual co-ordinates. |
Method Summary | |
---|---|
int |
compareTo(Point o)
Compares this object with the specified object for order. |
double |
dist(Point o)
Calculate the distance between this point and another. |
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one. |
double |
getComponent(int i)
Get the specified co-ordinate of this point. |
double |
getX()
Get the X co-ordinate of this point. |
float |
getXf()
Get the X co-ordinate of this point as a float. |
double |
getY()
Get the Y co-ordinate of this point. |
float |
getYf()
Get the Y co-ordinate of this point as a float. |
int |
hashCode()
Returns a hash code value for the object. |
boolean |
isInfinite()
Determine whether this point is infinite. |
boolean |
isNaN()
Determine whether this point is NaN. |
static Point |
mid(Point a,
Point b)
Calculate the midpoint between two points. |
java.lang.String |
toString()
Convert this instance to a String suitable for display. |
static Vector |
vector(Point a,
Point b)
Calculate the Vector between two points. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Point INFINITE
public static final Point UNKNOWN
public static final int X_INDEX
getComponent(int)
,
Constant Field Valuespublic static final int Y_INDEX
getComponent(int)
,
Constant Field ValuesConstructor Detail |
---|
public Point(double x, double y)
x
- The X co-ordinate.y
- The Y co-ordinate.Method Detail |
---|
public boolean isInfinite()
public boolean isNaN()
public double getX()
public double getY()
public double getComponent(int i) throws java.lang.IllegalArgumentException
i
- Index of the desired co-ordinate; either
X_INDEX
or Y_INDEX
.
java.lang.IllegalArgumentException
- Bad index.public float getXf()
public float getYf()
public double dist(Point o)
o
- The other point.
public static Vector vector(Point a, Point b)
a
- The starting point.b
- The ending point.
public static Point mid(Point a, Point b)
a
- One point.b
- The other point.
public boolean equals(java.lang.Object obj)
This method simply compares the co-ordinates of the two points, with a limited precision.
Note that the precision of the test is limited by the precision
set in MathTools.setPrecision(double)
. That is, only as
many fractional digits are compared as configured there; hence,
two very close points will be considered equal.
equals
in class java.lang.Object
obj
- The reference object with which to compare.
public int compareTo(Point o)
This method compares the co-ordinates of the two points, with a limited precision. The Y co-ordinate is given precedence; that is, the smaller Y will be considered less than the larger Y. If the Y values are equal to within the configured precision, then the X values are compared.
Note that the precision of the test is limited by the precision
set in MathTools.setPrecision(double)
. That is, only as
many fractional digits are compared as configured there; hence,
two very close points will be considered equal.
compareTo
in interface java.lang.Comparable<Point>
o
- The object to be compared to this one.
java.lang.ClassCastException
- The specified object's type prevents it
from being compared to this object.public int hashCode()
The hash code returned here is based on the co-ordinates of this
Point, and is designed to be different for different points.
The least significant bits of the co-ordinates are not compared,
in line with the precision set in
MathTools.setPrecision(double)
. Hence, this method should
be consistent with equals() and compareTo().
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |