public class Rectangle2D
- Object
- Rectangle2D
ImplementsShape
Represents a Rectangle position (x, y) and
Dimension (width, height),
this is useful for measuring coordinates within the application.Constructors
public Rectangle2D() | Creates a new instance of Rectangle |
public Rectangle2D(double x, double y, Dimension2D size) | Creates a new instance of Rectangle at position (x, y) and with predefine dimension |
public Rectangle2D(double x, double y, double w, double h) | Creates a new instance of Rectangle at position (x, y) and with predefine width and height |
public Rectangle2D(Rectangle2D rect) | A copy Constructor |
Methods
public static boolean contains(double x1, double y1, double w1, double h1, double x2, double y2, double w2, double h2) | Checks wheather the 2nd rectangle is contained in the first rectangle |
public static void intersection(double rrX, double rrY, double rrW, double rrH, double rtx1, double rty1, double rtw2, double rth2, Rectangle2D dest) | Returns a rectangle that intersects the given rectangle with this rectangle |
public static boolean intersects(double tx, double ty, double tw, double th, double x, double y, double width, double height) | Helper method allowing us to determine if two coordinate sets intersect. |
public void setBounds(double x, double y, double w, double h) | Helper method to set coordinates |
public double getWidth() | Convenience method for getSize().getWidth(); |
public void setWidth(double w) | Convenience method for getSize().setWidth(); |
public double getHeight() | Convenience method for getSize().getHeight(); |
public void setHeight(double h) | Convenience method for getSize().setHeight(); |
public Dimension2D getSize() | Return the dimension of the rectangle |
public double getX() | Return the x coordinate of the rectangle |
public void setX(int x) | Sets the x position of the rectangle |
public void setX(double x) | Sets the x position of the rectangle as a double. |
public double getY() | Return the y coordinate of the rectangle |
public void setY(int y) | Sets the y position of the rectangle |
public void setY(double y) | Sets the y position of the rectangle as a double. |
public String toString() | Returns a string representation of the object. |
public boolean contains(Rectangle2D rect) | Checks whether or not this Rectangle entirely contains the specified Rectangle. |
public boolean contains(double rX, double rY, double rWidth, double rHeight) | Checks whether this Rectangle entirely contains the Rectangle at the specified location (rX, rY) with the specified dimensions (rWidth, rHeight). |
public boolean contains(double rX, double rY) | Checks whether or not this Rectangle contains the point at the specified location (rX, rY). |
public Rectangle2D intersection(double rX, double rY, double rW, double rH) | Returns a rectangle that intersects the given rectangle with this rectangle |
public Rectangle2D intersection(Rectangle2D r) | Returns a rectangle that intersects the given rectangle with this rectangle |
public boolean intersects(double x, double y, double width, double height) | Determines whether or not this Rectangle and the specified Rectangle location (x, y) with the specified dimensions (width, height), intersect. |
public boolean intersects(Rectangle2D 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 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 contains(int x, int y) | Checks if the shape contains the given point. |
public Shape intersection(Rectangle rect) | Returns the shape formed by the intersection of this shape and the provided rectangle. |
public void translate(double x, double y) |
Inherited methods
Constructor details
Rectangle2D
public Rectangle2D()Creates a new instance of Rectangle
Rectangle2D
public Rectangle2D(double x, double y, Dimension2D size)Creates a new instance of Rectangle at position (x, y) and with
predefine dimension
Parameters
xdouble- the x coordinate of the rectangle
ydouble- the y coordinate of the rectangle
sizeDimension2D- the
Dimensionof the rectangle
Rectangle2D
public Rectangle2D(double x, double y, double w, double h)Creates a new instance of Rectangle at position (x, y) and with
predefine width and height
Parameters
xdouble- the x coordinate of the rectangle
ydouble- the y coordinate of the rectangle
wdouble- the width of the rectangle
hdouble- the height of the rectangle
Rectangle2D
public Rectangle2D(Rectangle2D rect)A copy Constructor
Parameters
rectRectangle2D- the Rectangle to copy
Method details
contains
public static boolean contains(double x1, double y1, double w1, double h1, double x2, double y2, double w2, double h2)Checks wheather the 2nd rectangle is contained in the first rectangle
Parameters
x1double- first rect x
y1double- first rect y
w1double- first rect w
h1double- first rect h
x2double- second rect x
y2double- second rect y
w2double- second rect w
h2double- second rect h
Returns
true if x2, y2, w2, h2 is contained in x1, y1, w1, h1
intersection
public static void intersection(double rrX, double rrY, double rrW, double rrH, double rtx1, double rty1, double rtw2, double rth2, Rectangle2D dest)Returns a rectangle that intersects the given rectangle with this rectangle
Parameters
rrXdouble- rectangle to intersect with this rectangle
rrYdouble- rectangle to intersect with this rectangle
rrWdouble- rectangle to intersect with this rectangle
rrHdouble- rectangle to intersect with this rectangle
rtx1double- rectangle to intersect with this rectangle
rty1double- rectangle to intersect with this rectangle
rtw2double- rectangle to intersect with this rectangle
rth2double- rectangle to intersect with this rectangle
destRectangle2D- result of the intersection are stored here
intersects
public static boolean intersects(double tx, double ty, double tw, double th, double x, double y, double width, double 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
txdouble- x of first rectangle
tydouble- y of first rectangle
twdouble- width of first rectangle
thdouble- height of first rectangle
xdouble- x of second rectangle
ydouble- y of second rectangle
widthdouble- width of second rectangle
heightdouble- height of second rectangle
Returns
true if the rectangles intersect
setBounds
public void setBounds(double x, double y, double w, double h)Helper method to set coordinates
getWidth
public double getWidth()Convenience method for getSize().getWidth();
Returns
width
setWidth
public void setWidth(double w)Convenience method for getSize().setWidth();
Parameters
wdouble- the width
getHeight
public double getHeight()Convenience method for getSize().getHeight();
Returns
height
setHeight
public void setHeight(double h)Convenience method for getSize().setHeight();
Parameters
hdouble- the height
getSize
public Dimension2D getSize()Return the dimension of the rectangle
Returns
the size of the rectangle
getX
public double 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
setX
public void setX(double x)Sets the x position of the rectangle as a double.
getY
public double 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
setY
public void setY(double y)Sets the y position of the rectangle as a double.
Parameters
ydouble- The y position
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(Rectangle2D rect)Checks whether or not this Rectangle entirely contains the specified
Rectangle.
Parameters
rectRectangle2D- the specified Rectangle
Returns
true if the Rectangle is contained entirely inside this
Rectangle; false otherwise
contains
public boolean contains(double rX, double rY, double rWidth, double rHeight)Checks whether this Rectangle entirely contains the Rectangle
at the specified location (rX, rY) with the specified
dimensions (rWidth, rHeight).
Parameters
rXdouble- the specified x coordinate
rYdouble- the specified y coordinate
rWidthdouble- the width of the Rectangle
rHeightdouble- 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(double rX, double rY)Checks whether or not this Rectangle contains the point at the specified
location (rX, rY).
Parameters
rXdouble- the specified x coordinate
rYdouble- the specified y coordinate
Returns
true if the point (rX, rY) is inside this Rectangle;
false otherwise.
intersection
public Rectangle2D intersection(double rX, double rY, double rW, double rH)Returns a rectangle that intersects the given rectangle with this rectangle
Parameters
rXdouble- rectangle to intersect with this rectangle
rYdouble- rectangle to intersect with this rectangle
rWdouble- rectangle to intersect with this rectangle
rHdouble- rectangle to intersect with this rectangle
Returns
the intersection
intersection
public Rectangle2D intersection(Rectangle2D r)Returns a rectangle that intersects the given rectangle with this rectangle
Parameters
rRectangle2D- rectangle to intersect with this rectangle
Returns
the intersection
intersects
public boolean intersects(double x, double y, double width, double 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
xdouble- the specified x coordinate
ydouble- the specified y coordinate
widthdouble- the width of the Rectangle
heightdouble- the height of the Rectangle
Returns
true if the specified Rectangle and this Rectangle intersect;
false otherwise.
intersects
public boolean intersects(Rectangle2D 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
rectRectangle2D- 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.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.
contains
public boolean contains(int x, int y)Checks if the shape contains the given point.
Parameters
xint- The x-coordinate of the point to test.
yint- The y-coordinate of the point to test.
Returns
True if (x, y) is inside the shape.
intersection
public Shape intersection(Rectangle rect)Returns the shape formed by the intersection of this shape and the provided
rectangle.
Parameters
rectRectangle- A rectangle with which to form an intersection.
Returns
The shape formed by intersecting the current shape with the provided rectangle.
translate
public void translate(double x, double y)