Rectangle class provides static functions to create and operate on rectangles. A rectangle is usually represented as a Group of 2 Pts, marking the top-left and bottom-right corners of the rectangle.
You can use the static functions as-is, or apply the Group.op
or Pt.op
to enable functional programming.
See Op guide for details.
Given an array of rectangles, get a rectangle that bounds all of them.
an array of (Groups or Iterables
the bounding rectangle as a Group
Get the 4 corners of this rectangle as a Group.
a Group or an Iterable
Create a rectangle from top-left anchor point. Same as Rectangle.fromTopLeft
.
top-left point
width as a number, or a Pt that defines its size
optional height as a number
a Group of 2 Pts representing a rectangle
Create a rectangle given a center position and a size.
width as a number, or a Pt that defines its size
optional height as a number
a Group of 2 Pts representing a rectangle
Create a rectangle given a top-left position and a size.
top-left point
width as a number, or a Pt that defines its size
optional height as a number
a Group of 2 Pts representing a rectangle
Subdivde a rectangle into 2 rectangles, by row or by column.
a Group or an Iterable
a value between 0 to 1 to indicate the split ratio
if true
, split into 2 rows. Default is false
which splits into 2 columns.
an array of 2 Groups of rectangles
Check if a rectangle is within the bounds of another rectangle.
a Group of 2 Pts representing a rectangle
a Group of 2 Pts representing a rectangle
if true
, reset the bounding box. Default is false
which assumes the rect's first Pt at is its top-left corner.
An easy way to get rectangle-rectangle intersection points. For more optimized implementation, store the rectangle's sides separately (eg, Rectangle.sides()
) and use Polygon.intersectPolygon2D()
.
a Group of 2 Pts representing a rectangle
a Group of 2 Pts representing a rectangle
Convert this rectangle into a Group representing a polygon. An alias for Rectangle.corners
a Group or an Iterable
Subdivide a rectangle into 4 rectangles, one for each quadrant.
a Group or an Iterable
an array of 4 Groups of rectangles
Get the 4 sides of this rectangle as an array of 4 Groups.
a Group or an Iterable
an array of 4 Groups, each of which represents a line segment
Create a new circle that either fits within or encloses the rectangle. Same as Circle.fromRect
.
a Group or an Iterable
if true
, the circle will be within the rectangle. If false
, the circle will enclose the rectangle.
a Group that represents a circle
Create a square that either fits within or encloses a rectangle.
a Group or an Iterable
if true
, the square will enclose the rectangle. Default is false
, which will fit the square inside the rectangle.
a Group of 2 Pts representing a rectangle
Check if a point is within a rectangle.
a Group of 2 Pts representing a Rectangle
the point to check