FileDocCategorySizeDatePackage
Point2D.javaAPI DocJava SE 5 API10442Fri Aug 26 14:56:52 BST 2005java.awt.geom

Point2D

public abstract class Point2D extends Object implements Cloneable
The Point2D class defines a point representing a location in (x, y) coordinate space.

This class is only the abstract superclass for all objects that store a 2D coordinate. The actual storage representation of the coordinates is left to the subclass.

version
1.18, 12/19/03
author
Jim Graham

Fields Summary
Constructors Summary
protected Point2D()
This is an abstract class that cannot be instantiated directly. Type-specific implementation subclasses are available for instantiation and provide a number of formats for storing the information necessary to satisfy the various accessor methods below.

see
java.awt.geom.Point2D.Float
see
java.awt.geom.Point2D.Double
see
java.awt.Point

    
Methods Summary
public java.lang.Objectclone()
Creates a new object of the same class and with the same contents as this object.

return
a clone of this instance.
exception
OutOfMemoryError if there is not enough memory.
see
java.lang.Cloneable
since
1.2

	try {
	    return super.clone();
	} catch (CloneNotSupportedException e) {
	    // this shouldn't happen, since we are Cloneable
	    throw new InternalError();
	}
    
public doubledistance(double PX, double PY)
Returns the distance from this Point2D to a specified point.

param
PX, PY the coordinates of the specified Point2D
return
the distance between this Point2D and a specified point.

	PX -= getX();
	PY -= getY();
	return Math.sqrt(PX * PX + PY * PY);
    
public doubledistance(java.awt.geom.Point2D pt)
Returns the distance from this Point2D to a specified Point2D.

param
pt the specified Point2D
return
the distance between this Point2D and the specified Point2D.

	double PX = pt.getX() - this.getX();
	double PY = pt.getY() - this.getY();
	return Math.sqrt(PX * PX + PY * PY);
    
public static doubledistance(double X1, double Y1, double X2, double Y2)
Returns the distance between two points.

param
X1, Y1 the coordinates of the first point
param
X2, Y2 the coordinates of the second point
return
the distance between the two sets of specified coordinates.

	X1 -= X2;
	Y1 -= Y2;
	return Math.sqrt(X1 * X1 + Y1 * Y1);
    
public static doubledistanceSq(double X1, double Y1, double X2, double Y2)
Returns the square of the distance between two points.

param
X1, Y1 the coordinates of the first point
param
X2, Y2 the coordinates of the second point
return
the square of the distance between the two sets of specified coordinates.

	X1 -= X2;
	Y1 -= Y2;
	return (X1 * X1 + Y1 * Y1);
    
public doubledistanceSq(double PX, double PY)
Returns the square of the distance from this Point2D to a specified point.

param
PX, PY the coordinates of the other point
return
the square of the distance between this Point2D and the specified point.

	PX -= getX();
	PY -= getY();
	return (PX * PX + PY * PY);
    
public doubledistanceSq(java.awt.geom.Point2D pt)
Returns the square of the distance from this Point2D to a specified Point2D.

param
pt the specified Point2D
return
the square of the distance between this Point2D to a specified Point2D.

	double PX = pt.getX() - this.getX();
	double PY = pt.getY() - this.getY();
	return (PX * PX + PY * PY);
    
public booleanequals(java.lang.Object obj)
Determines whether or not two points are equal. Two instances of Point2D are equal if the values of their x and y member fields, representing their position in the coordinate space, are the same.

param
obj an object to be compared with this Point2D
return
true if the object to be compared is an instance of Point2D and has the same values; false otherwise.
since
1.2

	if (obj instanceof Point2D) {
	    Point2D p2d = (Point2D) obj;
	    return (getX() == p2d.getX()) && (getY() == p2d.getY());
	}
	return super.equals(obj);
    
public abstract doublegetX()
Returns the X coordinate of this Point2D in double precision.

return
the X coordinate of this Point2D.
since
1.2

public abstract doublegetY()
Returns the Y coordinate of this Point2D in double precision.

return
the Y coordinate of this Point2D.
since
1.2

public inthashCode()
Returns the hashcode for this Point2D.

return
a hash code for this Point2D.

	long bits = java.lang.Double.doubleToLongBits(getX());
	bits ^= java.lang.Double.doubleToLongBits(getY()) * 31;
	return (((int) bits) ^ ((int) (bits >> 32)));
    
public abstract voidsetLocation(double x, double y)
Sets the location of this Point2D to the specified double coordinates.

param
x, y the coordinates of this Point2D
since
1.2

public voidsetLocation(java.awt.geom.Point2D p)
Sets the location of this Point2D to the same coordinates as the specified Point2D object.

param
p the specified Point2D the which to set this Point2D
since
1.2

	setLocation(p.getX(), p.getY());