Speclib  0.1.2
The library for writing better CUDA libraries
sp::Rect< T > Class Template Reference

A rectangle. More...

#include <Rect.hpp>

Public Member Functions

constexpr Rect (const sp::Vec< T, 2 > &position, const sp::Vec< T, 2 > size)
 Construct a rectangle given size and position. More...
 
constexpr sp::Vec< T, 2 > topLeft () const
 Get the top-left corner. More...
 
constexpr sp::Vec< T, 2 > topRight () const
 Get the top-right corner. More...
 
constexpr sp::Vec< T, 2 > bottomLeft () const
 Get the bottom-left corner. More...
 
constexpr sp::Vec< T, 2 > bottomRight () const
 Get the bottom-right corner. More...
 
constexpr bool valid () const
 Does this rectangle actually make sense? More...
 
constexpr sp::Rect< T > intersect (const sp::Rect< T > &other)
 Get a new rectangle representing the intersection of this one with other. More...
 
constexpr sp::Rect< T > boundingRect (const sp::Rect< T > &other) const
 Find the smallest rectangle that contains (as defined in contains()) both this rectangle and the given one. More...
 
constexpr bool contains (const sp::Vec< T, 2 > &point)
 Does this rectangle contain the given point? More...
 
constexpr bool contains (const sp::Rect< T > &rect)
 Does this rectangle contain the given rectangle? More...
 
bool operator== (const sp::Rect< T > &other) const
 
bool operator!= (const Rect< T > &other) const
 

Static Public Member Functions

constexpr static Rect< T > fromPoints (const sp::Vec< T, 2 > &topLeft, const sp::Vec< T, 2 > &bottomRight)
 Create a rectangle given its top-left and bottom-right corners. More...
 

Public Attributes

sp::Vec< T, 2 > position
 
sp::Vec< T, 2 > size
 

Detailed Description

template<typename T>
class sp::Rect< T >

A rectangle.

Template Parameters
TThe type used to store the elements of the rectangle.

Constructor & Destructor Documentation

◆ Rect()

template<typename T >
constexpr sp::Rect< T >::Rect ( const sp::Vec< T, 2 > &  position,
const sp::Vec< T, 2 >  size 
)
constexpr

Construct a rectangle given size and position.

Member Function Documentation

◆ bottomLeft()

template<typename T >
constexpr sp::Vec< T, 2 > sp::Rect< T >::bottomLeft ( ) const
constexpr

Get the bottom-left corner.

◆ bottomRight()

template<typename T >
constexpr sp::Vec< T, 2 > sp::Rect< T >::bottomRight ( ) const
constexpr

Get the bottom-right corner.

◆ boundingRect()

template<typename T >
constexpr sp::Rect< T > sp::Rect< T >::boundingRect ( const sp::Rect< T > &  other) const
constexpr

Find the smallest rectangle that contains (as defined in contains()) both this rectangle and the given one.

◆ contains() [1/2]

template<typename T >
constexpr bool sp::Rect< T >::contains ( const sp::Rect< T > &  rect)
constexpr

Does this rectangle contain the given rectangle?

If the given rectangle touches the edge of this one, but is otherwise inside it (including if it is equal to this one), then true is returned.

◆ contains() [2/2]

template<typename T >
constexpr bool sp::Rect< T >::contains ( const sp::Vec< T, 2 > &  point)
constexpr

Does this rectangle contain the given point?

Points exactly on the border of the rectangle are considered to be inside it.

◆ fromPoints()

template<typename T >
constexpr static Rect< T > sp::Rect< T >::fromPoints ( const sp::Vec< T, 2 > &  topLeft,
const sp::Vec< T, 2 > &  bottomRight 
)
staticconstexpr

Create a rectangle given its top-left and bottom-right corners.

◆ intersect()

template<typename T >
constexpr sp::Rect< T > sp::Rect< T >::intersect ( const sp::Rect< T > &  other)
constexpr

Get a new rectangle representing the intersection of this one with other.

An invalid rectangle is returned if no intersection exists.

See also
valid()
Parameters
otherThe other Rect to intersect this one with
Returns
The Rect resulting from the intersection, or an invalid Rect if there is no intersection.

◆ topLeft()

template<typename T >
constexpr sp::Vec< T, 2 > sp::Rect< T >::topLeft ( ) const
constexpr

Get the top-left corner.

◆ topRight()

template<typename T >
constexpr sp::Vec< T, 2 > sp::Rect< T >::topRight ( ) const
constexpr

Get the top-right corner.

◆ valid()

template<typename T >
constexpr bool sp::Rect< T >::valid ( ) const
constexpr

Does this rectangle actually make sense?