Struct RectOf

2D rectangle.

struct RectOf(T)
  
if (is(T == float) || is(T == int));

It differs from Box in that it stores coordinates of the top-left and bottom-right corners. Box is more convenient when dealing with widgets, Rect is better in drawing procedures.

Constructors

NameDescription
this (x0, y0, x1, y1) Construct a rectangle using left, top, right, bottom coordinates
this (pt0, pt1) Construct a rectangle using two points - (left, top), (right, bottom) coordinates
this (b) Construct a rectangle from a box

Fields

TypeNameDescription
T
bottom y coordinate of bottom right corner (non-inclusive)
T
left x coordinate of top left corner
T
right x coordinate of bottom right corner (non-inclusive)
T
top y coordinate of top left corner

Methods

NameDescription
bottomRight () Bottom right point
contains (rc) Returns true if rc is completely inside the rectangle
contains (pt) Returns true if pt is inside the rectangle
contains (x, y) Returns true if (x, y) point is inside the rectangle
containsX (x) Returns true if x is between left and right sides
containsY (y) Returns true if y is between top and bottom sides
empty () True if the rectangle is empty (i.e. right <= left || bottom <= top)
expand (dx, dy) Expand rectangle dimensions
from (source) Construct from a rectangle with another base type via casting
height () Height (i.e. bottom - top)
include (rc) Expand this rectangle to include rc
intersect (rc) Update this rect to intersection with rc, returns true if it's not empty after that
intersects (rc) Returns true if this rect has nonempty intersection with rc
middle () The center point
middleX () The midpoint of X side
middleY () The midpoint of Y side
moveToFit (rc) Moves this rect to fit rc bounds, retaining the same size
shrink (dx, dy) Shrink rectangle dimensions
size () Size (i.e. right - left, bottom - top)
topLeft () Top left point
toString ()
translate (dx, dy) Translate the rectangle by (dx, dy)
width () Width (i.e. right - left)

Note

Rect(0,0,20,10) has size 20x10, but right and bottom sides are non-inclusive. If you draw such rect, rightmost drawn pixel will be x=19 and bottom pixel y=9