org.openmali.types.twodee
Class Rect2i

java.lang.Object
  extended by org.openmali.types.twodee.Rect2i
All Implemented Interfaces:
Positioned2i, Positioned2iRO, Sized2i, Sized2iRO
Direct Known Subclasses:
ExtRect2i

public class Rect2i
extends java.lang.Object
implements Positioned2i, Sized2i

A basic 2-dimensional rectangle.


Field Summary
protected  boolean isDirty
           
 
Constructor Summary
Rect2i()
          Creates a new 2-dimensional rectangle with zero position and size.
Rect2i(int left, int top, int width, int height)
          Creates a new 2-dimensional rectangle.
Rect2i(Rect2i template)
          Creates a new 2-dimensional rectangle and copies the template's coordinates.
 
Method Summary
 Rect2i clamp(int left, int top, int width, int height)
          Clamps this rectangle by the given one and writes the result into this instance.
 Rect2i clamp(Rect2i rect)
          Clamps this rectangle by the given one and writes the result into this instance.
 Rect2i combine(int left, int top, int width, int height)
          Combines this Rectangle with the given one and writes the result into this instance.
 Rect2i combine(Rect2i rect)
          Combines this Rectangle with the given one and writes the result into this instance.
 boolean covers(int left, int top, int width, int height)
          Checks, whether this rectangle completely covers the given one.
 boolean covers(Rect2i rect)
          Checks, whether this rectangle completely covers the given one.
 boolean equals(java.lang.Object o)
          
 boolean equals(Rect2i rect)
           
static Rect2i fromPool()
           
static Rect2i fromPool(int left, int top, int width, int height)
           
 int getArea()
           
 float getAspect()
          
 int getHeight()
           
 int getLeft()
           
 Tuple2i getLocation()
           
 int getMatchFactor(int left, int top, int width, int height)
           
 int getMatchFactor(Rect2i rect)
           
 int getTop()
           
 int getWidth()
           
 boolean intersects(int left, int top, int width, int height)
          Checks, if the given rectangle intersects this rectangle.
 boolean intersects(Rect2i rect)
          Checks, if the given rectangle intersects this rectangle.
 boolean isCoveredBy(int left, int top, int width, int height)
          Checks, whether this rectangle is completely covered by the given one.
 boolean isCoveredBy(Rect2i rect)
          Checks, whether this rectangle is completely covered by the given one.
 boolean isDirty()
           
 Rect2i set(int left, int top, int width, int height)
          Sets this rectangle's coordinates to the given rectangle's ones.
 Rect2i set(Positioned2iRO pos, Sized2iRO size)
          Sets this rectangle's coordinates to the given rectangle's ones.
 Rect2i set(Rect2i rect)
          Sets this rectangle's coordinates to the given rectangle's ones.
 void setClean()
          Marks this object as not dirty.
 void setHeight(int height)
          Sets the height.
 Rect2i setLocation(int left, int top)
          Sets the upper-left corner's coordinates.
 Rect2i setLocation(Tuple2i upperLeft)
          Sets the upper-left corner's coordinates.
 Rect2i setSize(int width, int height)
          Sets the size.
 Rect2i setSize(Sized2iRO size)
          Sets the size.
 Rect2i setSize(Tuple2i size)
          Sets the size.
 void setWidth(int width)
          Sets the width.
static void toPool(Rect2i rect)
           
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

isDirty

protected boolean isDirty
Constructor Detail

Rect2i

public Rect2i(int left,
              int top,
              int width,
              int height)
Creates a new 2-dimensional rectangle.

Parameters:
left - the upper-left corner's x-coordinate
top - the upper-left corner's y-coordinate
width - the rectangle's width
height - the rectangle's height

Rect2i

public Rect2i(Rect2i template)
Creates a new 2-dimensional rectangle and copies the template's coordinates.

Parameters:
template -

Rect2i

public Rect2i()
Creates a new 2-dimensional rectangle with zero position and size.

Method Detail

isDirty

public final boolean isDirty()
Returns:
true, if this object has been modified since the last setClean() call.
See Also:
setClean()

setClean

public void setClean()
Marks this object as not dirty.


setLocation

public Rect2i setLocation(int left,
                          int top)
Sets the upper-left corner's coordinates.

Specified by:
setLocation in interface Positioned2i
Parameters:
left -
top -
Returns:
true, if the location actually has changed

setLocation

public final Rect2i setLocation(Tuple2i upperLeft)
Sets the upper-left corner's coordinates.

Specified by:
setLocation in interface Positioned2i
Parameters:
upperLeft -
Returns:
true, if the location actually has changed

getLocation

public final Tuple2i getLocation()
Specified by:
getLocation in interface Positioned2iRO
Returns:
the upper-left corner's coordinates

getLeft

public final int getLeft()
Specified by:
getLeft in interface Positioned2iRO
Returns:
the upper-left corner's x-coordinate

getTop

public final int getTop()
Specified by:
getTop in interface Positioned2iRO
Returns:
the upper-left corner's y-coordinate

setSize

public Rect2i setSize(int width,
                      int height)
Sets the size.

Specified by:
setSize in interface Sized2i
Returns:
this instance back again.

setWidth

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

Specified by:
setWidth in interface Sized2i

setHeight

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

Specified by:
setHeight in interface Sized2i

getWidth

public final int getWidth()
Specified by:
getWidth in interface Sized2iRO
Returns:
the rectangle's width

getHeight

public final int getHeight()
Specified by:
getHeight in interface Sized2iRO
Returns:
the rectangle's height

getAspect

public final float getAspect()

Specified by:
getAspect in interface Sized2iRO
Returns:
the aspect ratio calculated by (getWidth() / getHeight()). If getHeight() is 0, 0 is returned.

getArea

public final int getArea()
Returns:
the area-size of this rectangle.

setSize

public final Rect2i setSize(Sized2iRO size)
Sets the size.

Specified by:
setSize in interface Sized2i
Returns:
this instance back again.

setSize

public final Rect2i setSize(Tuple2i size)
Sets the size.

Specified by:
setSize in interface Sized2i
Returns:
this instance back again.

set

public final Rect2i set(int left,
                        int top,
                        int width,
                        int height)
Sets this rectangle's coordinates to the given rectangle's ones.

Parameters:
left - the upper-left corner's x-coordinate
top - the upper-left corner's y-coordinate
width - the rectangle's width
height - the rectangle's height

set

public final Rect2i set(Positioned2iRO pos,
                        Sized2iRO size)
Sets this rectangle's coordinates to the given rectangle's ones.

Parameters:
pos -
size -

set

public final Rect2i set(Rect2i rect)
Sets this rectangle's coordinates to the given rectangle's ones.

Parameters:
rect -

isCoveredBy

public final boolean isCoveredBy(int left,
                                 int top,
                                 int width,
                                 int height)
Checks, whether this rectangle is completely covered by the given one.

Parameters:
left -
top -
width -
height -
Returns:
true, if the given rectangle completely covers this rectangle.

isCoveredBy

public final boolean isCoveredBy(Rect2i rect)
Checks, whether this rectangle is completely covered by the given one.

Parameters:
rect -
Returns:
true, if the given rectangle completely covers this rectangle.

covers

public final boolean covers(int left,
                            int top,
                            int width,
                            int height)
Checks, whether this rectangle completely covers the given one.

Parameters:
left -
top -
width -
height -
Returns:
true, if this rectangle completely covers the given rectangle.

covers

public final boolean covers(Rect2i rect)
Checks, whether this rectangle completely covers the given one.

Parameters:
rect -
Returns:
true, if this rectangle completely covers the given rectangle.

getMatchFactor

public final int getMatchFactor(int left,
                                int top,
                                int width,
                                int height)
Parameters:
left -
top -
width -
height -
Returns:
the sum of area-size of the parts of this rectangle, that overlap the given one.

getMatchFactor

public final int getMatchFactor(Rect2i rect)
Parameters:
left -
top -
width -
height -
Returns:
the sum of area-size of the parts of this rectangle, that overlap the given one.

intersects

public final boolean intersects(int left,
                                int top,
                                int width,
                                int height)
Checks, if the given rectangle intersects this rectangle.

Parameters:
left -
top -
width -
height -
Returns:
true, if the two rectangles intersect.

intersects

public final boolean intersects(Rect2i rect)
Checks, if the given rectangle intersects this rectangle.

Parameters:
rect -
Returns:
true, if the two rectangles intersect.

combine

public Rect2i combine(int left,
                      int top,
                      int width,
                      int height)
Combines this Rectangle with the given one and writes the result into this instance.

Parameters:
left -
top -
width -
height -
Returns:
this instance.

combine

public final Rect2i combine(Rect2i rect)
Combines this Rectangle with the given one and writes the result into this instance.

Parameters:
rect -
Returns:
this instance.

clamp

public Rect2i clamp(int left,
                    int top,
                    int width,
                    int height)
Clamps this rectangle by the given one and writes the result into this instance.

Parameters:
left -
top -
width -
height -
Returns:
this instance.

clamp

public final Rect2i clamp(Rect2i rect)
Clamps this rectangle by the given one and writes the result into this instance.

Parameters:
rect -
Returns:
this instance.

equals

public boolean equals(Rect2i rect)

equals

public boolean equals(java.lang.Object o)

Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

fromPool

public static final Rect2i fromPool()

fromPool

public static final Rect2i fromPool(int left,
                                    int top,
                                    int width,
                                    int height)

toPool

public static final void toPool(Rect2i rect)