Struct Rect

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

struct Rect ;

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

NameDescription
this (sdlRect) Constructs a dsdl2.Rect from a vanilla SDL_Rect from bindbc-sdl
this (x, y, width, height) Constructs a dsdl2.Rect by feeding in the x, y, width, and height of the rectangle
this (point, width, height) Constructs a dsdl2.Rect by feeding in a dsdl2.Point as the x and y, then width and height of the rectangle
this (frect) Constructs a dsdl2.Rect from a dsdl2.FRect (from SDL 2.0.10)

Fields

NameTypeDescription
sdlRect sdl.rect.SDL_RectInternal SDL_Rect struct

Properties

NameTypeDescription
height[get] inout(int)Proxy to the height of the dsdl2.Rect
point[get] inout(Point)Proxy to the dsdl2.Point containing the x and y value of the dsdl2.Rect
size[get] inout(int[2])Proxy to the size array containing the width and height of the dsdl2.Rect
width[get] inout(int)Proxy to the width of the dsdl2.Rect
x[get] inout(int)Proxy to the X value of the dsdl2.Rect
y[get] inout(int)Proxy to the Y value of the dsdl2.Rect

Methods

NameDescription
empty () Wraps SDL_RectEmpty which checks if the dsdl2.Rect is an empty rectangle
hasIntersection (other) Wraps SDL_HasIntersection which sees whether two dsdl2.Rects intersect each other
hasLineIntersection (line) Wraps SDL_IntersectRectAndLine which sees whether a line intersects with the dsdl2.Rect
intersectLine (line) Wraps SDL_IntersectRectAndLine which attempts to clip a line segment in the boundaries of the dsdl2.Rect
intersectRect (other) Wraps SDL_IntersectRect which attempts to get the rectangle of intersection between two dsdl2.Rects
opBinary (offset) Binary operation overload template to move rectangle's position by an offset as a dsdl2.Point
opOpAssign (offset) Operator assignment overload template to move rectangle's position in-place by an offset as a dsdl2.Point
pointInRect (point) Wraps SDL_PointInRect which sees whether the coordinate of a dsdl2.Point is inside the dsdl2.Rect
toString () Formats the dsdl2.Rect into its construction representation: "dsdl2.Rect(<x>, <y>, <w>, <h>)"
unify (other) Wraps SDL_UnionRect which creates a dsdl2.Rect of the minimum size to enclose two given dsdl2.Rects

Example

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));