Definition of a Rect using floats.
Definition of a Rect using integers.
Utility structure for manipulating 2D axis aligned rectangles.
// Define a rectangle, located at (0, 0) with a size of 20x5 auto r1 = IntRect(0, 0, 20, 5); // Define another rectangle, located at (4, 2) with a size of 18x10 auto position = Vector2i(4, 2); auto size = Vector2i(18, 10); auto r2 = IntRect(position, size); // Test intersections with the point (3, 1) bool b1 = r1.contains(3, 1); // true bool b2 = r2.contains(3, 1); // false // Test the intersection between r1 and r2 IntRect result; bool b3 = r1.intersects(r2, result); // true // result == IntRect(4, 2, 16, 3)
A rectangle is defined by its top-left corner and its size. It is a very simple structure defined for convenience, so its member variables (left, top, width, and height) are public and can be accessed directly, just like the vector structures ($(VECTOR2_LINK) and $(VECTOR3_LINK)).
To keep things simple, $(U 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:
$(PARA This means that `IntRect(0, 0, 1, 1)` and `IntRect(1, 1, 1, 1)` don't intersect. $(U Rect) is a template and may be used with any numeric type, but for simplicity the instanciations used by SFML are aliased:)
$(PARA This is so you don't have to care about the template syntax.)