danger.ui
Class Rect

java.lang.Object
  |
  +--danger.ui.Rect

public class Rect
extends java.lang.Object

Various methods for constructing and manipulating a 2-dimension rectangle Danger rectangles are exclusive meaning that the upper-left and bottom-right points define the upper-left corner of a pixel rather than the center of a pixel. This has the advantage that the width of the rectangle is (right - left) and the height is (bottom - top). All rational people define rectangles this way.


Field Summary
 int bottom
          Contains the values of the four sides of the rectangle Do not change the order of these; native code depends on it!
 int left
          Contains the values of the four sides of the rectangle Do not change the order of these; native code depends on it!
 int right
          Contains the values of the four sides of the rectangle Do not change the order of these; native code depends on it!
 int top
          Contains the values of the four sides of the rectangle Do not change the order of these; native code depends on it!
 
Constructor Summary
Rect()
          Generic constructor.
Rect(int width, int height)
          Construct which creates a zero-based rectangle with a specific width and height.
Rect(int left, int top, int right, int bottom)
          Constructor which creates a new rectangle and sets its ordinates to the specific values passed in.
Rect(Rect r)
          Copy constructor.
 
Method Summary
 Rect clip(Rect this_rect, Rect that_rect)
           
 Rect clipAdjust(Rect this_rect, Rect that_rect, int deltaX, int deltaY)
           
 boolean contains(int x, int y)
          Returns whether or not a rectangle envelopes a specific point
 boolean contains(Point p)
           
 boolean contains(Rect r)
           
 boolean equals(Rect r)
           
 int getHeight()
          Returns the height of a rectangle
 int getWidth()
          Returns the width of a rectangle
 void inset(int delta)
           
 void inset(int deltax, int deltay)
          Adjusts all the sides of a rectangle by a given horizontal and vertical amount
 Rect intersection(Rect inR, Rect outResult)
           
 boolean intersects(int inLeft, int inTop, int inRight, int inBottom)
           
 boolean intersects(Rect rect)
          Returns whether or not a rectangle intersects another rectangle
 boolean isEmpty()
           
static Rect newXYWH(int left, int top, int width, int height)
          "Constructor" which creates a new rectangle and sets its ordinates based on a left/top, and a width/height.
 void setPosition(int x, int y)
          Moves a rectangle to a specific horizontal and vertical position
 void setSize(int width, int height)
          Adjusts the width and height of a rectangle
 void setTo(int inLeft, int inTop, int inRight, int inBottom)
          Sets the left, top, right and bottom values of the rectangle
 void setTo(Rect inRect)
          Sets the left, top, right and bottom values of the rectangle
 java.lang.String toString()
           
 void translate(int inX, int inY)
          Move a rectangle by a specific horizontal and vertical amount
 void translate(Point inP)
          Move a rectangle by a specific horizontal and vertical amount
 void translate(Rect base, int deltaX, int deltaY)
           
 void union(Rect r)
          Sets the dimensions of this rectangle to the union of itself and the specificed second rectangle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

left

public int left
Contains the values of the four sides of the rectangle Do not change the order of these; native code depends on it!

top

public int top
Contains the values of the four sides of the rectangle Do not change the order of these; native code depends on it!

right

public int right
Contains the values of the four sides of the rectangle Do not change the order of these; native code depends on it!

bottom

public int bottom
Contains the values of the four sides of the rectangle Do not change the order of these; native code depends on it!
Constructor Detail

Rect

public Rect(Rect r)
Copy constructor. Creates a new rectangle object and sets its values to the match those of the provided rectangle.
Parameters:
r - the source rectangle to be used for the values of the new rectangle

Rect

public Rect()
Generic constructor. Creates a new rectangle and sets all of its ordinates to zero.

Rect

public Rect(int width,
            int height)
Construct which creates a zero-based rectangle with a specific width and height.
Parameters:
width - value for the right side of the rect
height - value for the bottom of the rect

Rect

public Rect(int left,
            int top,
            int right,
            int bottom)
Constructor which creates a new rectangle and sets its ordinates to the specific values passed in.
Parameters:
left - value for the left side of the rect
top - value for the top of the rect
right - value for the right side of the rect
bottom - value for the bottom of the rect
Method Detail

newXYWH

public static Rect newXYWH(int left,
                           int top,
                           int width,
                           int height)
"Constructor" which creates a new rectangle and sets its ordinates based on a left/top, and a width/height.
Parameters:
left - value for the left side of the rect
top - value for the top of the rect
width - value for the width of the rect
height - value for the height of the rect
Returns:
non-null; an appropriately-constructed instance

translate

public final void translate(int inX,
                            int inY)
Move a rectangle by a specific horizontal and vertical amount
Parameters:
inX - distance to move the rect horizontally
inY - distance to move the rect vertically

translate

public final void translate(Point inP)
Move a rectangle by a specific horizontal and vertical amount
Parameters:
inP - distance to move the rect horizontally

translate

public final void translate(Rect base,
                            int deltaX,
                            int deltaY)

union

public final void union(Rect r)
Sets the dimensions of this rectangle to the union of itself and the specificed second rectangle.
Parameters:
r - the rectangle to union with the current rect

clip

public final Rect clip(Rect this_rect,
                       Rect that_rect)

clipAdjust

public final Rect clipAdjust(Rect this_rect,
                             Rect that_rect,
                             int deltaX,
                             int deltaY)

setPosition

public final void setPosition(int x,
                              int y)
Moves a rectangle to a specific horizontal and vertical position
Parameters:
x - new horizontal position for the rect
y - new vertical position for the rect

setSize

public final void setSize(int width,
                          int height)
Adjusts the width and height of a rectangle
Parameters:
width - new width for the rect
height - new height for the rect

setTo

public final void setTo(Rect inRect)
Sets the left, top, right and bottom values of the rectangle
Parameters:
inRect - rectangle to grab new values from

setTo

public final void setTo(int inLeft,
                        int inTop,
                        int inRight,
                        int inBottom)
Sets the left, top, right and bottom values of the rectangle
Parameters:
inLeft - new value for left field
inTop - new value for top field
inRight - new value for right field
inBottom - new value for bottom field

inset

public final void inset(int deltax,
                        int deltay)
Adjusts all the sides of a rectangle by a given horizontal and vertical amount
Parameters:
deltax - amount to move in the left and right sides of the rect
deltay - amount to move in the top and bottom of the rect

inset

public final void inset(int delta)

getWidth

public final int getWidth()
Returns the width of a rectangle
Returns:
the width of the rectangle

getHeight

public final int getHeight()
Returns the height of a rectangle
Returns:
the height of the rectangle

contains

public final boolean contains(int x,
                              int y)
Returns whether or not a rectangle envelopes a specific point
Parameters:
x - the horizontal offset of the point being checked
y - the vertical offset of the point being checked

contains

public final boolean contains(Point p)

contains

public final boolean contains(Rect r)

intersects

public final boolean intersects(Rect rect)
Returns whether or not a rectangle intersects another rectangle
Parameters:
rect - the rectangle being compared against

intersects

public final boolean intersects(int inLeft,
                                int inTop,
                                int inRight,
                                int inBottom)

intersection

public final Rect intersection(Rect inR,
                               Rect outResult)

isEmpty

public final boolean isEmpty()

equals

public final boolean equals(Rect r)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Danger Confidential. Copyright © 2000-2003, Danger Inc.