GameKit
0.0.1a
C++ gamedev tools
|
Utility class for manipulating 2D axis aligned rectangles. More...
#include <Rect.hpp>
Public Member Functions | |
Rect ()=default | |
Default constructor. More... | |
Rect (T _x, T _y, T _width, T _height) | |
Construct the rectangle from its coordinates. More... | |
Rect (const Vector2< T > &position, const Vector2< T > &size) | |
Construct the rectangle from position and size. More... | |
template<typename U > | |
Rect (const Rect< U > &rect) | |
Construct the rectangle from another type of rectangle. More... | |
bool | contains (T _x, T _y) const |
Check if a point is inside the rectangle's area. More... | |
bool | contains (const Vector2< T > &point) const |
Check if a point is inside the rectangle's area. More... | |
bool | intersects (const Rect< T > &rect) const |
Check the intersection between two rectangles. More... | |
T | intersectionDirection (const Rect< T > &rect) const |
Check the intersection direction between two rectangles. More... | |
bool | operator== (const Rect< T > &rect) const |
Overload of binary operator ==. More... | |
bool | operator!= (const Rect< T > &rect) const |
Overload of binary operator !=. More... | |
Public Attributes | |
T | x = 0 |
Left coordinate of the rectangle. More... | |
T | y = 0 |
Top coordinate of the rectangle. More... | |
T | width = 0 |
Width of the rectangle. More... | |
T | height = 0 |
Height of the rectangle. More... | |
Utility class for manipulating 2D axis aligned rectangles.
This part of the documentation has been taken from SFML Once the migration to SFML 2.6 is done, this file will be removed
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 (x, y, width and height) are public and can be accessed directly, just like the vector classes (Vector2 and Vector3).
To keep things simple, gk::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.
gk::Rect uses the usual rules for its boundaries:
This means that gk::IntRect(0, 0, 1, 1) and gk::IntRect(1, 1, 1, 1) don't intersect.
gk::Rect is a template and may be used with any numeric type, but for simplicity the instantiations used by GameKit are typedef'd:
So that you don't have to care about the template syntax.
Usage example:
Default constructor.
Creates an empty rectangle (it is equivalent to calling Rect(0, 0, 0, 0)).
Construct the rectangle from its coordinates.
Be careful, the last two parameters are the width and height, not the right and bottom coordinates!
_x | Left coordinate of the rectangle |
_y | Top coordinate of the rectangle |
_width | Width of the rectangle |
_height | Height of the rectangle |
|
inline |
Check if a point is inside the rectangle's area.
This check is non-inclusive. If the point lies on the edge of the rectangle, this function will return false.
_x | X coordinate of the point to test |
_y | Y coordinate of the point to test |
Check if a point is inside the rectangle's area.
This check is non-inclusive. If the point lies on the edge of the rectangle, this function will return false.
point | Point to test |
Check the intersection direction between two rectangles.
rect | Rectangle to test |
Check the intersection between two rectangles.
rect | Rectangle to test |
T gk::Rect< T >::height = 0 |
T gk::Rect< T >::width = 0 |
T gk::Rect< T >::x = 0 |
T gk::Rect< T >::y = 0 |