Rect

D struct that wraps SDL_Rect representing a rectangle of integer 2D coordinate and dimension

dsdl2.Rect stores signed integer x and y coordinate points, as well as width and height which specifies the rectangle's dimension. x and y symbolize the top-left coordinate of the rectangle, and the width and height extend to the positive plane of both axes.

Constructors

this
this()
Undocumented in source.
this
this(SDL_Rect sdlRect)

Constructs a dsdl2.Rect from a vanilla SDL_Rect from bindbc-sdl

this
this(int x, int y, int width, int height)

Constructs a dsdl2.Rect by feeding in the x, y, width, and height of the rectangle

this
this(Point point, int width, int height)

Constructs a dsdl2.Rect by feeding in a dsdl2.Point as the x and y, then width and height of the rectangle

this
this(FRect frect)

Constructs a dsdl2.Rect from a dsdl2.FRect (from SDL 2.0.10)

Members

Functions

empty
bool empty()

Wraps SDL_RectEmpty which checks if the dsdl2.Rect is an empty rectangle

hasIntersection
bool hasIntersection(Rect other)

Wraps SDL_HasIntersection which sees whether two dsdl2.Rects intersect each other

hasLineIntersection
bool hasLineIntersection(Point[2] line)

Wraps SDL_IntersectRectAndLine which sees whether a line intersects with the dsdl2.Rect

height
inout(int) height()

Proxy to the height of the dsdl2.Rect

intersectLine
Nullable!(Point[2]) intersectLine(Point[2] line)

Wraps SDL_IntersectRectAndLine which attempts to clip a line segment in the boundaries of the dsdl2.Rect

intersectRect
Nullable!Rect intersectRect(Rect other)

Wraps SDL_IntersectRect which attempts to get the rectangle of intersection between two dsdl2.Rects

opBinary
Rect opBinary(Point offset)

Binary operation overload template to move rectangle's position by an offset as a dsdl2.Point

opOpAssign
inout(Point) opOpAssign(Point offset)

Operator assignment overload template to move rectangle's position in-place by an offset as a dsdl2.Point

point
inout(Point) point()

Proxy to the dsdl2.Point containing the x and y value of the dsdl2.Rect

pointInRect
bool pointInRect(Point point)

Wraps SDL_PointInRect which sees whether the coordinate of a dsdl2.Point is inside the dsdl2.Rect

size
inout(int[2]) size()

Proxy to the size array containing the width and height of the dsdl2.Rect

toString
string toString()

Formats the dsdl2.Rect into its construction representation: "dsdl2.Rect(<x>, <y>, <w>, <h>)"

unify
Rect unify(Rect other)

Wraps SDL_UnionRect which creates a dsdl2.Rect of the minimum size to enclose two given dsdl2.Rects

width
inout(int) width()

Proxy to the width of the dsdl2.Rect

x
inout(int) x()

Proxy to the X value of the dsdl2.Rect

y
inout(int) y()

Proxy to the Y value of the dsdl2.Rect

Variables

sdlRect
SDL_Rect sdlRect;

Internal SDL_Rect struct

Examples

auto rect1 = dsdl2.Rect(-2, -2, 3, 3);
auto rect2 = dsdl2.Rect(-1, -1, 3, 3);

assert(rect1.hasIntersection(rect2));
assert(rect1.intersectRect(rect2).get == dsdl2.Rect(-1, -1, 2, 2));

Meta