![]() |
Duckcpp 2.1.0
Duckcpp is a high-performance c++ graphics engine.
|
Rectangle template. More...
#include <duckcpp/core/engine/rect.hpp>
Public Member Functions | |
| rect () | |
| Default constructor creating empty rectangle at (0,0) | |
| rect (T x, T y, T x2, T y2) | |
| Constructor with two corners. | |
| rect (const position2d< T > &upperLeft, const position2d< T > &lowerRight) | |
| Constructor with two corners. | |
| template<class U > | |
| rect (const position2d< T > &pos, const dimension2d< U > &size) | |
| Constructor with upper left corner and dimension. | |
| template<class U > | |
| rect (const dimension2d< U > &size) | |
| Constructor with upper left at 0,0 and lower right using dimension. | |
| rect< T > | operator+ (const position2d< T > &pos) const |
| move right by given numbers | |
| rect< T > & | operator+= (const position2d< T > &pos) |
| move right by given numbers | |
| rect< T > | operator- (const position2d< T > &pos) const |
| move left by given numbers | |
| rect< T > & | operator-= (const position2d< T > &pos) |
| move left by given numbers | |
| bool | operator== (const rect< T > &other) const |
| equality operator | |
| bool | operator!= (const rect< T > &other) const |
| inequality operator | |
| bool | operator< (const rect< T > &other) const |
| compares size of rectangles | |
| T | getArea () const |
| Returns size of rectangle. | |
| bool | isPointInside (const position2d< T > &pos) const |
| Returns if a 2d point is within this rectangle. | |
| bool | isRectCollided (const rect< T > &other) const |
| Check if the rectangle collides with another rectangle. | |
| void | clipAgainst (const rect< T > &other) |
| Clips this rectangle with another one. | |
| bool | constrainTo (const rect< T > &other) |
| Moves this rectangle to fit inside another one. | |
| T | getWidth () const |
| Get width of rectangle. | |
| T | getHeight () const |
| Get height of rectangle. | |
| void | repair () |
| If the lower right corner of the rect is smaller then the upper left, the points are swapped. | |
| bool | isValid () const |
| Returns if the rect is valid to draw. | |
| position2d< T > | getCenter () const |
| Get the center of the rectangle. | |
| dimension2d< T > | getSize () const |
| Get the dimensions of the rectangle. | |
| void | addInternalPoint (const position2d< T > &p) |
| Adds a point to the rectangle. | |
| void | addInternalPoint (T x, T y) |
| Adds a point to the bounding rectangle. | |
Public Attributes | |
| position2d< T > | UpperLeftCorner |
| Upper left corner. | |
| position2d< T > | LowerRightCorner |
| Lower right corner. | |
Rectangle template.
Mostly used by 2D GUI elements and for 2D drawing methods. It has 2 positions instead of position and dimension and a fast method for collision detection with other rectangles and points.
Coordinates are (0,0) for top-left corner, and increasing to the right and to the bottom.
Adds a point to the rectangle.
Causes the rectangle to grow bigger if point is outside of the box
| p | Point to add to the box. |
Adds a point to the bounding rectangle.
Causes the rectangle to grow bigger if point is outside of the box
| x | X-Coordinate of the point to add to this box. |
| y | Y-Coordinate of the point to add to this box. |
Clips this rectangle with another one.
| other | Rectangle to clip with |
Moves this rectangle to fit inside another one.
|
inline |
Returns if a 2d point is within this rectangle.
| pos | Position to test if it lies within this rectangle. |
Check if the rectangle collides with another rectangle.
| other | Rectangle to test collision with |
|
inline |
Returns if the rect is valid to draw.
It would be invalid if the UpperLeftCorner is lower or more right than the LowerRightCorner.