PenProfile 2.x

com.livescribe.geom
Class Rectangle

java.lang.Object
  extended by com.livescribe.geom.Shape
      extended by com.livescribe.geom.Rectangle

public class Rectangle
extends Shape

This class describes a rectangle by using the upper left and lower right points. The width and height are calculated as the difference between the X- and Y-coordinates, respectively. Note that "upper left" refers to page coordinates and not mathematical coordinates. In other words, the "upper left" is considered to contain the minimum X- and Y-coordinate values.

It is assumed that the X- and Y-coordinates of the first point (coordinate zero) are ≤ the coordinates of the second point (coordinate one). Some, but not all, of the methods here enforce this. Be aware of this fact.


Field Summary
 
Fields inherited from class com.livescribe.geom.Shape
COORD_MAX, COORD_MIN, INTERSECT_CLIP, INTERSECT_EXTERNAL, INTERSECT_INTERNAL1, INTERSECT_INTERNAL2, SHAPE_COMPOSITE, SHAPE_ELLIPSE, SHAPE_LINESEGMENT, SHAPE_POINT, SHAPE_POLYGON, SHAPE_POLYLINE, SHAPE_RECTANGLE, SHAPE_STROKE, type, vertex
 
Constructor Summary
Rectangle()
          Creates a new rectangle having its top left point at (0,0) and a height and width of zero.
Rectangle(int[] v)
          Creates a new rectangle having the specified points.
Rectangle(int x, int y, int width, int height)
          Creates a new rectangle having the specified top left coordinate and size.
 
Method Summary
 boolean contains(int x, int y)
          Indicates if the point specified by (x,y) is contained within this rectangle.
 boolean equals(Object obj)
          Returns whether the given object is considered equal to this rectangle.
 int getHeight()
          Gets the height of this rectangle.
 int getWidth()
          Gets the width of this rectangle.
 int getX()
          Returns the X-coordinate of the top left corner.
 int getY()
          Returns the Y-coordinate of the top left corner.
 void setHeight(int height)
          Sets the rectangle height.
 void setWidth(int width)
          Sets the rectangle width.
 void setX(int x)
          Sets the X-coordinate of the top left corner.
 void setY(int y)
          Sets the Y-coordinate of the top left corner.
 String toString()
          Returns a string representation of this object.
 Rectangle union(Rectangle r)
          Finds the union of this rectangle and the given rectangle.
 
Methods inherited from class com.livescribe.geom.Shape
getBoundingBox, getNumberofVertices, getNumberOfVertices, getSize, getType, getUnion, getX, getXY, getY, intersectsWith, setVertexArray, setX, setXY, setXY, setY
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rectangle

public Rectangle()
Creates a new rectangle having its top left point at (0,0) and a height and width of zero.


Rectangle

public Rectangle(int x,
                 int y,
                 int width,
                 int height)
Creates a new rectangle having the specified top left coordinate and size.

Parameters:
x - the top left X-coordinate
y - the top left Y-coordinate
width - the width
height - the height
Throws:
IllegalArgumentException - if the width or height are negative.

Rectangle

public Rectangle(int[] v)
Creates a new rectangle having the specified points. The array should contain four elements, two (X,Y) pairs.

Parameters:
v - the vertex array
Method Detail

getX

public int getX()
Returns the X-coordinate of the top left corner.

Returns:
the X-coordinate of the top left corner.

getY

public int getY()
Returns the Y-coordinate of the top left corner.

Returns:
the Y-coordinate of the top left corner.

getWidth

public int getWidth()
Gets the width of this rectangle. This is the difference between the X-coordinates.

Returns:
the rectangle width.

getHeight

public int getHeight()
Gets the height of this rectangle. This is the difference between the Y-coordinates.

Returns:
the rectangle height.

setX

public void setX(int x)
Sets the X-coordinate of the top left corner.

Parameters:
x - the X-coordinate of the top left corner

setY

public void setY(int y)
Sets the Y-coordinate of the top left corner.

Parameters:
y - the X-coordinate of the top left corner

setWidth

public void setWidth(int width)
Sets the rectangle width.

Parameters:
width - the new width
Throws:
IllegalArgumentException - if the width is negative.

setHeight

public void setHeight(int height)
Sets the rectangle height.

Parameters:
height - the new height
Throws:
IllegalArgumentException - if the height is negative.

contains

public boolean contains(int x,
                        int y)
Indicates if the point specified by (x,y) is contained within this rectangle. This method assumes that the rectangle does not have a negative height or width.

Overrides:
contains in class Shape
Parameters:
x - the X-coordinate to test
y - the Y-coordinate to test
Returns:
true if it is contained and false if not fully contained.

union

public Rectangle union(Rectangle r)
Finds the union of this rectangle and the given rectangle. This method assumes that the rectangle does not have a negative height or width.

Parameters:
r - the second rectangle
Returns:
a new Rectangle that is the union if this and the given rectangle.

equals

public boolean equals(Object obj)
Returns whether the given object is considered equal to this rectangle.

Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if the object is equal to this rectangle and false otherwise.
See Also:
Boolean.hashCode(), Hashtable

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Shape
Returns:
a string representation of this object.

PenProfile 2.x

Copyright © 2010 Livescribe Inc. All Rights Reserved.
Confidential and subject to NDA.