math.rect

Rectangle struct.

struct Rect(T);

Rectangle defined by its extents.

Vector2!(T) min;

Upper-left corner of the rectangle.

Vector2!(T) max;

Lower-right corner of the rectangle.

pure nothrow this(const T minX, const T minY, const T maxX, const T maxY);

Construct a rectangle from 4 bounds.

Parameters:
T minX Left bound of the rectangle.
T minY Top bound of the rectangle.
T maxX Right bound of the rectangle.
T maxY Bottom bound of the rectangle.
pure nothrow this(const Vector2!(T) min, const Vector2!(T) max);

Construct a rectangle from 2 points.

Parameters:
Vector2!(T) min Upper-left corner of the rectangle.
Vector2!(T) max Lower-right corner of the rectangle.
const pure nothrow Rect opBinary(string op)(const Vector2!(T) v);

Addition/subtraction with a vector - used to move the rectangle.

pure nothrow void opOpAssign(string op)(const Vector2!(T) v);

Addition/subtraction with a vector - used to move the rectangle.

const pure nothrow @safe Vector2!(T) center();

Returns center of the rectangle.

const pure nothrow @safe T width();

Returns width of the rectangle.

const pure nothrow @safe T height();

Returns height of the rectangle.

const pure nothrow @safe Vector2!(T) size();

Returns size of the rectangle.

const pure nothrow @safe T area();

Returns area of the rectangle.

const pure nothrow Vector2!(T) minMax();

Returns the lower-left corner of the rectangle.

const pure nothrow Vector2!(T) maxMin();

Returns the upper-right corner of the rectangle.

const pure nothrow Vector2!(T) clamp(const Vector2!(T) point);

Clamps point to be within the rectangle. (Returns the closest point in the rectangle)

Parameters:
Vector2!(T) point Point to clamp.
Returns:
Clamped point.
const pure nothrow T distance(const Vector2!(T) point);

Get distance from the point to the rectangle.

Parameters:
Vector2!(T) point Point to get distance from.
Returns:
Distance from the point to the rectangle.
const pure nothrow bool intersect(const Vector2!(T) point);

Determines if a point intersects with the rectangle.

Parameters:
Vector2!(T) point Point to check intersection with.
Returns:
True in case of intersection, false otherwise.
pure nothrow void addInternalPoint(const Vector2!(T) point);

If the point is not in this rectangle, grow the rectangle to include it.

const pure nothrow bool valid();

Is this rectangle valid?

const pure nothrow Rect!(T) to(T)();

Convert a Rect of one type to other.

Examples:
 Rectu r_uint = Rectu(4, 2, 5, 3);
 //convert to Rectf
 Rectf r_float = r_uint.to!float
alias Rectf;

Rect of floats.

alias Rectd;

Rect of doubles.

alias Recti;

Rect of ints.

alias Rectu;

Rect of uints.