edu.neu.ccs
Class XPoint2D

java.lang.Object
  extended byjava.awt.geom.Point2D
      extended byjava.awt.geom.Point2D.Double
          extended byedu.neu.ccs.XPoint2D
All Implemented Interfaces:
Cloneable, JPTConstants, Serializable, Stringable, SwingConstants
Direct Known Subclasses:
XComplex

public class XPoint2D
extends Point2D.Double
implements Serializable, Stringable, JPTConstants

Class XPoint2D extends Point2D.Double in order to provide a much shorter name that does not explicitly refer to an inner class and to support Stringable.

As of 2.5.0, added the isFinite methods.

Version:
2.5.0
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.geom.Point2D
Point2D.Double, Point2D.Float
 
Field Summary
static String[] BLANK
          The data array with blank names "", "".
protected  SwingPropertyChangeSupport changeAdapter
          Helper object for property change API.
static String standardMessage
          The standard error message for fromStringData.
static String[] XY
          The data array with names "x", "y".
 
Fields inherited from class java.awt.geom.Point2D.Double
x, y
 
Fields inherited from interface edu.neu.ccs.util.JPTConstants
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
XPoint2D()
          Constructs a default XPoint2D.
XPoint2D(double[] data)
          Constructs an XPoint2D using the pair of values in the given array of double which must be of size 2.
XPoint2D(double x, double y)
          Constructs an XPoint2D using the given x,y double values.
XPoint2D(float[] data)
          Constructs an XPoint2D using the pair of values in the given array of float which must be of size 2.
XPoint2D(Point2D p)
          Constructs an XPoint2D using a copy of the data in the given Point2D.
XPoint2D(String data)
          Constructs an XPoint2D object from a String representation of the data state.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          Registers the given object to listen for property change events generated by this object.
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Registers the given object to listen for property change events generated by this object with the given property name.
 double angleInDegrees()
          Computes the angle in degrees from the positive x-axis.
static double angleInDegrees(double x1, double y1, double x2, double y2)
          Computes the angle in degrees from the the point (x1,y1) to the point (x2,y2).
static double angleInDegrees(Point2D p, Point2D q)
          Computes the angle in degrees from the point p to the point q.
 double angleInRadians()
          Computes the angle in radians from the positive x-axis.
static double angleInRadians(double x1, double y1, double x2, double y2)
          Computes the angle in radians from the the point (x1,y1) to the point (x2,y2).
static double angleInRadians(Point2D p, Point2D q)
          Computes the angle in radians from the point p to the point q.
 void fromStringData(String data)
          Defines the data state for this XPoint2D object from a String representation of the data state.
 boolean isFinite()
          Returns true if both coordinates of this XPoint2D are finite and false otherwise.
static boolean isFinite(Point2D p)
          Returns true if both coordinates of the given Point2D are finite and false otherwise.
 void move(double dx, double dy)
          Moves the point by a translation using the data in the point specified by coordinates.
 void move(Point2D p)
          Moves the point by a translation using the data in the point.
 double radius()
          Computes the distance of the point to the origin, that is sqrt(x*x+y*y).
 double radiusSq()
          Computes the distance squared of the point to the origin, that is, x*x+y*y.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Deregisters the given object from listening for property change events generated by this object.
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Deregisters the given object from listening for property change events generated by this object with the given property name.
 void setLocation(double[] data)
          Sets this point using the pair of values in the given array of double which must be of size 2.
 void setLocation(double x, double y)
          Sets this point to the given x,y values.
 void setLocation(float[] data)
          Sets this point using the pair of values in the given array of float which must be of size 2.
 void setLocation(Point2D p)
          Sets this point to the value of the given point.
 void setValue(double[] data)
          Sets this point using the pair of values in the given array of double which must be of size 2.
 void setValue(double x, double y)
          Sets this point to the given x,y values.
 void setValue(float[] data)
          Sets this point using the pair of values in the given array of float which must be of size 2.
 void setValue(Point2D p)
          Sets this point to the value of the given point.
 double[] toDoubleArray()
          Returns the x,y data in an array of double of size 2.
 float[] toFloatArray()
          Returns the x,y data in an array of float of size 2.
 String toString()
          Returns a human readable String representing the data state of this XPoint2D as an annotated string.
 String toStringData()
          Returns a human readable String representing the data state of this XPoint2D as a simple string.
 
Methods inherited from class java.awt.geom.Point2D.Double
getX, getY
 
Methods inherited from class java.awt.geom.Point2D
clone, distance, distance, distance, distanceSq, distanceSq, distanceSq, equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BLANK

public static final String[] BLANK
The data array with blank names "", "".


XY

public static final String[] XY
The data array with names "x", "y".


standardMessage

public static final String standardMessage
The standard error message for fromStringData.

See Also:
Constant Field Values

changeAdapter

protected SwingPropertyChangeSupport changeAdapter
Helper object for property change API.

Constructor Detail

XPoint2D

public XPoint2D()
Constructs a default XPoint2D.


XPoint2D

public XPoint2D(double x,
                double y)
Constructs an XPoint2D using the given x,y double values.

Parameters:
x - the x-coordinate of the point
y - the y-coordinate of the point

XPoint2D

public XPoint2D(Point2D p)

Constructs an XPoint2D using a copy of the data in the given Point2D.

If the given point is null, then initializes this point to 0,0.

Parameters:
p - the existing point whose data will be copied

XPoint2D

public XPoint2D(double[] data)
Constructs an XPoint2D using the pair of values in the given array of double which must be of size 2.

If the given array is null or not of size 2, then initializes this point to 0,0.

Parameters:
data - the array of size 2 with the x,y data

XPoint2D

public XPoint2D(float[] data)
Constructs an XPoint2D using the pair of values in the given array of float which must be of size 2.

If the given array is null or not of size 2, then initializes this point to 0,0.

Parameters:
data - the array of size 2 with the x,y data

XPoint2D

public XPoint2D(String data)
         throws ParseException
Constructs an XPoint2D object from a String representation of the data state.

Parameters:
data - String representation of the data state
Throws:
ParseException - if the data is malformed
Method Detail

toString

public String toString()

Returns a human readable String representing the data state of this XPoint2D as an annotated string.

XPoint2D[x=...;y=...]

where the dots stand for the x,y coordinate data.


toStringData

public String toStringData()

Returns a human readable String representing the data state of this XPoint2D as a simple string.

[...;...]

where the dots stand for the x,y coordinate data.

Specified by:
toStringData in interface Stringable
See Also:
Stringable.fromStringData(String)

fromStringData

public void fromStringData(String data)
                    throws ParseException

Defines the data state for this XPoint2D object from a String representation of the data state.

Fires property change VALUE.

Specified by:
fromStringData in interface Stringable
Parameters:
data - String representation of the data state
Throws:
ParseException - if the data is malformed
See Also:
Stringable.toStringData()

setValue

public void setValue(double x,
                     double y)

Sets this point to the given x,y values.

Fires property change VALUE.

Parameters:
x - the x-coordinate of the point
y - the y-coordinate of the point

setValue

public void setValue(Point2D p)

Sets this point to the value of the given point.

If the given point is null, then does nothing.

Fires property change VALUE.

Parameters:
p - the existing point whose data will be copied

setValue

public void setValue(double[] data)

Sets this point using the pair of values in the given array of double which must be of size 2.

If the given array is null or not of size 2, then does nothing.

Fires property change VALUE.

Parameters:
data - the array of size 2 with the x,y data

setValue

public void setValue(float[] data)

Sets this point using the pair of values in the given array of float which must be of size 2.

If the given array is null or not of size 2, then does nothing.

Fires property change VALUE.

Parameters:
data - the array of size 2 with the x,y data

setLocation

public void setLocation(double x,
                        double y)

Sets this point to the given x,y values.

Fires property change VALUE.

Equivalent to setValue.

Parameters:
x - the x-coordinate
y - the y-coordinate

setLocation

public void setLocation(Point2D p)

Sets this point to the value of the given point.

If the given point is null, then does nothing.

Fires property change VALUE.

Parameters:
p - the existing point whose data will be copied

setLocation

public void setLocation(double[] data)

Sets this point using the pair of values in the given array of double which must be of size 2.

If the given array is null or not of size 2, then does nothing.

Fires property change VALUE.

Parameters:
data - the array of size 2 with the x,y data

setLocation

public void setLocation(float[] data)

Sets this point using the pair of values in the given array of float which must be of size 2.

If the given array is null or not of size 2, then does nothing.

Fires property change VALUE.

Parameters:
data - the array of size 2 with the x,y data

move

public void move(double dx,
                 double dy)

Moves the point by a translation using the data in the point specified by coordinates.

Fires property change VALUE.

Parameters:
dx - the x-coordinate of the translation
dy - the y-coordinate of the translation

move

public void move(Point2D p)

Moves the point by a translation using the data in the point.

If the given point is null, then does nothing.

Fires property change VALUE.

Parameters:
p - the translation vector

toDoubleArray

public double[] toDoubleArray()

Returns the x,y data in an array of double of size 2.


toFloatArray

public float[] toFloatArray()

Returns the x,y data in an array of float of size 2.


radius

public double radius()
Computes the distance of the point to the origin, that is sqrt(x*x+y*y).


radiusSq

public double radiusSq()
Computes the distance squared of the point to the origin, that is, x*x+y*y.


angleInRadians

public double angleInRadians()
Computes the angle in radians from the positive x-axis.


angleInRadians

public static double angleInRadians(Point2D p,
                                    Point2D q)
Computes the angle in radians from the point p to the point q.

Parameters:
p - point to start angle measurement
q - point to finish angle measurement

angleInRadians

public static double angleInRadians(double x1,
                                    double y1,
                                    double x2,
                                    double y2)
Computes the angle in radians from the the point (x1,y1) to the point (x2,y2).

Parameters:
x1 - x-coordinate of point to start angle measurement
y1 - y-coordinate of point to start angle measurement
x2 - x-coordinate of point to finish angle measurement
y2 - y-coordinate of point to finish angle measurement

angleInDegrees

public double angleInDegrees()
Computes the angle in degrees from the positive x-axis.


angleInDegrees

public static double angleInDegrees(Point2D p,
                                    Point2D q)
Computes the angle in degrees from the point p to the point q.

Parameters:
p - point to start angle measurement
q - point to finish angle measurement

angleInDegrees

public static double angleInDegrees(double x1,
                                    double y1,
                                    double x2,
                                    double y2)
Computes the angle in degrees from the the point (x1,y1) to the point (x2,y2).

Parameters:
x1 - x-coordinate of point to start angle measurement
y1 - y-coordinate of point to start angle measurement
x2 - x-coordinate of point to finish angle measurement
y2 - y-coordinate of point to finish angle measurement

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Registers the given object to listen for property change events generated by this object.

Parameters:
listener - the listener to be registered

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)
Registers the given object to listen for property change events generated by this object with the given property name.

Parameters:
propertyName - the name of the desired property
listener - the listener to be registered

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Deregisters the given object from listening for property change events generated by this object.

Parameters:
listener - the listener to be deregistered

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)
Deregisters the given object from listening for property change events generated by this object with the given property name.

Parameters:
propertyName - the name of the desired property
listener - the listener to be deregistered

isFinite

public boolean isFinite()
Returns true if both coordinates of this XPoint2D are finite and false otherwise.


isFinite

public static boolean isFinite(Point2D p)

Returns true if both coordinates of the given Point2D are finite and false otherwise.

In particular, returns false if the given Point2D is null.