nCine 2025.06.r503-ff15d8d
A cross-platform 2D game engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
ncine::Rect< T > Class Template Reference

A template based rectangle in a two dimensional space. More...

#include <Rect.h>

Public Member Functions

 Rect ()
 Default constructor, all zeros.
 
 Rect (T xx, T yy, T ww, T hh)
 Constructs a rectangle from top-left point and size.
 
 Rect (const Vector2< T > &topLeft, const Vector2< T > &size)
 Constructs a rectangle from top-left point and size as two Vector2
 
 Rect (const Vector2< T > &topLeft, T ww, T hh)
 Constructs a rectangle from top-left point and size, the first as aVector2
 
 Rect (T xx, T yy, const Vector2< T > &size)
 Constructs a rectangle from top-left point and size, the second as aVector2
 
 Rect (const Rect &other)
 
Rectoperator= (const Rect &other)
 
Vector2< T > center () const
 Calculates the center of the rectangle.
 
Vector2< T > min () const
 Calculates the minimum coordinates of the rectangle.
 
Vector2< T > max () const
 Calculates the maximum coordinates of the rectangle.
 
void set (T xx, T yy, T ww, T hh)
 Sets rectangle top-left point and size.
 
void set (const Vector2< T > &topLeft, const Vector2< T > &size)
 Sets rectangle top-left point and size as two Vector2
 
void set (const Vector2< T > &topLeft, T ww, T hh)
 Sets rectangle top-left point and size, the first as aVector2
 
void set (T xx, T yy, const Vector2< T > &size)
 Sets rectangle top-left point and size, the second as aVector2
 
void setCenter (float cx, float cy)
 Retains rectangle size but moves its center to another position.
 
void setCenter (const Vector2< T > &center)
 Retains rectangle size but moves its center to another position with a Vector2
 
void setSize (float ww, float hh)
 Retains rectangle center but changes its size.
 
void setSize (const Vector2< T > &size)
 Retains rectangle center but changes its size with a Vector2
 
void setCenterSize (T xx, T yy, T ww, T hh)
 Sets rectangle center and size.
 
void setCenterSize (const Vector2< T > &center, const Vector2< T > &size)
 Sets rectangle center and size as two Vector2
 
void setCenterSize (const Vector2< T > &center, T ww, T hh)
 Sets rectangle center and size, the first as aVector2
 
void setCenterSize (T xx, T yy, const Vector2< T > &size)
 Sets rectangle center and size, the second as aVector2
 
void setMinMax (T minX, T minY, T maxX, T maxY)
 Sets rectangle minimum and maximum coordinates.
 
void setMinMax (const Vector2< T > &min, const Vector2< T > &max)
 Sets rectangle minimum and maximum coordinates as two Vector2
 
void setMinMax (const Vector2< T > &min, T maxX, T maxY)
 Sets rectangle minimum and maximum coordinates, the first as aVector2
 
void setMinMax (T minX, T minY, const Vector2< T > &max)
 Sets rectangle minimum and maximum coordinates, the second as aVector2
 
void invertSize ()
 Inverts rectangle size and moves (x, y) to a different angle.
 
bool contains (T px, T py) const
 
bool contains (const Vector2< T > &p) const
 
bool contains (const Rect< T > &rect) const
 
bool overlaps (const Rect< T > &rect) const
 
void intersect (const Rect< T > &rect)
 Intersects this rectangle with the other rectangle.
 
bool operator== (const Rect &rect) const
 Eqality operator.
 
template<class S >
Rect< T > convertType (const Rect< S > &other)
 

Static Public Member Functions

template<class S >
static Rect convertType (const Rect< S > &other)
 
static Rect fromCenterSize (T xx, T yy, T ww, T hh)
 Creates a rectangle from center and size.
 
static Rect fromCenterSize (const Vector2< T > &center, const Vector2< T > &size)
 Creates a rectangle from center and size as two Vector2
 
static Rect fromCenterSize (const Vector2< T > &center, T ww, T hh)
 Creates a rectangle from center and size, the first as aVector2
 
static Rect fromCenterSize (T xx, T yy, const Vector2< T > &size)
 Creates a rectangle from center and size, the second as aVector2
 
static Rect fromMinMax (T minX, T minY, T maxX, T maxY)
 Creates a rectangle from minimum and maximum coordinates.
 
static Rect fromMinMax (const Vector2< T > &min, const Vector2< T > &max)
 Creates a rectangle from minimum and maximum coordinates as two Vector2
 
static Rect fromMinMax (const Vector2< T > &min, T maxX, T maxY)
 Creates a rectangle from minimum and maximum coordinates, the first as aVector2
 
static Rect fromMinMax (T minX, T minY, const Vector2< T > &max)
 Creates a rectangle from minimum and maximum coordinates, the second as aVector2
 

Public Attributes

x
 Top-left X coordinate as a public property (left with positive width)
 
y
 Top-left Y coordinate as a public property (top with positive height)
 
w
 Width as a public property.
 
h
 Height as a public property.
 

Detailed Description

template<class T>
class ncine::Rect< T >

A template based rectangle in a two dimensional space.

Member Function Documentation

◆ contains() [1/3]

template<class T >
bool ncine::Rect< T >::contains ( const Rect< T > &  rect) const
inline
Returns
True if the other rectangle is contained inside this one

◆ contains() [2/3]

template<class T >
bool ncine::Rect< T >::contains ( const Vector2< T > &  p) const
inline
Returns
True if the point vector is inside this rectangle

◆ contains() [3/3]

template<class T >
bool ncine::Rect< T >::contains ( px,
py 
) const
inline
Returns
True if the point is inside this rectangle

◆ overlaps()

template<class T >
bool ncine::Rect< T >::overlaps ( const Rect< T > &  rect) const
inline
Returns
True if this rect does overlap the other rectangle in any way

The documentation for this class was generated from the following file: