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

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

public class Circle
extends java.lang.Object
implements java.lang.Cloneable, HasCentroid, Moveable

A circle, specified by the center point and the radius in integer format, supporting functions necessary for simple comparison. It does not support the functions necessary for advanced comparison (union, etc.) yet.


Field Summary
 
Fields inherited from interface edu.umd.cfar.lamp.viper.geometry.Moveable
EAST, NORTH, NORTHEAST, NORTHWEST, SOUTH, SOUTHEAST, SOUTHWEST, WEST
 
Constructor Summary
Circle()
          creates circle at (0,0) with radius = 0.
Circle(Circle old)
          Copy constructor for the circle.
Circle(int x, int y, int r)
          Creates circle with center (x,y) and radius = r
 
Method Summary
 double area()
          Approximates the area of the circle.
 java.lang.Object clone()
          Copies the circle.
 boolean contains(Pnt point)
          Tests to see if the given point is within the circle.
 boolean equals(java.lang.Object o)
          Tests to see if this circle is the same one as the specified circle.
 BoundingBox getBoundingBox()
          Gets the closest square surrounding the circle.
 Pnt getCenter()
          Returns the center of the circle.
 Pnt getCentroid()
          Gets a copy of the centroid.
 int getRadius()
          Gets the circle's radius.
 double intersectArea(Circle other)
          Approximates the shared area of two circles.
 Moveable move(int direction, int distance)
          Creates a new copy of this movable item, shifted in the given direction by the given number of pixels.
 Moveable shift(int x, int y)
          Shifts the moveable by the given amount.
 java.lang.String toString()
          Prints out the circle in the ViPER format.
static Circle valueOf(java.lang.String S)
          Creates a new Circle from the string.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Circle

public Circle()
creates circle at (0,0) with radius = 0.


Circle

public Circle(int x,
              int y,
              int r)
Creates circle with center (x,y) and radius = r

Parameters:
x - the x-coordinate of the circle's center
y - the y-coordinate of the circle's center
r - the radius of the circle

Circle

public Circle(Circle old)
Copy constructor for the circle.

Parameters:
old - the circle to copy
Method Detail

valueOf

public static Circle valueOf(java.lang.String S)
Creates a new Circle from the string.

Parameters:
S - a string in the form x y radius
Returns:
new Circle from the string
Throws:
BadAttributeDataException - upon a parse error

equals

public boolean equals(java.lang.Object o)
Tests to see if this circle is the same one as the specified circle.

Parameters:
o - the circle to test against
Returns:
true iff the this and the specified circle represent the same origin and radius

getCenter

public Pnt getCenter()
Returns the center of the circle.

Returns:
the center point of the circle

getRadius

public int getRadius()
Gets the circle's radius.

Returns:
the radius of this circle

toString

public java.lang.String toString()
Prints out the circle in the ViPER format.

Returns:
a space delimited list of integers, in the form x y r

clone

public java.lang.Object clone()
Copies the circle.

Returns:
a new copy of the same circle

contains

public boolean contains(Pnt point)
Tests to see if the given point is within the circle.

Parameters:
point - the point to test
Returns:
true iff the point is within or onthe circle.

getBoundingBox

public BoundingBox getBoundingBox()
Gets the closest square surrounding the circle.

Returns:
the bounding box for the circle

area

public double area()
Approximates the area of the circle.

Returns:
Math.PI times the square of the radius

intersectArea

public double intersectArea(Circle other)
Approximates the shared area of two circles.

Parameters:
other - the circle to intersect with
Returns:
the area of the region overlapped by both circles

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()

move

public Moveable move(int direction,
                     int distance)
Description copied from interface: Moveable
Creates a new copy of this movable item, shifted in the given direction by the given number of pixels.

Specified by:
move in interface Moveable
Parameters:
direction - the direction to move the item
distance - the distance to move it
Returns:
the new item, the same as the old one, but shifted
See Also:
Moveable.move(int, int)

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)