com.yospace.yae.yogi
Class Rectangle

java.lang.Object
  |
  +--com.yospace.yae.yogi.Rectangle

public class Rectangle
extends java.lang.Object

A basic dimension collector class.


Field Summary
 int height
          The height of the Rectangle.
 int width
          The width of the Rectangle.
 int x
          The x coordinate of the Rectangle.
 int y
          The y coordinate of the Rectangle.
 
Constructor Summary
Rectangle(int x, int y, int width, int height)
          Constructs a new Rectangle at the location (x, y) with dimension (width, height).
 
Method Summary
 void expandToContain(int rx, int ry, int rw, int rh)
          Expand this rectangle to encompass the rectangle described by the arguments.
 void expandToContain(Rectangle r)
          Expand this rectangle to encompass the given rectangle.
 Rectangle intersection(Rectangle r)
          Find the intersection rectangle of this and the given rectangle r.
 boolean isEqualTo(Rectangle r2)
          Tests whether two rectangles have exactly the same bounds.
 boolean isZeroValued()
          Simply checks as to whether this rectangle is completely zero-valued.
static Rectangle parseRectangle(java.lang.String s)
          Parses a string representation of a rectangle.
 java.lang.String toString()
          Overridden toString method to give nicely formatted output of the position and size of the Rectangle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public int x
The x coordinate of the Rectangle.

y

public int y
The y coordinate of the Rectangle.

width

public int width
The width of the Rectangle.

height

public int height
The height of the Rectangle.
Constructor Detail

Rectangle

public Rectangle(int x,
                 int y,
                 int width,
                 int height)
Constructs a new Rectangle at the location (x, y) with dimension (width, height).
Parameters:
x - the x coordinate of the Rectangle.
y - the y coordinate of the Rectangle.
width - the width of the Rectangle.
height - the height of the Rectangle.
Method Detail

expandToContain

public void expandToContain(Rectangle r)
Expand this rectangle to encompass the given rectangle.
Parameters:
r - the rectangle to expand to contain.

expandToContain

public void expandToContain(int rx,
                            int ry,
                            int rw,
                            int rh)
Expand this rectangle to encompass the rectangle described by the arguments.
Parameters:
rx - the x coordinate of the top left corner of the rectangle to be encompassed.
ry - the y coordinate of the top left corner of the rectangle to be encompassed.
rw - the width of the rectangle to be encompassed.
rh - the height of the rectangle to be encompassed.

intersection

public Rectangle intersection(Rectangle r)
Find the intersection rectangle of this and the given rectangle r.
Parameters:
r - the rectangle to intersect with.
Returns:
the intersected rectangle. A 0-valued rectangle is returned if no intersection exists.

isZeroValued

public boolean isZeroValued()
Simply checks as to whether this rectangle is completely zero-valued.
Returns:
true if the rectangle is completely zero-valued, false otherwise.

isEqualTo

public boolean isEqualTo(Rectangle r2)
Tests whether two rectangles have exactly the same bounds.
Parameters:
r2 - the Rectangle to compare this one against.
Returns:
true if this Rectangle and r2 have the same bounds, false otherwise.

toString

public java.lang.String toString()
Overridden toString method to give nicely formatted output of the position and size of the Rectangle. The format is "x,y,w,h".
Overrides:
toString in class java.lang.Object
Returns:
the String representation.

parseRectangle

public static Rectangle parseRectangle(java.lang.String s)
Parses a string representation of a rectangle. A valid string is a comma-separated list of four values representing the x, y, width and height of the rectangle. null is returned if the string is invalid.
Parameters:
s - the String version of the rectangle.
Returns:
the generated Rectangle or null.

Copyright 2002 Yospace Holdings Ltd. All Rights Reserved.