Algorithm
Development Kit 1.0

algs.model.twod
Class TwoDPoint

java.lang.Object
  extended by algs.model.twod.TwoDPoint
All Implemented Interfaces:
IMultiPoint, IPoint

public class TwoDPoint
extends java.lang.Object
implements IPoint, IMultiPoint

Standard two-dimensional implementation of IPoint. For compatibility with other n-dimensional implementations, this class also implements IMultiPoint

Author:
George Heineman
See Also:
IMultiPoint, IPoint

Field Summary
 
Fields inherited from interface algs.model.IPoint
xy_sorter
 
Constructor Summary
TwoDPoint(double x, double y)
          Construct a TwoDPoint from the given (x,y) values.
TwoDPoint(IPoint pt)
          Construct when given an IPoint.
TwoDPoint(java.lang.String s)
          Construct when given a comma-separated string of x,y values as double.
 
Method Summary
 int dimensionality()
          Return the dimensionality of this point.
 double distance(IMultiPoint imp)
          Return the Euclidean distance between the given multipoint.
 boolean equals(java.lang.Object o)
          Provides the required equals method.
 double getCoordinate(int d)
          Return the coordinate value in the given dimension for the given point.
 double getX()
          return the x-coordinate value for the given point.
 double getY()
          return the y-coordinate value for the given point.
 int hashCode()
           
 double[] raw()
          Returns the raw representation of this point as an array of two values.
 java.lang.String toString()
          Reasonable toString() implementation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TwoDPoint

public TwoDPoint(double x,
                 double y)
Construct a TwoDPoint from the given (x,y) values.

Parameters:
x - value of x-coordinate.
y - value of y-coordinate.

TwoDPoint

public TwoDPoint(IPoint pt)
Construct when given an IPoint.

Parameters:
pt - point whose values are extracted and used to initialize this.

TwoDPoint

public TwoDPoint(java.lang.String s)
Construct when given a comma-separated string of x,y values as double.

No serious error handling is considered, so be wary of passing in invalid values.

Parameters:
s - A comma-separated string of doubles used to initialize this two-dimensional point.
Method Detail

getX

public double getX()
Description copied from interface: IPoint
return the x-coordinate value for the given point.

Specified by:
getX in interface IPoint
See Also:
IPoint.getX()

getY

public double getY()
Description copied from interface: IPoint
return the y-coordinate value for the given point.

Specified by:
getY in interface IPoint
See Also:
IPoint.getY()

equals

public boolean equals(java.lang.Object o)
Provides the required equals method. Two points are equal if their (x,y) values are equal to each other within the floating point tolerance FloatingPoint.epsilon, as defined in

Overrides:
equals in class java.lang.Object
Parameters:
o - the object against which to compare.
See Also:
FloatingPoint

toString

public java.lang.String toString()
Reasonable toString() implementation.

Overrides:
toString in class java.lang.Object

dimensionality

public int dimensionality()
Description copied from interface: IMultiPoint
Return the dimensionality of this point.

Specified by:
dimensionality in interface IMultiPoint
See Also:
IMultiPoint.dimensionality()

getCoordinate

public double getCoordinate(int d)
Description copied from interface: IMultiPoint
Return the coordinate value in the given dimension for the given point.

Specified by:
getCoordinate in interface IMultiPoint
Parameters:
d - the dimension 1 ≤ dx ≤ dimensionality() for the desired coordinate.
See Also:
IMultiPoint.getCoordinate(int)

distance

public double distance(IMultiPoint imp)
Return the Euclidean distance between the given multipoint. Ensures that only valid for two-dimensional comparison.

Specified by:
distance in interface IMultiPoint
Parameters:
imp - the point against from which the distance is computed.
Throws:
java.lang.IllegalArgumentException - if invoked with an argument that does not represent a two-dimensional point.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

raw

public double[] raw()
Returns the raw representation of this point as an array of two values.

Specified by:
raw in interface IMultiPoint

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.