Definition of a Rect using floats.
Definition of a Rect using integers.
Utility class for manipulating 2D axis aligned rectangles.
1 // Define a rectangle, located at (0, 0) with a size of 20x5 2 auto r1 = IntRect(0, 0, 20, 5); 3 4 // Define another rectangle, located at (4, 2) with a size of 18x10 5 auto position = Vector2i(4, 2); 6 auto size = Vector2i(18, 10); 7 auto r2 = IntRect(position, size); 8 9 // Test intersections with the point (3, 1) 10 bool b1 = r1.contains(3, 1); // true 11 bool b2 = r2.contains(3, 1); // false 12 13 // Test the intersection between r1 and r2 14 IntRect result; 15 bool b3 = r1.intersects(r2, result); // true 16 // result == IntRect(4, 2, 16, 3)
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_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.)