APIdia Launch Partner
Top Description Inners Constructors Methods
java.awt.geom

public abstract Class Point2D

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Known Direct Subclasses
java.awt.geom.Point2D.Float, java.awt.geom.Point2D.Double, java.awt.Point
Imports
java.io.Serial, .Serializable

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.

Author
Jim Graham
Since
1.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Point2D.Double

The Double class defines a point specified in double precision.

public static class
Point2D.Float

The Float class defines a point specified in float precision.

Constructor Summary

AccessConstructor and Description
protected
Point2D()

This is an abstract class that cannot be instantiated directly.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

a clone of this instance.
clone
()

Overrides java.lang.Object.clone.

Creates a new object of the same class and with the same contents as this object.

public static double

Returns:

the distance between the two sets of specified coordinates.
distance
(double
the X coordinate of the first specified point
x1
,
double
the Y coordinate of the first specified point
y1
,
double
the X coordinate of the second specified point
x2
,
double
the Y coordinate of the second specified point
y2
)

Returns the distance between two points.

public double

Returns:

the distance between this Point2D and a specified point.
distance
(double
the X coordinate of the specified point to be measured against this Point2D
px
,
double
the Y coordinate of the specified point to be measured against this Point2D
py
)

Returns the distance from this Point2D to a specified point.

public double

Returns:

the distance between this Point2D and the specified Point2D.
distance
(Point2D
the specified point to be measured against this Point2D
pt
)

Returns the distance from this Point2D to a specified Point2D.

public static double

Returns:

the square of the distance between the two sets of specified coordinates.
distanceSq
(double
the X coordinate of the first specified point
x1
,
double
the Y coordinate of the first specified point
y1
,
double
the X coordinate of the second specified point
x2
,
double
the Y coordinate of the second specified point
y2
)

Returns the square of the distance between two points.

public double

Returns:

the square of the distance between this Point2D and the specified point.
distanceSq
(double
the X coordinate of the specified point to be measured against this Point2D
px
,
double
the Y coordinate of the specified point to be measured against this Point2D
py
)

Returns the square of the distance from this Point2D to a specified point.

public double

Returns:

the square of the distance between this Point2D to a specified Point2D.
distanceSq
(Point2D
the specified point to be measured against this Point2D
pt
)

Returns the square of the distance from this Point2D to a specified Point2D.

public boolean

Returns:

true if the object to be compared is an instance of Point2D and has the same values; false otherwise.
equals
(Object
an object to be compared with this Point2D
obj
)

Overrides java.lang.Object.equals.

Determines whether or not two points are equal.

public abstract double

Returns:

the X coordinate of this Point2D.
getX
()

Returns the X coordinate of this Point2D in double precision.

public abstract double

Returns:

the Y coordinate of this Point2D.
getY
()

Returns the Y coordinate of this Point2D in double precision.

public int

Returns:

a hash code for this Point2D.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns the hashcode for this Point2D.

public abstract void
setLocation(double
the new X coordinate of this Point2D
x
,
double
the new Y coordinate of this Point2D
y
)

Sets the location of this Point2D to the specified double coordinates.

public void
setLocation(Point2D
the specified Point2D to which to set this Point2D
p
)

Sets the location of this Point2D to the same coordinates as the specified Point2D object.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Point2Dback to 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.

Since
1.2
See Also
java.awt.geom.Point2D.Float, java.awt.geom.Point2D.Double, java.awt.Point

Method Detail

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Creates a new object of the same class and with the same contents as this object.

Returns:Object

a clone of this instance.

Exceptions
OutOfMemoryError:
if there is not enough memory.
Since
1.2
See Also
java.lang.Cloneable
distanceback to summary
public static double distance(double x1, double y1, double x2, double y2)

Returns the distance between two points.

Parameters
x1:double

the X coordinate of the first specified point

y1:double

the Y coordinate of the first specified point

x2:double

the X coordinate of the second specified point

y2:double

the Y coordinate of the second specified point

Returns:double

the distance between the two sets of specified coordinates.

Since
1.2
distanceback to summary
public double distance(double px, double py)

Returns the distance from this Point2D to a specified point.

Parameters
px:double

the X coordinate of the specified point to be measured against this Point2D

py:double

the Y coordinate of the specified point to be measured against this Point2D

Returns:double

the distance between this Point2D and a specified point.

Since
1.2
distanceback to summary
public double distance(Point2D pt)

Returns the distance from this Point2D to a specified Point2D.

Parameters
pt:Point2D

the specified point to be measured against this Point2D

Returns:double

the distance between this Point2D and the specified Point2D.

Since
1.2
distanceSqback to summary
public static double distanceSq(double x1, double y1, double x2, double y2)

Returns the square of the distance between two points.

Parameters
x1:double

the X coordinate of the first specified point

y1:double

the Y coordinate of the first specified point

x2:double

the X coordinate of the second specified point

y2:double

the Y coordinate of the second specified point

Returns:double

the square of the distance between the two sets of specified coordinates.

Since
1.2
distanceSqback to summary
public double distanceSq(double px, double py)

Returns the square of the distance from this Point2D to a specified point.

Parameters
px:double

the X coordinate of the specified point to be measured against this Point2D

py:double

the Y coordinate of the specified point to be measured against this Point2D

Returns:double

the square of the distance between this Point2D and the specified point.

Since
1.2
distanceSqback to summary
public double distanceSq(Point2D pt)

Returns the square of the distance from this Point2D to a specified Point2D.

Parameters
pt:Point2D

the specified point to be measured against this Point2D

Returns:double

the square of the distance between this Point2D to a specified Point2D.

Since
1.2
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

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.

Parameters
obj:Object

an object to be compared with this Point2D

Returns:boolean

true if the object to be compared is an instance of Point2D and has the same values; false otherwise.

Since
1.2
getXback to summary
public abstract double getX()

Returns the X coordinate of this Point2D in double precision.

Returns:double

the X coordinate of this Point2D.

Since
1.2
getYback to summary
public abstract double getY()

Returns the Y coordinate of this Point2D in double precision.

Returns:double

the Y coordinate of this Point2D.

Since
1.2
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns the hashcode for this Point2D.

Returns:int

a hash code for this Point2D.

setLocationback to summary
public abstract void setLocation(double x, double y)

Sets the location of this Point2D to the specified double coordinates.

Parameters
x:double

the new X coordinate of this Point2D

y:double

the new Y coordinate of this Point2D

Since
1.2
setLocationback to summary
public void setLocation(Point2D p)

Sets the location of this Point2D to the same coordinates as the specified Point2D object.

Parameters
p:Point2D

the specified Point2D to which to set this Point2D

Since
1.2
java.awt.geom back to summary

public Class Point2D.Double

extends Point2D
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

The Double class defines a point specified in double precision.
Since
1.2

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Use serialVersionUID from JDK 1.6 for interoperability.

public double
x

The X coordinate of this Point2D.

public double
y

The Y coordinate of this Point2D.

Constructor Summary

AccessConstructor and Description
public
Double()

Constructs and initializes a Point2D with coordinates (0, 0).

public
Double(double
the X coordinate of the newly constructed Point2D
x
,
double
the Y coordinate of the newly constructed Point2D
y
)

Constructs and initializes a Point2D with the specified coordinates.

Method Summary

Modifier and TypeMethod and Description
public double
getX()

Implements abstract java.awt.geom.Point2D.getX.

Returns the X coordinate of this Point2D in double precision.

public double
getY()

Implements abstract java.awt.geom.Point2D.getY.

Returns the Y coordinate of this Point2D in double precision.

public void
setLocation(double x, double y)

Implements abstract java.awt.geom.Point2D.setLocation.

Sets the location of this Point2D to the specified double coordinates.

public String

Returns:

a string representation of this Point2D.
toString
()

Overrides java.lang.Object.toString.

Returns a String that represents the value of this Point2D.

Inherited from java.awt.geom.Point2D:
clonedistancedistancedistancedistanceSqdistanceSqdistanceSqequalshashCodesetLocation

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Use serialVersionUID from JDK 1.6 for interoperability.

Annotations
@Serial
xback to summary
public double x

The X coordinate of this Point2D.

Since
1.2
yback to summary
public double y

The Y coordinate of this Point2D.

Since
1.2

Constructor Detail

Doubleback to summary
public Double()

Constructs and initializes a Point2D with coordinates (0, 0).

Since
1.2
Doubleback to summary
public Double(double x, double y)

Constructs and initializes a Point2D with the specified coordinates.

Parameters
x:double

the X coordinate of the newly constructed Point2D

y:double

the Y coordinate of the newly constructed Point2D

Since
1.2

Method Detail

getXback to summary
public double getX()

Implements abstract java.awt.geom.Point2D.getX.

Doc from java.awt.geom.Point2D.getX.

Returns the X coordinate of this Point2D in double precision.

Since
1.2
getYback to summary
public double getY()

Implements abstract java.awt.geom.Point2D.getY.

Doc from java.awt.geom.Point2D.getY.

Returns the Y coordinate of this Point2D in double precision.

Since
1.2
setLocationback to summary
public void setLocation(double x, double y)

Implements abstract java.awt.geom.Point2D.setLocation.

Doc from java.awt.geom.Point2D.setLocation.

Sets the location of this Point2D to the specified double coordinates.

Since
1.2
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a String that represents the value of this Point2D.

Returns:String

a string representation of this Point2D.

Since
1.2
java.awt.geom back to summary

public Class Point2D.Float

extends Point2D
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

The Float class defines a point specified in float precision.
Since
1.2

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Use serialVersionUID from JDK 1.6 for interoperability.

public float
x

The X coordinate of this Point2D.

public float
y

The Y coordinate of this Point2D.

Constructor Summary

AccessConstructor and Description
public
Float()

Constructs and initializes a Point2D with coordinates (0, 0).

public
Float(float
the X coordinate of the newly constructed Point2D
x
,
float
the Y coordinate of the newly constructed Point2D
y
)

Constructs and initializes a Point2D with the specified coordinates.

Method Summary

Modifier and TypeMethod and Description
public double
getX()

Implements abstract java.awt.geom.Point2D.getX.

Returns the X coordinate of this Point2D in double precision.

public double
getY()

Implements abstract java.awt.geom.Point2D.getY.

Returns the Y coordinate of this Point2D in double precision.

public void
setLocation(double x, double y)

Implements abstract java.awt.geom.Point2D.setLocation.

Sets the location of this Point2D to the specified double coordinates.

public void
setLocation(float
the new X coordinate of this Point2D
x
,
float
the new Y coordinate of this Point2D
y
)

Sets the location of this Point2D to the specified float coordinates.

public String

Returns:

a string representation of this Point2D.
toString
()

Overrides java.lang.Object.toString.

Returns a String that represents the value of this Point2D.

Inherited from java.awt.geom.Point2D:
clonedistancedistancedistancedistanceSqdistanceSqdistanceSqequalshashCodesetLocation

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Use serialVersionUID from JDK 1.6 for interoperability.

Annotations
@Serial
xback to summary
public float x

The X coordinate of this Point2D.

Since
1.2
yback to summary
public float y

The Y coordinate of this Point2D.

Since
1.2

Constructor Detail

Floatback to summary
public Float()

Constructs and initializes a Point2D with coordinates (0, 0).

Since
1.2
Floatback to summary
public Float(float x, float y)

Constructs and initializes a Point2D with the specified coordinates.

Parameters
x:float

the X coordinate of the newly constructed Point2D

y:float

the Y coordinate of the newly constructed Point2D

Since
1.2

Method Detail

getXback to summary
public double getX()

Implements abstract java.awt.geom.Point2D.getX.

Doc from java.awt.geom.Point2D.getX.

Returns the X coordinate of this Point2D in double precision.

Since
1.2
getYback to summary
public double getY()

Implements abstract java.awt.geom.Point2D.getY.

Doc from java.awt.geom.Point2D.getY.

Returns the Y coordinate of this Point2D in double precision.

Since
1.2
setLocationback to summary
public void setLocation(double x, double y)

Implements abstract java.awt.geom.Point2D.setLocation.

Doc from java.awt.geom.Point2D.setLocation.

Sets the location of this Point2D to the specified double coordinates.

Since
1.2
setLocationback to summary
public void setLocation(float x, float y)

Sets the location of this Point2D to the specified float coordinates.

Parameters
x:float

the new X coordinate of this Point2D

y:float

the new Y coordinate of this Point2D

Since
1.2
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a String that represents the value of this Point2D.

Returns:String

a string representation of this Point2D.

Since
1.2