Struct Rect
2D rectangle
Constructors
| Name | Description |
this
(x0, y0, x1, y1)
|
constructs rectangle using left, top, right, bottom coordinates
|
this
(pt0, pt1)
|
constructs rectangle using two points - (left, top), (right, bottom) coordinates
|
Fields
| Name | Type | Description |
bottom
|
int | y coordinate of bottom right corner (non-inclusive)
|
left
|
int | x coordinate of top left corner
|
right
|
int | x coordinate of bottom right corner (non-inclusive)
|
top
|
int | y coordinate of top left corner
|
Properties
| Name | Type | Description |
bottomLeft[get]
|
Point | returns bottom left point of rectangle
|
bottomRight[get]
|
Point | returns bottom right point of rectangle
|
empty[get]
|
bool | returns true if rectangle is empty (right <= left || bottom <= top)
|
height[get]
|
int | returns height of rectangle (bottom - top)
|
middle[get]
|
Point | returns middle point
|
middlex[get]
|
int | returns average of left, right
|
middley[get]
|
int | returns average of top, bottom
|
size[get]
|
Point | returns size (width, height) in Point
|
topLeft[get]
|
Point | returns top left point of rectangle
|
topRight[get]
|
Point | returns top right point of rectangel
|
width[get]
|
int | returns width of rectangle (right - left)
|
Methods
| Name | Description |
expand
(dx, dy)
|
expand rectangle dimensions
|
intersect
(rc)
|
updates this rect to intersection with rc, returns true if result is non empty
|
intersects
(rc)
|
returns true if this rect has nonempty intersection with rc
|
isInsideOf
(rc)
|
this rectangle is completely inside rc
|
isPointInside
(pt)
|
returns true if point is inside of this rectangle
|
moveToFit
(rc)
|
moves this rect to fit rc bounds, retaining the same size
|
offset
(dx, dy)
|
add offset to horizontal and vertical coordinates
|
opEquals
(rc)
|
|
setMax
(rc)
|
for all fields, sets this.field to rc.field if rc.field > this.field
|
shrink
(dx, dy)
|
shrink rectangle dimensions
|
Aliases
| Name | Description |
moveBy
|
translate rectangle coordinates by (x,y) - add deltax to x coordinates, and deltay to y coordinates
|
Note
Rect(0,0,20,10) size is 20x10 -- right and bottom sides are non-inclusive -- if you draw such rect, rightmost drawn pixel will be x=19 and bottom pixel y=9