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();
- const pure nothrow @safe T width();
- const pure nothrow @safe T height();
- const pure nothrow @safe Vector2!(T) size();
- const pure nothrow @safe T area();
- 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: Returns:Clamped point.- const pure nothrow T distance(const Vector2!(T) point);
Get distance from the point to the rectangle.
Parameters: 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:Returns:Vector2!(T) point Point to check intersection with. 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();
- 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.