com.partnersoft.geometry.xy
Class XyPoint

java.lang.Object
  extended by com.partnersoft.geometry.xy.XyPoint
All Implemented Interfaces:
Coggable, Immutable, XyShape<XyPoint>, java.lang.Iterable<XyPoint>

public class XyPoint
extends java.lang.Object
implements XyShape<XyPoint>, Coggable

A 2-dimensional point in x, y space.

Copyright 2006-2007

Version:
$Id: XyPoint.java 2044 2009-08-22 22:11:09Z paul $
Author:
Paul Reavis, Rich Stepanski, Richard Fay

Constructor Summary
XyPoint(Cog state)
           
XyPoint(double x, double y)
           
 
Method Summary
 double distanceFrom(XyPoint nother)
          Returns the straight-line distance between this point and the one given.
 double distanceSquaredFrom(XyPoint nother)
          Returns the square of the straight-line distance between this point and the one given.
 boolean equals(java.lang.Object nother)
           
 boolean equals(java.lang.Object nother, double epsilon)
          Fuzzier than equals, returns true if both x and y are within epsilon of each other.
 XyBounds getBounds()
          Returns an XyBounds object representing the rectangular extents of this shape.
 double getX()
          X coordinate.
 double getY()
          Y coordinate.
 int hashCode()
           
 java.util.Iterator<XyPoint> iterator()
           
 XyPoint minus(XyPoint nother)
          Returns the offset, or two-dimensional difference, between this point and the other.
 XyPoint plus(XyPoint nother)
          Returns the two-dimensional sum of this point and the one given.
 XyPoint scaledBy(double scale)
          Return a scaled version of the shape by multiplying all coordinates by the given factor in both dimensions.
 XyPoint scaledBy(double scaleX, double scaleY)
           
 XyPoint shoot(double distance, XyDirection direction)
          Computes a new point using a distance and direction.
 XyPoint shoot(XyVector vector)
          Computes a new point using a vector.
 XyPoint snappedToGrid(double gridSize)
           
 XyPoint times(double factor)
          Multiplies both x and y by the given factor and returns the result.
 Cog toCog()
          Returns the complete internal state of this object in the form of a Cog.
 XyPolar toPolar()
          Converts the point to polar representation.
 java.lang.String toString()
           
 XyVector toVector()
          Converts the point to a vector from the origin (0, 0).
 XyShape transformedBy(XyTransform transform)
          Transform the shape using the given transform.
 XyPoint translatedBy(double offsetX, double offsetY)
          Translate the shape by adding all coordinates to the given x and y offsets.
 XyVector vectorFrom(XyPoint nother)
          Returns the two-dimensional vector offset between this point and the one given.
 XyVector vectorTo(XyPoint nother)
          Returns the two-dimensional vector offset between the point given and this point.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XyPoint

public XyPoint(double x,
               double y)

XyPoint

public XyPoint(Cog state)
Method Detail

distanceFrom

public double distanceFrom(XyPoint nother)
Returns the straight-line distance between this point and the one given.

Parameters:
nother - other point to measure from
Returns:
distance from other point

vectorFrom

public XyVector vectorFrom(XyPoint nother)
Returns the two-dimensional vector offset between this point and the one given.

Parameters:
nother - other point to measure from
Returns:
vector from other point

vectorTo

public XyVector vectorTo(XyPoint nother)
Returns the two-dimensional vector offset between the point given and this point.

Parameters:
nother - other point to measure from
Returns:
vector from other point

distanceSquaredFrom

public double distanceSquaredFrom(XyPoint nother)
Returns the square of the straight-line distance between this point and the one given. Since it avoids the square root operation required by the regular distance function, it's more efficient if you are doing a lot of distance comparisons.

Parameters:
nother - other point to measure from
Returns:
square of the distance from other point

plus

public XyPoint plus(XyPoint nother)
Returns the two-dimensional sum of this point and the one given.


minus

public XyPoint minus(XyPoint nother)
Returns the offset, or two-dimensional difference, between this point and the other. Subtracks the given point's x and y coordinates from this one's and returns the result.

Parameters:
nother - point to calculate offset from
Returns:
x and y difference from offset point

times

public XyPoint times(double factor)
Multiplies both x and y by the given factor and returns the result.


shoot

public XyPoint shoot(double distance,
                     XyDirection direction)
Computes a new point using a distance and direction.


shoot

public XyPoint shoot(XyVector vector)
Computes a new point using a vector.


snappedToGrid

public XyPoint snappedToGrid(double gridSize)

toPolar

public XyPolar toPolar()
Converts the point to polar representation.

Returns:
polar coordinates for this point

toVector

public XyVector toVector()
Converts the point to a vector from the origin (0, 0).

Returns:

scaledBy

public XyPoint scaledBy(double scale)
Description copied from interface: XyShape
Return a scaled version of the shape by multiplying all coordinates by the given factor in both dimensions. This resulting shape must be of the same class as the original.

Specified by:
scaledBy in interface XyShape<XyPoint>
Parameters:
scale - scaling factor
Returns:
scaled result

scaledBy

public XyPoint scaledBy(double scaleX,
                        double scaleY)

translatedBy

public XyPoint translatedBy(double offsetX,
                            double offsetY)
Description copied from interface: XyShape
Translate the shape by adding all coordinates to the given x and y offsets. The resulting shape must be of the same class as the original.

Specified by:
translatedBy in interface XyShape<XyPoint>
Parameters:
offsetX - offset for the x dimension
offsetY - offset for the y dimension
Returns:
offset result

transformedBy

public XyShape transformedBy(XyTransform transform)
Description copied from interface: XyShape
Transform the shape using the given transform. Due to potential distortion the result may be a different type of shape than this one.

Specified by:
transformedBy in interface XyShape<XyPoint>
Parameters:
transform - affine transform to apply.
Returns:
transformed result

iterator

public java.util.Iterator<XyPoint> iterator()
Specified by:
iterator in interface java.lang.Iterable<XyPoint>

toCog

public Cog toCog()
Description copied from interface: Coggable
Returns the complete internal state of this object in the form of a Cog.

Specified by:
toCog in interface Coggable
Returns:
Cog representing the internal state of this object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object nother)
Overrides:
equals in class java.lang.Object

equals

public boolean equals(java.lang.Object nother,
                      double epsilon)
Fuzzier than equals, returns true if both x and y are within epsilon of each other.

Parameters:
nother -
epsilon -
Returns:

getBounds

public XyBounds getBounds()
Description copied from interface: XyShape
Returns an XyBounds object representing the rectangular extents of this shape.

Specified by:
getBounds in interface XyShape<XyPoint>

hashCode

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

getX

public double getX()
X coordinate.

Returns:
x coordinate value

getY

public double getY()
Y coordinate.

Returns:
y coordinate value