shady.common
Class Point

java.lang.Object
  extended by shady.common.Point
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Point.Cartesian, Point.OnSegment

public abstract class Point
extends java.lang.Object
implements java.io.Serializable

A 2D point.

Generic Points are immutable and can always report their Cartesian coordinates.

There are two mutable specializations of Point: Point.OnSegment and Point.Cartesian.

Target: 1.1 JRE.

Copyright (C) 2006 Marsette A. Vona, III

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Author:
Marsette (Marty) A. Vona, III
See Also:
Serialized Form

Nested Class Summary
static class Point.Cartesian
          A mutable point in a 2D Cartesian plane.
static class Point.OnSegment
          A mutable point on a Segment.
 
Field Summary
private static java.lang.String cvsid
          CVS id.
 
Constructor Summary
Point()
           
 
Method Summary
 double distance(Point other)
          Get the distance to another point.
 double distanceSq(double x, double y)
          Get the square of the distance to (x, y).
 double distanceSq(Point other)
          Get the square of the distance to another point.
abstract  double getX()
          Get the Cartesian x coordinate.
abstract  double getY()
          Get the Cartesian y coordinate.
abstract  Point invalidate()
          Invalidate this Point.
 boolean isValid()
          Check whether this Point is valid.
 java.lang.String toString()
          Convenience cover of toString(DoubleFormatter), uses no formatter.
 java.lang.String toString(DoubleFormatter formatter)
          Return a human-readable String representation of this Point.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cvsid

private static final java.lang.String cvsid

CVS id.

See Also:
Constant Field Values
Constructor Detail

Point

public Point()
Method Detail

getX

public abstract double getX()

Get the Cartesian x coordinate.

Returns:
the Cartesian x coordinate

getY

public abstract double getY()

Get the Cartesian y coordinate.

Returns:
the Cartesian y coordinate

isValid

public boolean isValid()

Check whether this Point is valid.

Default impl just checks that both coordinates are non-NaN.

Returns:
true iff this Point is valid

invalidate

public abstract Point invalidate()

Invalidate this Point.

After calling this isValid() will return false.

Returns:
self ref

toString

public java.lang.String toString(DoubleFormatter formatter)

Return a human-readable String representation of this Point.

Parameters:
formatter - the formatter to use, null if none
Returns:
a human-readable String representation of this Point

toString

public java.lang.String toString()

Convenience cover of toString(DoubleFormatter), uses no formatter.

Overrides:
toString in class java.lang.Object

distanceSq

public double distanceSq(Point other)

Get the square of the distance to another point.

Parameters:
other - the other point, not null
Returns:
the square of the distance to other

distanceSq

public double distanceSq(double x,
                         double y)

Get the square of the distance to (x, y).

Parameters:
x - the x-coord
y - the y-coord
Returns:
the square of the distance to (x, y)

distance

public double distance(Point other)

Get the distance to another point.

Parameters:
other - the other point
Returns:
the the distance to other