com.sas.geometry
Class Rectangles

com.sas.geometry.Rectangles
All Implemented Interfaces:
com.sas.PublicClonable, com.sas.util.Countable, java.lang.Cloneable

public class Rectangles
implements com.sas.util.Countable, com.sas.PublicClonable

Rectangles is a class which maintains a list of java.awt.Rectangle objects. The Rectangles class also provides various rectangle related services.


Constructor Summary
Rectangles()
           
 
Method Summary
 void add(java.awt.Rectangle rect)
          Adds a rectangle.
 java.lang.Object clone()
          Returns a clone of the current Rectangles object
 int count()
          Returns the number of rectangles in the list.
 int count(com.sas.util.PredicateInterface pi)
          Returns the number of rectangles in the list that satisfy the given predicate.
 void dump()
          Prints each rectangle in the list to standard out.
 java.awt.Rectangle get(int index)
          Returns the rectangle at the specified index.
static int getBottom(java.awt.Rectangle rect)
          Returns the bottom edge of the specified rectangle.
static int getRight(java.awt.Rectangle rect)
          Returns the right edge of the specified rectangle.
static boolean intersect(java.awt.Rectangle r1, java.awt.Rectangle r2, java.awt.Rectangle rout, java.awt.Rectangle[] r1Left, int[] nr1Left, java.awt.Rectangle[] r2Left, int[] nr2Left)
          Computes the intersection of two rectangles.
 void intersect(java.awt.Rectangle r1, Rectangles list)
          Computes the intersection of the specified rectangle and list.
static boolean intersectRects(java.awt.Rectangle r1, java.awt.Rectangle r2, java.awt.Rectangle rx)
          Computes the intersection of the specified rectangles.
 void negate(java.awt.Rectangle universe)
          Negates the set of rectangles.
 void removeAll()
          Empties the rectangle list.
static void setBottom(java.awt.Rectangle rect, int bottom)
          Sets the bottom edge of the specified rectangle.
static void setRectBounds(java.awt.Rectangle rect, int x1, int y1, int x2, int y2)
          Sets the bounds of the given rectangle.
static void setRight(java.awt.Rectangle rect, int right)
          Sets the right edge of the specified rectangle.
 void unite(Rectangles list)
          Combines two rectangle lists.
 

Constructor Detail

Rectangles

public Rectangles()
Method Detail

add

public void add(java.awt.Rectangle rect)
Adds a rectangle. If the specified rectangle intersects any of the rectangles already in the set, then it is coalesced to keep the set as small as possible.

Parameters:
rect - the rectangle to add

intersect

public static boolean intersect(java.awt.Rectangle r1,
                                java.awt.Rectangle r2,
                                java.awt.Rectangle rout,
                                java.awt.Rectangle[] r1Left,
                                int[] nr1Left,
                                java.awt.Rectangle[] r2Left,
                                int[] nr2Left)
Computes the intersection of two rectangles.

Parameters:
r1 - the first input rectangle
r2 - the second input rectangle
rout - the resulting intersection; may be null if you don't care
r1Left - four-element array of "leftover" r1 rectangles (optional)
nr1Left - number of r1 things (max 4) (optional)
r2Left - four-element array of "leftover" r2 rectangles (optional)
nr2Left - number of r2 things (max 4) (optional)
Returns:
true r1 contains r2, otherwise false

intersect

public void intersect(java.awt.Rectangle r1,
                      Rectangles list)
Computes the intersection of the specified rectangle and list.

Parameters:
r1 - the Rectangle to intersect
list - the Rectangles oject to intersect

negate

public void negate(java.awt.Rectangle universe)
Negates the set of rectangles. Determines the "opposite" of the set of rectangles within the specified "universe". The universe is a rectangle that encloses the set. The opposite set is the set of rectangles that when combined with the current set exactly covers the universe.

Parameters:
universe - the bounds to negate against

unite

public void unite(Rectangles list)
Combines two rectangle lists. Adds each rectangle in the specified list to the current one. The rectangles are added using "add" so that overlapped ones are coalesced.

Parameters:
list - the list to combine with this one

dump

public void dump()
Prints each rectangle in the list to standard out.


getBottom

public static int getBottom(java.awt.Rectangle rect)
Returns the bottom edge of the specified rectangle.

Returns:
the bottom edge of the specified rectangle

getRight

public static int getRight(java.awt.Rectangle rect)
Returns the right edge of the specified rectangle.

Returns:
the right edge of the specified rectangle

setBottom

public static void setBottom(java.awt.Rectangle rect,
                             int bottom)
Sets the bottom edge of the specified rectangle.

Parameters:
rect - the rectangle to set the bottom edge of
bottom - the new value for the bottom edge

setRight

public static void setRight(java.awt.Rectangle rect,
                            int right)
Sets the right edge of the specified rectangle.

Parameters:
rect - the rectangle to set the right edge of
right - the new value for the right edge

intersectRects

public static boolean intersectRects(java.awt.Rectangle r1,
                                     java.awt.Rectangle r2,
                                     java.awt.Rectangle rx)
Computes the intersection of the specified rectangles.

Parameters:
r1 - first rectangle to intersect
r2 - second rectangle to intersect
rx - resulting rectangle
Returns:
true if they intersect, false otherwise

setRectBounds

public static void setRectBounds(java.awt.Rectangle rect,
                                 int x1,
                                 int y1,
                                 int x2,
                                 int y2)
Sets the bounds of the given rectangle. Complements Rectangle.rectBounds which takes x, y, width, and height. This method handles the case where x1 > x2 and/or y1 > y2.

Parameters:
rect - the rectangle to set the bounds of
x1 - the new left edge
y1 - the new top edge
x2 - the new right edge
y2 - the new bottom edge

get

public java.awt.Rectangle get(int index)
Returns the rectangle at the specified index.

Parameters:
index - the index of the rectangle to retrieve

removeAll

public void removeAll()
Empties the rectangle list.


count

public int count()
Returns the number of rectangles in the list.

Specified by:
count in interface com.sas.util.Countable

count

public int count(com.sas.util.PredicateInterface pi)
Returns the number of rectangles in the list that satisfy the given predicate.

Parameters:
pi - the predicate to satisfy

clone

public java.lang.Object clone()
Returns a clone of the current Rectangles object

Specified by:
clone in interface com.sas.PublicClonable
Overrides:
clone in class java.lang.Object
Returns:
a clone of the current Rectangles object



Copyright © 2009 SAS Institute Inc. All Rights Reserved.