View on GitHub

DSFML

dsfml.graphics.rect



struct Rect(T) if (isNumeric!T);
Utility class for manipulating 2D axis aligned rectangles.

A rectangle is defined by its top-left corner and its size.

It is a very simple class defined for convenience, so its member variables (left, top, width and height) are public and can be accessed directly, just like the vector classes (Vector2 and Vector3).

To keep things simple, Rect doesn't define functions to emulate the properties that are not directly members (such as right, bottom, center, etc.), it rather only provides intersection functions.

Rect uses the usual rules for its boundaries: - The let and top edges are included in the rectangle's area - The right (left + width) and bottom (top + height) edges are excluded from the rectangle's area

This means that IntRect(0, 0, 1, 1) and IntRect(1, 1, 1, 1) don't intersect.

Rect is a template and may be used with any numeric type, but for simplicity the instanciations used by SFML are typedefed: - Rect!(int) is IntRect - Rect!(float) is FloatRect

So that you don't have to care about the template syntax.

Authors:
Laurent Gomila, Jeremy DeHaan

See Also:


http:
//www.sfml-dev.org/documentation/2.0/classsf_1_1Rect.php#details

T left;
Left coordinate of the rectangle.

T top;
Top coordinate of the rectangle.

T width;
Width of the rectangle.

T height;
HEight of the rectangle.

const bool contains(E)(E X, E Y) if (isNumeric!E);
Check if a point is inside the rectangle's area.

Params:
x X coordinate of the point to test
y Y coordinate of the point to test

Returns:
True if the point is inside, false otherwise.

const bool contains(E)(Vector2!E point) if (isNumeric!E);
Check if a point is inside the rectangle's area.

Params:
Vector2!E point Point to test

Returns:
True if the point is inside, false otherwise.

const bool intersects(E)(Rect!E rectangle) if (isNumeric!E);
Check the intersection between two rectangles.

Params:
Rect!E rectangle Rectangle to test

Returns:
True if rectangles overlap, false otherwise.

const bool intersects(E, O)(Rect!E rectangle, out Rect!O intersection) if (isNumeric!E && isNumeric!O);
Check the intersection between two rectangles.

This overload returns the overlapped rectangle in the intersection parameter.

Params:
Rect!E rectangle Rectangle to test
Rect!O intersection Rectangle to be filled with the intersection

Returns:
True if rectangles overlap, false otherwise.