2D (left,top,right,bottom) rectangle structure. More...

#include <rect.h>

Public Member Functions

 Rectx ()
 Constructs an rectangle.
 
 Rectx (const Pointx< Type > &p, const Sizex< Type > &size)
 Constructs an rectangle.
 
template<typename OtherType, typename std::enable_if_t< std::is_integral< Type >::value &&!std::is_integral< OtherType >::value, int > = 0>
 Rectx (const Rectx< OtherType > &copy)
 
template<typename OtherType, typename std::enable_if_t<!std::is_integral< Type >::value||std::is_integral< OtherType >::value, int > = 0>
 Rectx (const Rectx< OtherType > &copy)
 
 Rectx (const Rectx< Type > &rect)=default
 Constructs an rectangle.
 
 Rectx (const Sizex< Type > &s)
 Constructs an rectangle.
 
 Rectx (Type new_left, Type new_top, const Sizex< Type > &size)
 Constructs an rectangle.
 
 Rectx (Type new_left, Type new_top, Type new_right, Type new_bottom)
 Constructs an rectangle.
 
Rectx< Type > & apply_alignment (Origin origin, Type x, Type y)
 Applies an origin and offset pair to this rectangle.
 
Rectx< Type > & bounding_rect (const Rectx< Type > &rect)
 Calculates the bounding rectangle of the rectangles.
 
Rectx< Type > & clip (const Rectx< Type > &cr)
 Clip according to the specified clip rectangle.
 
bool contains (const Vec2< Type > &p) const
 Returns true if the rectangle contains the point.
 
Rectx< Type > & expand (const Type &expand)
 Expand the rectangle.
 
Rectx< Type > & expand (const Type &expand_left, const Type &expand_top, const Type &expand_right, const Type &expand_bottom)
 Expand the rectangle.
 
Rectx< Type > & expand (const Type &left_and_right, const Type &top_and_bottom)
 Expand the rectangle.
 
Pointx< Type > get_bottom_left () const
 Returns the bottom-left point outside the rectangle.
 
Pointx< Type > get_bottom_right () const
 Returns the bottom-right point outside the rectangle.
 
Pointx< Type > get_center () const
 Returns the center point of the rectangle.
 
Type get_height () const
 Returns the height of the rectangle.
 
Rectx< Type > get_rot_bounds (const Vec2< Type > &hotspot, const Angle &angle) const
 Returns another Rectx<Type> containing a rotated version of this one.
 
Rectx< Type > get_rot_bounds (Origin origin, Type x, Type y, const Angle &angle) const
 Returns another Rectx<Type> containing a rotated version of this one.
 
Sizex< Type > get_size () const
 Returns the size of the rectangle.
 
Pointx< Type > get_top_left () const
 Returns the top-left point inside the rectangle.
 
Pointx< Type > get_top_right () const
 Returns the top-right point outside the rectangle.
 
Type get_width () const
 Returns the width of the rectangle.
 
bool is_inside (const Rectx< Type > &r) const
 Returns true if rectangle passed is inside this rectangle.
 
bool is_overlapped (const Rectx< Type > &r) const
 Returns true if rectangle passed is overlapping or inside this rectangle.
 
Rectx< Type > & normalize ()
 Normalize rectangle.
 
bool operator!= (const Rectx< Type > &r) const
 Rect != Rect operator.
 
Rectx< Type > operator* (const Type &s) const
 Rect * operator.
 
Rectx< Type > & operator*= (const Type &s)
 Rect *= operator.
 
bool operator== (const Rectx< Type > &r) const
 Rect == Rect operator.
 
Rectx< Type > & overlap (const Rectx< Type > &rect)
 Calculates the intersection of two rectangles.
 
Rectx< Type > & set_bottom_right (const Vec2< Type > &p)
 Sets the bottom-right point of the rectangle.
 
Rectx< Type > & set_height (Type height)
 Sets the height of the rectangle.
 
Rectx< Type > & set_size (const Sizex< Type > &size)
 Sets the size of the rectangle, maintaining top/left position.
 
Rectx< Type > & set_top_left (const Vec2< Type > &p)
 Sets the top-left point of the rectangle.
 
Rectx< Type > & set_width (Type width)
 Sets the width of the rectangle.
 
Rectx< Type > & shrink (const Type &left_right, const Type &top_bottom)
 Shrink the rectangle.
 
Rectx< Type > & shrink (const Type &new_left, const Type &new_top, const Type &new_right, const Type &new_bottom)
 Shrink the rectangle.
 
Rectx< Type > & shrink (const Type &shrink)
 Shrink the rectangle.
 
Rectx< Type > & translate (const Rectx< Type > &p)
 Translate the rect by another rect (only uses the left and top coords).
 
Rectx< Type > & translate (const Sizex< Type > &p)
 Translate the rect.
 
Rectx< Type > & translate (const Vec2< Type > &p)
 Translate the rect.
 
Rectx< Type > & translate (Type x, Type y)
 Translate the rect.
 

Static Public Member Functions

static Rectx< Type > ltrb (Type left, Type top, Type right, Type bottom)
 
static Rectx< Type > xywh (Type x, Type y, Type width, Type height)
 

Public Attributes

Type bottom
 Y2-coordinate (point outside the rectange)
 
Type left
 X1-coordinate (left point inside the rectangle)
 
Type right
 X2-coordinate (point outside the rectangle)
 
Type top
 Y1-coordinate (top point inside the rectangle)
 

Detailed Description

template<typename Type>
class clan::Rectx< Type >

2D (left,top,right,bottom) rectangle structure.

These line templates are defined for: int (Rect), float (Rectf), double (Rectd)

Constructor & Destructor Documentation

◆ Rectx() [1/8]

◆ Rectx() [2/8]

template<typename Type>
clan::Rectx< Type >::Rectx ( const Sizex< Type > & s)
inline

Constructs an rectangle.

Parameters
s= Size

References bottom, left, right, clan::s, and top.

◆ Rectx() [3/8]

template<typename Type>
clan::Rectx< Type >::Rectx ( Type new_left,
Type new_top,
Type new_right,
Type new_bottom )
inline

Constructs an rectangle.

Parameters
new_leftInitial left position of rectangle.
new_topInitial top position of rectangle.
new_rightInitial right position of rectangle.
new_bottomInitial bottom position of rectangle.

References bottom, left, right, and top.

◆ Rectx() [4/8]

template<typename Type>
clan::Rectx< Type >::Rectx ( const Pointx< Type > & p,
const Sizex< Type > & size )
inline

Constructs an rectangle.

Parameters
p= Initial top-left position of rectangle.
sizeInitial size of rectangle.

References bottom, left, clan::p, right, top, clan::x, and clan::y.

◆ Rectx() [5/8]

template<typename Type>
clan::Rectx< Type >::Rectx ( Type new_left,
Type new_top,
const Sizex< Type > & size )
inline

Constructs an rectangle.

Parameters
new_leftInitial left position of rectangle.
new_topInitial top position of rectangle.
sizeInitial size of rectangle.

References bottom, left, right, and top.

◆ Rectx() [6/8]

template<typename Type>
clan::Rectx< Type >::Rectx ( const Rectx< Type > & rect)
default

Constructs an rectangle.

Parameters
rectInitial rectangle position and size.

References Rectx().

◆ Rectx() [7/8]

template<typename Type>
template<typename OtherType, typename std::enable_if_t< std::is_integral< Type >::value &&!std::is_integral< OtherType >::value, int > = 0>
clan::Rectx< Type >::Rectx ( const Rectx< OtherType > & copy)
inline

References Rectx(), bottom, left, right, and top.

◆ Rectx() [8/8]

template<typename Type>
template<typename OtherType, typename std::enable_if_t<!std::is_integral< Type >::value||std::is_integral< OtherType >::value, int > = 0>
clan::Rectx< Type >::Rectx ( const Rectx< OtherType > & copy)
inline

References Rectx(), bottom, left, right, and top.

Member Function Documentation

◆ apply_alignment()

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::apply_alignment ( Origin origin,
Type x,
Type y )
inline

Applies an origin and offset pair to this rectangle.

Parameters
originThe new origin to adjust to from default upper-left position
x,yOffsets applied negatively to each corner of the rectangle
Returns
reference to this object

References Rectx(), bottom, clan::Vec2< Type >::calc_origin(), get_size(), left, right, top, clan::x, clan::Vec2< Type >::x, clan::y, and clan::Vec2< Type >::y.

◆ bounding_rect()

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::bounding_rect ( const Rectx< Type > & rect)
inline

Calculates the bounding rectangle of the rectangles.

Rect values become: min left, min top, max right, max bottom.

Returns
reference to this object

References Rectx(), bottom, left, clan::max, clan::min, right, and top.

◆ clip()

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::clip ( const Rectx< Type > & cr)
inline

Clip according to the specified clip rectangle.

Returns
reference to this object

References Rectx(), bottom, left, clan::max, clan::min, right, and top.

◆ contains()

template<typename Type>
bool clan::Rectx< Type >::contains ( const Vec2< Type > & p) const
inline

Returns true if the rectangle contains the point.

References bottom, left, clan::p, right, and top.

◆ expand() [1/3]

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::expand ( const Type & expand)
inline

Expand the rectangle.

Returns
reference to this object

References Rectx(), bottom, expand(), left, right, and top.

◆ expand() [2/3]

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::expand ( const Type & expand_left,
const Type & expand_top,
const Type & expand_right,
const Type & expand_bottom )
inline

Expand the rectangle.

Returns
reference to this object

References Rectx(), bottom, left, right, and top.

Referenced by expand().

◆ expand() [3/3]

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::expand ( const Type & left_and_right,
const Type & top_and_bottom )
inline

Expand the rectangle.

Returns
reference to this object

References Rectx(), bottom, left, right, and top.

◆ get_bottom_left()

template<typename Type>
Pointx< Type > clan::Rectx< Type >::get_bottom_left ( ) const
inline

Returns the bottom-left point outside the rectangle.

References bottom, and left.

◆ get_bottom_right()

template<typename Type>
Pointx< Type > clan::Rectx< Type >::get_bottom_right ( ) const
inline

Returns the bottom-right point outside the rectangle.

References bottom, and right.

◆ get_center()

template<typename Type>
Pointx< Type > clan::Rectx< Type >::get_center ( ) const
inline

Returns the center point of the rectangle.

References bottom, left, right, and top.

◆ get_height()

template<typename Type>
Type clan::Rectx< Type >::get_height ( ) const
inline

Returns the height of the rectangle.

References bottom, and top.

◆ get_rot_bounds() [1/2]

template<typename Type>
Rectx< Type > clan::Rectx< Type >::get_rot_bounds ( const Vec2< Type > & hotspot,
const Angle & angle ) const

Returns another Rectx<Type> containing a rotated version of this one.

Parameters
hotspotPoint to rotate around.
angleAngle to rotate.

References Rectx(), and clan::angle.

◆ get_rot_bounds() [2/2]

template<typename Type>
Rectx< Type > clan::Rectx< Type >::get_rot_bounds ( Origin origin,
Type x,
Type y,
const Angle & angle ) const

Returns another Rectx<Type> containing a rotated version of this one.

Parameters
originDetermines the hotspot point within the rectangle
xOffsets applied negatively to the hotspot point
yOffsets applied negatively to the hotspot point
angleAngle

References Rectx(), clan::angle, clan::x, and clan::y.

◆ get_size()

template<typename Type>
Sizex< Type > clan::Rectx< Type >::get_size ( ) const
inline

Returns the size of the rectangle.

References bottom, left, right, and top.

Referenced by apply_alignment().

◆ get_top_left()

template<typename Type>
Pointx< Type > clan::Rectx< Type >::get_top_left ( ) const
inline

Returns the top-left point inside the rectangle.

References left, and top.

◆ get_top_right()

template<typename Type>
Pointx< Type > clan::Rectx< Type >::get_top_right ( ) const
inline

Returns the top-right point outside the rectangle.

References right, and top.

◆ get_width()

template<typename Type>
Type clan::Rectx< Type >::get_width ( ) const
inline

Returns the width of the rectangle.

References left, and right.

◆ is_inside()

template<typename Type>
bool clan::Rectx< Type >::is_inside ( const Rectx< Type > & r) const
inline

Returns true if rectangle passed is inside this rectangle.

References Rectx(), bottom, left, clan::r, right, and top.

◆ is_overlapped()

template<typename Type>
bool clan::Rectx< Type >::is_overlapped ( const Rectx< Type > & r) const
inline

Returns true if rectangle passed is overlapping or inside this rectangle.

References Rectx(), bottom, left, clan::r, right, and top.

◆ ltrb()

template<typename Type>
static Rectx< Type > clan::Rectx< Type >::ltrb ( Type left,
Type top,
Type right,
Type bottom )
inlinestatic

References Rectx(), bottom, left, right, and top.

◆ normalize()

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::normalize ( )
inline

Normalize rectangle.

Sets the width to 0 if found a negative width Sets the height to 0 if found a negative height

Returns
reference to this object

References Rectx(), bottom, left, right, and top.

◆ operator!=()

template<typename Type>
bool clan::Rectx< Type >::operator!= ( const Rectx< Type > & r) const
inline

Rect != Rect operator.

References Rectx(), bottom, left, clan::r, right, and top.

◆ operator*()

template<typename Type>
Rectx< Type > clan::Rectx< Type >::operator* ( const Type & s) const
inline

Rect * operator.

References Rectx(), bottom, left, right, clan::s, and top.

◆ operator*=()

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::operator*= ( const Type & s)
inline

Rect *= operator.

References Rectx(), bottom, left, right, clan::s, and top.

◆ operator==()

template<typename Type>
bool clan::Rectx< Type >::operator== ( const Rectx< Type > & r) const
inline

Rect == Rect operator.

References Rectx(), bottom, left, clan::r, right, and top.

◆ overlap()

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::overlap ( const Rectx< Type > & rect)
inline

Calculates the intersection of two rectangles.

Rect values become: max left, max top, min right, min bottom.

Returns
reference to this object

References Rectx(), bottom, left, clan::max, clan::min, right, and top.

◆ set_bottom_right()

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::set_bottom_right ( const Vec2< Type > & p)
inline

Sets the bottom-right point of the rectangle.

Returns
reference to this object

References Rectx(), bottom, clan::p, and right.

◆ set_height()

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::set_height ( Type height)
inline

Sets the height of the rectangle.

Returns
reference to this object

References Rectx(), bottom, and top.

◆ set_size()

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::set_size ( const Sizex< Type > & size)
inline

Sets the size of the rectangle, maintaining top/left position.

Returns
reference to this object

References Rectx(), bottom, clan::Sizex< Type >::height, left, right, top, and clan::Sizex< Type >::width.

◆ set_top_left()

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::set_top_left ( const Vec2< Type > & p)
inline

Sets the top-left point of the rectangle.

Returns
reference to this object

References Rectx(), left, clan::p, and top.

◆ set_width()

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::set_width ( Type width)
inline

Sets the width of the rectangle.

Returns
reference to this object

References Rectx(), left, and right.

◆ shrink() [1/3]

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::shrink ( const Type & left_right,
const Type & top_bottom )
inline

Shrink the rectangle.

Returns
reference to this object

References Rectx(), bottom, left, right, and top.

◆ shrink() [2/3]

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::shrink ( const Type & new_left,
const Type & new_top,
const Type & new_right,
const Type & new_bottom )
inline

Shrink the rectangle.

Returns
reference to this object

References Rectx(), bottom, left, right, and top.

Referenced by shrink().

◆ shrink() [3/3]

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::shrink ( const Type & shrink)
inline

Shrink the rectangle.

Returns
reference to this object

References Rectx(), bottom, left, right, shrink(), and top.

◆ translate() [1/4]

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::translate ( const Rectx< Type > & p)
inline

Translate the rect by another rect (only uses the left and top coords).

Returns
reference to this object

References Rectx(), bottom, left, clan::p, right, and top.

◆ translate() [2/4]

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::translate ( const Sizex< Type > & p)
inline

Translate the rect.

Returns
reference to this object

References Rectx(), bottom, left, clan::p, right, and top.

◆ translate() [3/4]

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::translate ( const Vec2< Type > & p)
inline

Translate the rect.

Returns
reference to this object

References Rectx(), bottom, left, clan::p, right, and top.

◆ translate() [4/4]

template<typename Type>
Rectx< Type > & clan::Rectx< Type >::translate ( Type x,
Type y )
inline

Translate the rect.

Returns
reference to this object

References Rectx(), bottom, left, right, top, clan::x, and clan::y.

◆ xywh()

template<typename Type>
static Rectx< Type > clan::Rectx< Type >::xywh ( Type x,
Type y,
Type width,
Type height )
inlinestatic

References Rectx(), clan::x, and clan::y.

Member Data Documentation

◆ bottom

◆ left

◆ right

◆ top


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