Plasma Engine  2.0
Loading...
Searching...
No Matches
plRectTemplate< Type > Class Template Reference

A simple rectangle class templated on the type for x, y and width, height. More...

#include <Rect.h>

Public Member Functions

 PL_DECLARE_POD_TYPE ()
 
 plRectTemplate ()
 Default constructor does not initialize the data.
 
 plRectTemplate (Type x, Type y, Type width, Type height)
 Constructor to set all values.
 
 plRectTemplate (Type width, Type height)
 Initializes x and y with zero, width and height with the given values.
 
 plRectTemplate (const plVec2Template< Type > &vTopLeftPosition, const plVec2Template< Type > &vSize)
 Initializes x and y from pos, width and height from vSize.
 
Type Left () const
 The smaller value along x.
 
Type Right () const
 The larger value along x.
 
Type Top () const
 The smaller value along y.
 
Type Bottom () const
 The larger value along y.
 
Type GetX1 () const
 The smaller value along x. Same as Left().
 
Type GetX2 () const
 The larger value along x. Same as Right().
 
Type GetY1 () const
 The smaller value along y. Same as Top().
 
Type GetY2 () const
 The larger value along y. Same as Bottom().
 
plVec2Template< Type > GetMinCorner () const
 Returns the minimum corner position. Same as GetTopLeft().
 
plVec2Template< Type > GetMaxCorner () const
 Returns the maximum corner position. Same as GetBottomRight().
 
plVec2Template< Type > GetTopLeft () const
 Returns the top left corner. Same as GetMinCorner().
 
plVec2Template< Type > GetTopRight () const
 Returns the top right corner.
 
plVec2Template< Type > GetBottomLeft () const
 Returns the bottom left corner.
 
plVec2Template< Type > GetBottomRight () const
 Returns the bottom right corner. Same as GetMaxCorner().
 
plVec2Template< Type > GetCenter () const
 Returns the center point of the rectangle.
 
plVec2Template< Type > GetExtents () const
 Returns the width and height as a vec2.
 
plVec2Template< Type > GetHalfExtents () const
 Returns the half width and half height as a vec2.
 
void Grow (Type xy)
 Increases the size of the rect in all directions.
 
bool operator== (const plRectTemplate< Type > &rhs) const
 
bool operator!= (const plRectTemplate< Type > &rhs) const
 
bool IsValid () const
 Checks whether the position and size contain valid values.
 
bool HasNonZeroArea () const
 Returns true if the area of the rectangle is non zero.
 
bool Contains (const plVec2Template< Type > &vPoint) const
 Returns true if the rectangle contains the provided point.
 
bool Contains (const plRectTemplate< Type > &r) const
 
bool Overlaps (const plRectTemplate< Type > &other) const
 Returns true if the rectangle overlaps the provided rectangle. Also returns true if the rectangles are contained within each other completely(no intersecting edges).
 
void ExpandToInclude (const plRectTemplate< Type > &other)
 Extends this rectangle so that the provided rectangle is completely contained within it.
 
void ExpandToInclude (const plVec2Template< Type > &other)
 Extends this rectangle so that the provided point is contained within it.
 
void Clip (const plRectTemplate< Type > &clipRect)
 Clips this rect so that it is fully inside the provided rectangle.
 
const plVec2Template< Type > GetClampedPoint (const plVec2Template< Type > &vPoint) const
 The given point is clamped to the area of the rect, i.e. it will be either inside the rect or on its edge and it will have the closest possible distance to the original point.
 
const plRectTemplate< Type > GetClampedRect (const plRectTemplate< Type > &r) const
 Clamps the given rect to the area of this rect and returns it.
 
void SetCenter (Type tX, Type tY)
 Sets the center of the rectangle.
 
void Translate (Type tX, Type tY)
 Moves the rectangle.
 
void Scale (Type sX, Type sY)
 Scales width and height, and moves the position as well.
 

Static Public Member Functions

static plRectTemplate< Type > MakeInvalid ()
 Creates an 'invalid' rect.
 
static plRectTemplate< Type > MakeIntersection (const plRectTemplate< Type > &r0, const plRectTemplate< Type > &r1)
 Creates a rect that is the intersection of the two provided rects.
 
static plRectTemplate< Type > MakeUnion (const plRectTemplate< Type > &r0, const plRectTemplate< Type > &r1)
 Creates a rect that is the union of the two provided rects.
 

Public Attributes

Type x
 
Type y
 
Type width
 
Type height
 

Detailed Description

template<typename Type>
class plRectTemplate< Type >

A simple rectangle class templated on the type for x, y and width, height.

Member Function Documentation

◆ GetClampedPoint()

template<typename Type >
PL_ALWAYS_INLINE const plVec2Template< Type > plRectTemplate< Type >::GetClampedPoint ( const plVec2Template< Type > & vPoint) const
nodiscard

The given point is clamped to the area of the rect, i.e. it will be either inside the rect or on its edge and it will have the closest possible distance to the original point.

Test
This is new

◆ GetClampedRect()

template<typename Type >
const plRectTemplate< Type > plRectTemplate< Type >::GetClampedRect ( const plRectTemplate< Type > & r) const
inlinenodiscard

Clamps the given rect to the area of this rect and returns it.

If the input rect is entirely outside this rect, the result will be reduced to a point or a line closest to the input rect.

◆ IsValid()

template<typename Type >
PL_ALWAYS_INLINE bool plRectTemplate< Type >::IsValid ( ) const
nodiscard

Checks whether the position and size contain valid values.

Test
This is new

◆ MakeIntersection()

template<typename Type >
plRectTemplate< Type > plRectTemplate< Type >::MakeIntersection ( const plRectTemplate< Type > & r0,
const plRectTemplate< Type > & r1 )
staticnodiscard

Creates a rect that is the intersection of the two provided rects.

If the two rects don't overlap, the result will be a valid rect, but have zero area. See IsValid() and HasNonZeroArea().

Test
This is new

◆ MakeInvalid()

template<typename Type >
plRectTemplate< Type > plRectTemplate< Type >::MakeInvalid ( )
staticnodiscard

Creates an 'invalid' rect.

IsValid() will return false. It is possible to make an invalid rect valid using ExpandToInclude().

Test
This is new

◆ MakeUnion()

template<typename Type >
plRectTemplate< Type > plRectTemplate< Type >::MakeUnion ( const plRectTemplate< Type > & r0,
const plRectTemplate< Type > & r1 )
staticnodiscard

Creates a rect that is the union of the two provided rects.

This is the same as constructing a bounding box around the two rects.

Test
This is new

◆ Scale()

template<typename Type >
void plRectTemplate< Type >::Scale ( Type sX,
Type sY )

Scales width and height, and moves the position as well.

Test
This is new

◆ SetCenter()

template<typename Type >
void plRectTemplate< Type >::SetCenter ( Type tX,
Type tY )

Sets the center of the rectangle.

Test
This is new

◆ Translate()

template<typename Type >
void plRectTemplate< Type >::Translate ( Type tX,
Type tY )

Moves the rectangle.

Test
This is new

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