FileDocCategorySizeDatePackage
Point2D.javaAPI DocJava SE 6 API11205Tue Jun 10 00:25:26 BST 2008java.awt.geom

Point2D

public abstract class Point2D extends Object implements Cloneable
The Point2D class defines a point representing a location in {@code (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.21, 02/24/06
author
Jim Graham
since
1.2

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
since
1.2

    

                                                    
      
    
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 the X coordinate of the specified point to be measured against this Point2D
param
py the Y coordinate of the specified point to be measured against this Point2D
return
the distance between this Point2D and a specified point.
since
1.2

	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 point to be measured against this Point2D
return
the distance between this Point2D and the specified Point2D.
since
1.2

	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 the X coordinate of the first specified point
param
y1 the Y coordinate of the first specified point
param
x2 the X coordinate of the second specified point
param
y2 the Y coordinate of the second specified point
return
the distance between the two sets of specified coordinates.
since
1.2

	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 the X coordinate of the first specified point
param
y1 the Y coordinate of the first specified point
param
x2 the X coordinate of the second specified point
param
y2 the Y coordinate of the second specified point
return
the square of the distance between the two sets of specified coordinates.
since
1.2

	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 the X coordinate of the specified point to be measured against this Point2D
param
py the Y coordinate of the specified point to be measured against this Point2D
return
the square of the distance between this Point2D and the specified point.
since
1.2

	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 point to be measured against this Point2D
return
the square of the distance between this Point2D to a specified Point2D.
since
1.2

	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 the new X coordinate of this {@code Point2D}
param
y the new Y coordinate of this {@code 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 to which to set this Point2D
since
1.2

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