public class Rectangle
- Object
- Rectangle
ImplementsShape
Represents a Rectangle position (x, y) and
Dimension (width, height),
this is useful for measuring coordinates within the application.Constructors
public Rectangle() | Creates a new instance of Rectangle |
public Rectangle(int x, int y, Dimension size) | Creates a new instance of Rectangle at position (x, y) and with predefine dimension |
public Rectangle(int x, int y, int w, int h) | Creates a new instance of Rectangle at position (x, y) and with predefine width and height |
public Rectangle(Rectangle rect) | A copy Constructor |
Methods
public static synchronized Rectangle createFromPool(int x, int y, int w, int h) | Creates a rectangle from a Rectangle object pool. |
public static synchronized void recycle(Rectangle r) | Returns the given rectangle to the object pool. |
public static boolean contains(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) | Checks wheather the 2nd rectangle is contained in the first rectangle |
public static void intersection(int rrX, int rrY, int rrW, int rrH, int rtx1, int rty1, int rtw2, int rth2, Rectangle dest) | Returns a rectangle that intersects the given rectangle with this rectangle |
public static boolean intersects(int tx, int ty, int tw, int th, int x, int y, int width, int height) | Helper method allowing us to determine if two coordinate sets intersect. |
public void setBounds(int x, int y, int w, int h) | Helper method to set coordinates |
public int getWidth() | Convenience method for getSize().getWidth(); |
public void setWidth(int w) | Convenience method for getSize().setWidth(); |
public int getHeight() | Convenience method for getSize().getHeight(); |
public void setHeight(int h) | Convenience method for getSize().setHeight(); |
public Dimension getSize() | Return the dimension of the rectangle |
public int getX() | Return the x coordinate of the rectangle |
public void setX(int x) | Sets the x position of the rectangle |
public int getY() | Return the y coordinate of the rectangle |
public void setY(int y) | Sets the y position of the rectangle |
public String toString() | Returns a string representation of the object. |
public boolean contains(Rectangle rect) | Checks whether or not this Rectangle entirely contains the specified Rectangle. |
public boolean contains(int rX, int rY, int rWidth, int rHeight) | Checks whether this Rectangle entirely contains the Rectangle at the specified location (rX, rY) with the specified dimensions (rWidth, rHeight). |
public boolean contains(int rX, int rY) | Checks whether or not this Rectangle contains the point at the specified location (rX, rY). |
public Rectangle intersection(int rX, int rY, int rW, int rH) | Returns a rectangle that intersects the given rectangle with this rectangle. |
public void intersection(Rectangle input, Rectangle output) | |
public Rectangle intersection(Rectangle r) | Returns a rectangle that intersects the given rectangle with this rectangle |
public boolean intersects(int x, int y, int width, int height) | Determines whether or not this Rectangle and the specified Rectangle location (x, y) with the specified dimensions (width, height), intersect. |
public boolean intersects(Rectangle rect) | Determines whether or not this Rectangle and the specified Rectangle location (x, y) with the specified dimensions (width, height), intersect. |
public PathIterator getPathIterator(Transform m) | {Gets an iterator where all points are transformed by the provided transform. |
public PathIterator getPathIterator() | {Gets an iterator to walk all of the path segments of the shape.} |
public Rectangle getBounds() | {Returns the bounding rectangle for the shape. |
public void setBounds(Rectangle bounds) | Sets the bounds of this rectangle. |
public float[] getBounds2D() | {Gets the bounds of the shape as a 4-element array representing the (x,y,width,height) tuple.} |
public boolean isRectangle() | {Checks if this shape is a rectangle. |
public boolean equals(Object obj) | {Indicates whether some other object is “equal to” this one. |
public int hashCode() | {Returns a hash code value for the object. |
Inherited methods
Constructor details
Rectangle
public Rectangle()Creates a new instance of Rectangle
Rectangle
public Rectangle(int x, int y, Dimension size)Creates a new instance of Rectangle at position (x, y) and with
predefine dimension
Parameters
xint- the x coordinate of the rectangle
yint- the y coordinate of the rectangle
sizeDimension- the
Dimensionof the rectangle
Rectangle
public Rectangle(int x, int y, int w, int h)Creates a new instance of Rectangle at position (x, y) and with
predefine width and height
Parameters
xint- the x coordinate of the rectangle
yint- the y coordinate of the rectangle
wint- the width of the rectangle
hint- the height of the rectangle
Rectangle
public Rectangle(Rectangle rect)A copy Constructor
Parameters
rectRectangle- the Rectangle to copy
Method details
createFromPool
public static synchronized Rectangle createFromPool(int x, int y, int w, int h)Creates a rectangle from a Rectangle object pool. This is handy if you need to create a temporary Rectangle that you wish to recycle later.
When you are done with this object you should return it to the pool using
#recycle(com.codename1.ui.geom.Rectangle).
Parameters
xint- The x coordinate of the rect.
yint- The y coordinate of the rect.
wint- The width of the rect.
hint- The height of the rect.
Returns
A rectangle with the given dimensions.
recycle
public static synchronized void recycle(Rectangle r)Returns the given rectangle to the object pool.
Parameters
rRectangle- The rectangle to recycle.
contains
public static boolean contains(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)Checks wheather the 2nd rectangle is contained in the first rectangle
Parameters
x1int- first rect x
y1int- first rect y
w1int- first rect w
h1int- first rect h
x2int- second rect x
y2int- second rect y
w2int- second rect w
h2int- second rect h
Returns
true if x2, y2, w2, h2 is contained in x1, y1, w1, h1
intersection
public static void intersection(int rrX, int rrY, int rrW, int rrH, int rtx1, int rty1, int rtw2, int rth2, Rectangle dest)Returns a rectangle that intersects the given rectangle with this rectangle
Parameters
rrXint- rectangle to intersect with this rectangle
rrYint- rectangle to intersect with this rectangle
rrWint- rectangle to intersect with this rectangle
rrHint- rectangle to intersect with this rectangle
rtx1int- rectangle to intersect with this rectangle
rty1int- rectangle to intersect with this rectangle
rtw2int- rectangle to intersect with this rectangle
rth2int- rectangle to intersect with this rectangle
destRectangle- result of the intersection are stored here
intersects
public static boolean intersects(int tx, int ty, int tw, int th, int x, int y, int width, int height)Helper method allowing us to determine if two coordinate sets intersect. This saves
us the need of creating a rectangle object for a quick calculation
Parameters
txint- x of first rectangle
tyint- y of first rectangle
twint- width of first rectangle
thint- height of first rectangle
xint- x of second rectangle
yint- y of second rectangle
widthint- width of second rectangle
heightint- height of second rectangle
Returns
true if the rectangles intersect
setBounds
public void setBounds(int x, int y, int w, int h)Helper method to set coordinates
getWidth
public int getWidth()Convenience method for getSize().getWidth();
Returns
width
setWidth
public void setWidth(int w)Convenience method for getSize().setWidth();
Parameters
wint- the width
getHeight
public int getHeight()Convenience method for getSize().getHeight();
Returns
height
setHeight
public void setHeight(int h)Convenience method for getSize().setHeight();
Parameters
hint- the height
getSize
public Dimension getSize()Return the dimension of the rectangle
Returns
the size of the rectangle
getX
public int getX()Return the x coordinate of the rectangle
Returns
the x coordinate of the rectangle
setX
public void setX(int x)Sets the x position of the rectangle
Parameters
xint- the x coordinate of the rectangle
getY
public int getY()Return the y coordinate of the rectangle
Returns
the y coordinate of the rectangle
setY
public void setY(int y)Sets the y position of the rectangle
Parameters
yint- the y coordinate of the rectangle
toString
public String toString()Returns a string representation of the object. In general, the toString method returns a string that “textually represents” this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.
The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@’, and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
getClass().getName() + ‘@’ + Integer.toHexString(hashCode())
contains
public boolean contains(Rectangle rect)Checks whether or not this Rectangle entirely contains the specified
Rectangle.
Parameters
rectRectangle- the specified Rectangle
Returns
true if the Rectangle is contained entirely inside this
Rectangle; false otherwise
contains
public boolean contains(int rX, int rY, int rWidth, int rHeight)Checks whether this Rectangle entirely contains the Rectangle
at the specified location (rX, rY) with the specified
dimensions (rWidth, rHeight).
Parameters
rXint- the specified x coordinate
rYint- the specified y coordinate
rWidthint- the width of the Rectangle
rHeightint- the height of the Rectangle
Returns
true if the Rectangle specified by (rX, rY, rWidth, rHeight)
is entirely enclosed inside this Rectangle; false otherwise.
contains
public boolean contains(int rX, int rY)Checks whether or not this Rectangle contains the point at the specified
location (rX, rY).
Parameters
rXint- the specified x coordinate
rYint- the specified y coordinate
Returns
true if the point (rX, rY) is inside this Rectangle;
false otherwise.
intersection
public Rectangle intersection(int rX, int rY, int rW, int rH)Returns a rectangle that intersects the given rectangle with this rectangle. If they
don’t intersect, the resulting rectangle will have a negative width or height.
Parameters
rXint- rectangle to intersect with this rectangle
rYint- rectangle to intersect with this rectangle
rWint- rectangle to intersect with this rectangle
rHint- rectangle to intersect with this rectangle
Returns
the intersection
intersection
public void intersection(Rectangle input, Rectangle output)intersection
public Rectangle intersection(Rectangle r)Returns a rectangle that intersects the given rectangle with this rectangle
Parameters
rRectangle- rectangle to intersect with this rectangle
Returns
the intersection
intersects
public boolean intersects(int x, int y, int width, int height)Determines whether or not this Rectangle and the specified Rectangle
location (x, y) with the specified dimensions (width, height),
intersect. Two rectangles intersect if their intersection is nonempty.
Parameters
xint- the specified x coordinate
yint- the specified y coordinate
widthint- the width of the Rectangle
heightint- the height of the Rectangle
Returns
true if the specified Rectangle and this Rectangle intersect;
false otherwise.
intersects
public boolean intersects(Rectangle rect)Determines whether or not this Rectangle and the specified Rectangle
location (x, y) with the specified dimensions (width, height),
intersect. Two rectangles intersect if their intersection is nonempty.
Parameters
rectRectangle- the Rectangle to check intersection with
Returns
true if the specified Rectangle and this Rectangle intersect;
false otherwise.
getPathIterator
public PathIterator getPathIterator(Transform m){Gets an iterator where all points are transformed by the provided transform.
Note: If com.codename1.ui.Transform#isSupported() is false, then using this iterator will throw a Runtime Exception.}
Returns
A PathIterator where points are transformed by the provided transform.
getPathIterator
public PathIterator getPathIterator(){Gets an iterator to walk all of the path segments of the shape.}
Returns
A PathIterator that can iterate over the path segments of the shape.
getBounds
public Rectangle getBounds(){Returns the bounding rectangle for the shape. This should be the smallest rectangle
such that the all path segments in the shape are contained within it.}
Returns
A
Rectangle that comprises the bounds of the shape.setBounds
public void setBounds(Rectangle bounds)Sets the bounds of this rectangle.
Parameters
boundsRectangle- A rectangle whose bounds will be copied.
getBounds2D
public float[] getBounds2D(){Gets the bounds of the shape as a 4-element array representing the (x,y,width,height)
tuple.}
Returns
[x, y, width, height] bounds of this shape.
isRectangle
public boolean isRectangle(){Checks if this shape is a rectangle. A Shape is a rectangle if it is a closed quadrilateral
composed of two vertical lines and two horizontal lines. If all points have integer coordinates,
and this returns true, then getBounds() should return an equivalent rectangle to the shape itself.}
Returns
True if shape is a rectangle.
equals
public boolean equals(Object obj){Indicates whether some other object is “equal to” this one.
The equals method implements an equivalence relation: It is reflexive: for any reference value x, x.equals(x) should return true. It is symmetric: for any reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true. It is transitive: for any reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true. It is consistent: for any reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the object is modified. For any non-null reference value x, x.equals(null) should return false.
The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any reference values x and y, this method returns true if and only if x and y refer to the same object (x==y has the value true).}
hashCode
public int hashCode(){Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.
The general contract of hashCode is: Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result. It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables.
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)}