edu.umd.cfar.lamp.viper.geometry
Class Pnt

java.lang.Object
  extended byedu.umd.cfar.lamp.viper.geometry.Component
      extended byedu.umd.cfar.lamp.viper.geometry.Pnt
All Implemented Interfaces:
HasCentroid, Moveable

public class Pnt
extends Component
implements Moveable, HasCentroid

Represents a 2d point in Rational format.


Field Summary
 
Fields inherited from class edu.umd.cfar.lamp.viper.geometry.Component
t, x, y
 
Fields inherited from interface edu.umd.cfar.lamp.viper.geometry.Moveable
EAST, NORTH, NORTHEAST, NORTHWEST, SOUTH, SOUTHEAST, SOUTHWEST, WEST
 
Constructor Summary
Pnt()
          Constructs a new Pnt set to the origin.
Pnt(Component C)
          Constructs a new Pnt with the given coordinates.
Pnt(int X, int Y)
          Constructs a new Pnt at the given location.
Pnt(Rational X, Rational Y)
          Constructs a new Pnt at the given location.
 
Method Summary
 boolean equals(java.lang.Object o)
          Tests the equality of this with another Component.
 Pnt getCentroid()
          Gets a copy of the centroid.
 Rational getX()
          Gets the x-coordinate of the point.
 Rational getY()
          Gets the y-coordinate of the point.
 int hashCode()
          Generates a hash code for this object.
 boolean isLeftOf(Pnt a, Pnt b)
          Tests to see if this point is to the left of the oriented line segment ab.
 boolean isLeftOfOrOn(Pnt a, Pnt b)
          Tests to see if this point is to the left of or on the oriented line segment ab.
 Moveable move(int direction, int distance)
          Moves the box in the given direction.
 java.awt.geom.Point2D.Double point2DDoubleValue()
          Gets the Point2D representation of this point.
 java.awt.Point pointValue()
          Gets the Point representation of this point.
 Moveable shift(int x, int y)
          Shifts the moveable by the given amount.
static Pnt valueOf(java.lang.String S)
          Creates a new point from the given number pair.
 
Methods inherited from class edu.umd.cfar.lamp.viper.geometry.Component
dot, length, minus, plus, set, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pnt

public Pnt()
Constructs a new Pnt set to the origin.


Pnt

public Pnt(int X,
           int Y)
Constructs a new Pnt at the given location.

Parameters:
X - The x coordinate of the point.
Y - The y coordinate of the point.

Pnt

public Pnt(Rational X,
           Rational Y)
Constructs a new Pnt at the given location.

Parameters:
X - The x coordinate of the point.
Y - The y coordinate of the point.

Pnt

public Pnt(Component C)
Constructs a new Pnt with the given coordinates.

Parameters:
C - A Component to take the x and y coordinates from for a point.
Method Detail

valueOf

public static Pnt valueOf(java.lang.String S)
Creates a new point from the given number pair. E.g. 12 13

Parameters:
S - the pair of numbers
Returns:
new point
Throws:
BadAttributeDataException - if the string isn't formed properly

equals

public boolean equals(java.lang.Object o)
Tests the equality of this with another Component.

Overrides:
equals in class Component
Parameters:
o - The object to test against this Component.
Returns:
true if these are equal.

hashCode

public int hashCode()
Generates a hash code for this object.

Overrides:
hashCode in class Component
Returns:
A hash code for use in HashMaps and so on.

point2DDoubleValue

public java.awt.geom.Point2D.Double point2DDoubleValue()
Gets the Point2D representation of this point.

Returns:
A Point2D.Double that is as close to this Pnt as possible.

pointValue

public java.awt.Point pointValue()
Gets the Point representation of this point.

Returns:
The nearest integral Point to this Pnt.

getX

public Rational getX()
Gets the x-coordinate of the point.

Returns:
the x-coordinate of the point

getY

public Rational getY()
Gets the y-coordinate of the point.

Returns:
the y-coordinate of the point

move

public Moveable move(int direction,
                     int distance)
Moves the box in the given direction. XXX currently only works for 32-bit integral coordinates

Specified by:
move in interface Moveable
Parameters:
direction - the direction to move, one of Movable.NORTH, etc.
distance - the distance to move
Returns:
a copy of the box with the origin shifted per the instructions
See Also:
Moveable

shift

public Moveable shift(int x,
                      int y)
Description copied from interface: Moveable
Shifts the moveable by the given amount.

Specified by:
shift in interface Moveable
Parameters:
x -
y -
Returns:
See Also:
Moveable.shift(int, int)

getCentroid

public Pnt getCentroid()
Description copied from interface: HasCentroid
Gets a copy of the centroid.

Specified by:
getCentroid in interface HasCentroid
Returns:
the centroid of the object
See Also:
HasCentroid.getCentroid()

isLeftOf

public boolean isLeftOf(Pnt a,
                        Pnt b)
Tests to see if this point is to the left of the oriented line segment ab.

Parameters:
a - start
b - look from a to this point to see where left is
Returns:
if the point is on the left halfplane defined by ab

isLeftOfOrOn

public boolean isLeftOfOrOn(Pnt a,
                            Pnt b)
Tests to see if this point is to the left of or on the oriented line segment ab.

Parameters:
a - start
b - look from a to this point to see where left is
Returns:
if the point is on the left halfplane defined by ab