1.10
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
RectType< Dim, DimCompat > Class Template Reference

A rectangle with a point and a size. More...

#include <geometry.h>

Public Types

using DimType = Dim
 Helper to reference the dimension type.
 

Public Member Functions

constexpr RectType () noexcept=default
 
constexpr RectType (const PointType< Dim > &point, const SizeType< Dim, DimCompat > &size) noexcept
 Construct a rectangle with an explicit point and size.
 
template<typename Dim2 >
constexpr RectType (const RectType< Dim2 > &r)
 
constexpr RectType (const SizeType< Dim, DimCompat > &size) noexcept
 Construct a rectangle with the specified size and the point being at the default origin 0,0.
 
constexpr RectType (Dim x, Dim y, Dim width, Dim height) noexcept
 
EGT_NODISCARD constexpr Dim area () const noexcept
 Calculate the area of the rectangle.
 
EGT_NODISCARD constexpr Dim bottom () const noexcept
 Get the bottom side the rectangle.
 
EGT_NODISCARD constexpr PointType< Dim, DimCompat > bottom_left () const noexcept
 Get the bottom left point of the rectangle.
 
EGT_NODISCARD constexpr PointType< Dim, DimCompat > bottom_right () const noexcept
 Get the bottom right point of the rectangle.
 
EGT_NODISCARD constexpr PointType< Dim, DimCompat > center () const noexcept
 Return the center point of the rectangle.
 
constexpr void clear () noexcept
 Clear the rectangle by giving it no width or height.
 
EGT_NODISCARD constexpr bool contains (const RectType &rhs) const noexcept
 Returns true if this rectangle contains the specified one.
 
EGT_NODISCARD constexpr bool empty () const noexcept
 Returns true if the rectangle has no width or height.
 
constexpr void grow_around_center (Dim radius) noexcept
 Grow the rectangle around its center by the specified radius.
 
EGT_NODISCARD constexpr Dim height () const noexcept
 Get the height value.
 
constexpr void height (Dim height) noexcept
 Set the height value.
 
EGT_NODISCARD constexpr bool intersect (const PointType< Dim, DimCompat > &point) const noexcept
 Returns true if the specified point is inside the rectangle.
 
EGT_NODISCARD constexpr bool intersect (const RectType &rect) const noexcept
 Determine if two rectangles intersect, or, overlap.
 
EGT_NODISCARD constexpr Dim left () const noexcept
 Get the left side the rectangle.
 
constexpr void move_to_center (const PointType< Dim, DimCompat > &center) noexcept
 Move the rectangle's center to the specified point.
 
constexpr RectTypeoperator+= (const PointType< Dim, DimCompat > &rhs) noexcept
 RectType operator.
 
constexpr RectTypeoperator+= (const SizeType< Dim, DimCompat > &rhs) noexcept
 RectType operator.
 
constexpr RectTypeoperator-= (const PointType< Dim, DimCompat > &rhs) noexcept
 RectType operator.
 
constexpr RectTypeoperator-= (const SizeType< Dim, DimCompat > &rhs) noexcept
 RectType operator.
 
EGT_NODISCARD constexpr const PointType< Dim, DimCompat > & point () const noexcept
 Get the PointType of the rectangle.
 
constexpr void point (const PointType< Dim, DimCompat > &p) noexcept
 Set the rectangle's origin to the specified point.
 
EGT_NODISCARD constexpr Dim right () const noexcept
 Get the right side the rectangle.
 
constexpr void shrink_around_center (Dim radius) noexcept
 Shrink the rectangle around its center by the specified radius.
 
EGT_NODISCARD constexpr const SizeType< Dim, DimCompat > & size () const noexcept
 Get the SizeType of the rectangle.
 
constexpr void size (const SizeType< Dim, DimCompat > &size) noexcept
 Set the SizeType of the rectangle.
 
EGT_NODISCARD constexpr Dim top () const noexcept
 Get the top side of the rectangle.
 
EGT_NODISCARD constexpr PointType< Dim, DimCompat > top_left () const noexcept
 Get the top left point of the rectangle.
 
EGT_NODISCARD constexpr PointType< Dim, DimCompat > top_right () const noexcept
 Get the top right point of the rectangle.
 
EGT_NODISCARD constexpr Dim width () const noexcept
 Get the width value.
 
constexpr void width (Dim width) noexcept
 Set the width value.
 
EGT_NODISCARD constexpr Dim x () const noexcept
 Get the x value.
 
constexpr void x (Dim x) noexcept
 Set the x value.
 
EGT_NODISCARD constexpr Dim y () const noexcept
 Get the y value.
 
constexpr void y (Dim y) noexcept
 Set the y value.
 

Static Public Member Functions

static constexpr RectType intersection (const RectType &lhs, const RectType &rhs) noexcept
 Return the intersecting rectangle of two rectangles, if any.
 
static constexpr RectType merge (const RectType &lhs, const RectType &rhs) noexcept
 Merge two rectangles together into one super rectangle that contains them both.
 

Protected Attributes

PointType< Dim, DimCompat > m_origin
 Origin.
 
SizeType< Dim, DimCompat > m_size
 Size.
 

Detailed Description

template<class Dim, detail::Compatible DimCompat = detail::Compatible::normal>
class egt::v1::RectType< Dim, DimCompat >

A rectangle with a point and a size.

Typically Rect, RectF are used as aliases.

All rectangle points are at the top left.

Member Typedef Documentation

◆ DimType

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
using DimType = Dim

Helper to reference the dimension type.

Constructor & Destructor Documentation

◆ RectType() [1/5]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr RectType ( )
constexprdefaultnoexcept

◆ RectType() [2/5]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr RectType ( const PointType< Dim > &  point,
const SizeType< Dim, DimCompat > &  size 
)
inlineexplicitconstexprnoexcept

Construct a rectangle with an explicit point and size.

◆ RectType() [3/5]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr RectType ( const SizeType< Dim, DimCompat > &  size)
inlineconstexprnoexcept

Construct a rectangle with the specified size and the point being at the default origin 0,0.

◆ RectType() [4/5]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr RectType ( Dim  x,
Dim  y,
Dim  width,
Dim  height 
)
inlineconstexprnoexcept
Parameters
xX origin coordinate.
yY origin coordinate.
widthWidth
heightHeight

◆ RectType() [5/5]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
template<typename Dim2 >
constexpr RectType ( const RectType< Dim2 > &  r)
inlineconstexpr

Member Function Documentation

◆ area()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr Dim area ( ) const
inlineconstexprnoexcept

Calculate the area of the rectangle.

◆ bottom()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr Dim bottom ( ) const
inlineconstexprnoexcept

Get the bottom side the rectangle.

◆ bottom_left()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr PointType< Dim, DimCompat > bottom_left ( ) const
inlineconstexprnoexcept

Get the bottom left point of the rectangle.

◆ bottom_right()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr PointType< Dim, DimCompat > bottom_right ( ) const
inlineconstexprnoexcept

Get the bottom right point of the rectangle.

◆ center()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr PointType< Dim, DimCompat > center ( ) const
inlineconstexprnoexcept

Return the center point of the rectangle.

◆ clear()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr void clear ( )
inlineconstexprnoexcept

Clear the rectangle by giving it no width or height.

◆ contains()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr bool contains ( const RectType< Dim, DimCompat > &  rhs) const
inlineconstexprnoexcept

Returns true if this rectangle contains the specified one.

This is different than intersect(). The specified rectangle must be completely inside this one.

◆ empty()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr bool empty ( ) const
inlineconstexprnoexcept

Returns true if the rectangle has no width or height.

◆ grow_around_center()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr void grow_around_center ( Dim  radius)
inlineconstexprnoexcept

Grow the rectangle around its center by the specified radius.

Parameters
radiusRelative radius to change by.

◆ height() [1/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr Dim height ( ) const
inlineconstexprnoexcept

Get the height value.

◆ height() [2/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr void height ( Dim  height)
inlineconstexprnoexcept

Set the height value.

◆ intersect() [1/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr bool intersect ( const PointType< Dim, DimCompat > &  point) const
inlineconstexprnoexcept

Returns true if the specified point is inside the rectangle.

Parameters
pointThe point to test.

◆ intersect() [2/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr bool intersect ( const RectType< Dim, DimCompat > &  rect) const
inlineconstexprnoexcept

Determine if two rectangles intersect, or, overlap.

Parameters
rectThe rect to test.

◆ intersection()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
static constexpr RectType intersection ( const RectType< Dim, DimCompat > &  lhs,
const RectType< Dim, DimCompat > &  rhs 
)
inlinestaticconstexprnoexcept

Return the intersecting rectangle of two rectangles, if any.

◆ left()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr Dim left ( ) const
inlineconstexprnoexcept

Get the left side the rectangle.

◆ merge()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
static constexpr RectType merge ( const RectType< Dim, DimCompat > &  lhs,
const RectType< Dim, DimCompat > &  rhs 
)
inlinestaticconstexprnoexcept

Merge two rectangles together into one super rectangle that contains them both.

◆ move_to_center()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr void move_to_center ( const PointType< Dim, DimCompat > &  center)
inlineconstexprnoexcept

Move the rectangle's center to the specified point.

◆ operator+=() [1/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr RectType & operator+= ( const PointType< Dim, DimCompat > &  rhs)
inlineconstexprnoexcept

RectType operator.

◆ operator+=() [2/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr RectType & operator+= ( const SizeType< Dim, DimCompat > &  rhs)
inlineconstexprnoexcept

RectType operator.

◆ operator-=() [1/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr RectType & operator-= ( const PointType< Dim, DimCompat > &  rhs)
inlineconstexprnoexcept

RectType operator.

◆ operator-=() [2/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr RectType & operator-= ( const SizeType< Dim, DimCompat > &  rhs)
inlineconstexprnoexcept

RectType operator.

◆ point() [1/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr const PointType< Dim, DimCompat > & point ( ) const
inlineconstexprnoexcept

Get the PointType of the rectangle.

◆ point() [2/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr void point ( const PointType< Dim, DimCompat > &  p)
inlineconstexprnoexcept

Set the rectangle's origin to the specified point.

◆ right()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr Dim right ( ) const
inlineconstexprnoexcept

Get the right side the rectangle.

◆ shrink_around_center()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr void shrink_around_center ( Dim  radius)
inlineconstexprnoexcept

Shrink the rectangle around its center by the specified radius.

Parameters
radiusRelative radius to change by.

◆ size() [1/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr const SizeType< Dim, DimCompat > & size ( ) const
inlineconstexprnoexcept

Get the SizeType of the rectangle.

◆ size() [2/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr void size ( const SizeType< Dim, DimCompat > &  size)
inlineconstexprnoexcept

Set the SizeType of the rectangle.

◆ top()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr Dim top ( ) const
inlineconstexprnoexcept

Get the top side of the rectangle.

◆ top_left()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr PointType< Dim, DimCompat > top_left ( ) const
inlineconstexprnoexcept

Get the top left point of the rectangle.

Note
This is usually the origin/point of the rectangle.

◆ top_right()

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr PointType< Dim, DimCompat > top_right ( ) const
inlineconstexprnoexcept

Get the top right point of the rectangle.

◆ width() [1/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr Dim width ( ) const
inlineconstexprnoexcept

Get the width value.

◆ width() [2/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr void width ( Dim  width)
inlineconstexprnoexcept

Set the width value.

◆ x() [1/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr Dim x ( ) const
inlineconstexprnoexcept

Get the x value.

◆ x() [2/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr void x ( Dim  x)
inlineconstexprnoexcept

Set the x value.

◆ y() [1/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
EGT_NODISCARD constexpr Dim y ( ) const
inlineconstexprnoexcept

Get the y value.

◆ y() [2/2]

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
constexpr void y ( Dim  y)
inlineconstexprnoexcept

Set the y value.

Member Data Documentation

◆ m_origin

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
PointType<Dim, DimCompat> m_origin
protected

Origin.

◆ m_size

template<class Dim , detail::Compatible DimCompat = detail::Compatible::normal>
SizeType<Dim, DimCompat> m_size
protected

Size.