Class Rectangle2D
- All Implemented Interfaces:
Shape
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of RectangleRectangle2D(double x, double y, double w, double h) Creates a new instance of Rectangle at position (x, y) and with predefine width and heightRectangle2D(double x, double y, Dimension2D size) Creates a new instance of Rectangle at position (x, y) and with predefine dimensionRectangle2D(Rectangle2D rect) A copy Constructor -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(double rX, double rY) Checks whether or not this Rectangle contains the point at the specified location (rX, rY).booleancontains(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).static booleancontains(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 rectanglebooleancontains(int x, int y) Checks if the shape contains the given point.booleancontains(Rectangle2D rect) Checks whether or not this Rectangle entirely contains the specified Rectangle.{Returns the bounding rectangle for the shape.float[]{Gets the bounds of the shape as a 4-element array representing the (x,y,width,height) tuple.doubleConvenience method for getSize().getHeight();{Gets an iterator to walk all of the path segments of the shape.{Gets an iterator where all points are transformed by the provided transform.getSize()Return the dimension of the rectangledoublegetWidth()Convenience method for getSize().getWidth();doublegetX()Return the x coordinate of the rectangledoublegetY()Return the y coordinate of the rectangleintersection(double rX, double rY, double rW, double rH) Returns a rectangle that intersects the given rectangle with this rectanglestatic voidintersection(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 rectangleintersection(Rectangle rect) Returns the shape formed by the intersection of this shape and the provided rectangle.Returns a rectangle that intersects the given rectangle with this rectanglebooleanintersects(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.static booleanintersects(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.booleanintersects(Rectangle2D rect) Determines whether or not this Rectangle and the specified Rectangle location (x, y) with the specified dimensions (width, height), intersect.boolean{Checks if this shape is a rectangle.voidsetBounds(double x, double y, double w, double h) Helper method to set coordinatesvoidsetHeight(double h) Convenience method for getSize().setHeight();voidsetWidth(double w) Convenience method for getSize().setWidth();voidsetX(double x) Sets the x position of the rectangle as a double.voidsetX(int x) Sets the x position of the rectanglevoidsetY(double y) Sets the y position of the rectangle as a double.voidsetY(int y) Sets the y position of the rectangletoString()voidtranslate(double x, double y)
-
Constructor Details
-
Rectangle2D
public Rectangle2D()Creates a new instance of Rectangle -
Rectangle2D
Creates a new instance of Rectangle at position (x, y) and with predefine dimension
Parameters
-
x: the x coordinate of the rectangle -
y: the y coordinate of the rectangle -
size: theDimensionof 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
-
x: the x coordinate of the rectangle -
y: the y coordinate of the rectangle -
w: the width of the rectangle -
h: the height of the rectangle
-
-
Rectangle2D
A copy Constructor
Parameters
rect: 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
-
x1: first rect x -
y1: first rect y -
w1: first rect w -
h1: first rect h -
x2: second rect x -
y2: second rect y -
w2: second rect w -
h2: 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
-
rrX: rectangle to intersect with this rectangle -
rrY: rectangle to intersect with this rectangle -
rrW: rectangle to intersect with this rectangle -
rrH: rectangle to intersect with this rectangle -
rtx1: rectangle to intersect with this rectangle -
rty1: rectangle to intersect with this rectangle -
rtw2: rectangle to intersect with this rectangle -
rth2: rectangle to intersect with this rectangle -
dest: 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
-
tx: x of first rectangle -
ty: y of first rectangle -
tw: width of first rectangle -
th: height of first rectangle -
x: x of second rectangle -
y: y of second rectangle -
width: width of second rectangle -
height: 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
w: 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
h: the height
-
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
x: the x coordinate of the rectangle
-
setX
public void setX(double x) Sets the x position of the rectangle as a double.
Parameters
x
-
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
y: the y coordinate of the rectangle
-
setY
public void setY(double y) Sets the y position of the rectangle as a double.
Parameters
y: The y position
-
toString
-
contains
Checks whether or not this Rectangle entirely contains the specified Rectangle.
Parameters
rect: the specified Rectangle
Returns
- 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
-
rX: the specified x coordinate -
rY: the specified y coordinate -
rWidth: the width of the Rectangle -
rHeight: the height of the Rectangle
Returns
- 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
-
rX: the specified x coordinate -
rY: the specified y coordinate
Returns
- Returns:
- true if the point (rX, rY) is inside this Rectangle; false otherwise.
-
-
intersection
Returns a rectangle that intersects the given rectangle with this rectangle
Parameters
-
rX: rectangle to intersect with this rectangle -
rY: rectangle to intersect with this rectangle -
rW: rectangle to intersect with this rectangle -
rH: rectangle to intersect with this rectangle
Returns
the intersection
-
-
intersection
Returns a rectangle that intersects the given rectangle with this rectangle
Parameters
r: 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
-
x: the specified x coordinate -
y: the specified y coordinate -
width: the width of the Rectangle -
height: the height of the Rectangle
Returns
- Returns:
- true if the specified Rectangle and this Rectangle intersect; false otherwise.
-
-
intersects
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
rect: the Rectangle to check intersection with
Returns
- Returns:
- true if the specified Rectangle and this Rectangle intersect; false otherwise.
-
getPathIterator
{
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.Parameters
transform
Returns
A PathIterator where points are transformed by the provided transform.
}- Specified by:
getPathIteratorin interfaceShape
-
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.
}- Specified by:
getPathIteratorin interfaceShape
-
getBounds
-
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.
}- Specified by:
getBounds2Din interfaceShape
-
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.
}- Specified by:
isRectanglein interfaceShape
-
contains
public boolean contains(int x, int y) Description copied from interface:ShapeChecks if the shape contains the given point.
Parameters
-
x: The x-coordinate of the point to test. -
y: The y-coordinate of the point to test.
Returns
True if (x, y) is inside the shape.
-
-
intersection
Description copied from interface:ShapeReturns the shape formed by the intersection of this shape and the provided rectangle.
Parameters
rect: A rectangle with which to form an intersection.
Returns
The shape formed by intersecting the current shape with the provided rectangle.
- Specified by:
intersectionin interfaceShape
-
translate
public void translate(double x, double y)
-