Rect

2D rectangle 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

Constructors

this
this(int x0, int y0, int x1, int y1)

constructs rectangle using left, top, right, bottom coordinates

this
this(Point pt0, Point pt1)

constructs rectangle using two points - (left, top), (right, bottom) coordinates

Members

Aliases

moveBy
alias moveBy = offset

translate rectangle coordinates by (x,y) - add deltax to x coordinates, and deltay to y coordinates

Functions

expand
void expand(int dx, int dy)

expand rectangle dimensions

intersect
bool intersect(Rect rc)

updates this rect to intersection with rc, returns true if result is non empty

intersects
bool intersects(Rect rc)

returns true if this rect has nonempty intersection with rc

isInsideOf
bool isInsideOf(Rect rc)

this rectangle is completely inside rc

isPointInside
bool isPointInside(Point pt)

returns true if point is inside of this rectangle

isPointInside
bool isPointInside(int x, int y)

returns true if point is inside of this rectangle

moveToFit
void moveToFit(Rect rc)

moves this rect to fit rc bounds, retaining the same size

offset
void offset(int dx, int dy)

add offset to horizontal and vertical coordinates

opEquals
bool opEquals(Rect rc)
Undocumented in source. Be warned that the author may not have intended to support it.
setMax
void setMax(Rect rc)

for all fields, sets this.field to rc.field if rc.field > this.field

shrink
void shrink(int dx, int dy)

shrink rectangle dimensions

Properties

bottomLeft
Point bottomLeft [@property getter]

returns bottom left point of rectangle

bottomRight
Point bottomRight [@property getter]

returns bottom right point of rectangle

empty
bool empty [@property getter]

returns true if rectangle is empty (right <= left || bottom <= top)

height
int height [@property getter]

returns height of rectangle (bottom - top)

middle
Point middle [@property getter]

returns middle point

middlex
int middlex [@property getter]

returns average of left, right

middley
int middley [@property getter]

returns average of top, bottom

size
Point size [@property getter]

returns size (width, height) in Point

topLeft
Point topLeft [@property getter]

returns top left point of rectangle

topRight
Point topRight [@property getter]

returns top right point of rectangel

width
int width [@property getter]

returns width of rectangle (right - left)

Variables

bottom
int bottom;

y coordinate of bottom right corner (non-inclusive)

left
int left;

x coordinate of top left corner

right
int right;

x coordinate of bottom right corner (non-inclusive)

top
int top;

y coordinate of top left corner

Meta