1.9
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...

Public Types

using DimType = Dim
 Helper to reference the dimension type. More...
 

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

Static Public Member Functions

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

Protected Attributes

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

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

using DimType = Dim

Helper to reference the dimension type.

Constructor & Destructor Documentation

◆ RectType() [1/5]

constexpr RectType ( )
constexprdefaultnoexcept

◆ RectType() [2/5]

constexpr RectType ( const PointType< Dim > &  point,
const SizeType< Dim, DimCompat > &  size 
)
inlineexplicitconstexprnoexcept

Construct a rectangle with an explicit point and size.

◆ RectType() [3/5]

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]

constexpr RectType ( Dim  x,
Dim  y,
Dim  width,
Dim  height 
)
inlineconstexprnoexcept
Parameters
xX origin coordinate.
yY origin coordinate.
widthWidth
heightHeight

◆ RectType() [5/5]

constexpr RectType ( const RectType< Dim2 > &  r)
inlineconstexpr

Member Function Documentation

◆ area()

constexpr EGT_NODISCARD Dim area ( ) const
inlineconstexprnoexcept

Calculate the area of the rectangle.

◆ bottom()

constexpr EGT_NODISCARD Dim bottom ( ) const
inlineconstexprnoexcept

Get the bottom side the rectangle.

◆ bottom_left()

constexpr EGT_NODISCARD PointType<Dim, DimCompat> bottom_left ( ) const
inlineconstexprnoexcept

Get the bottom left point of the rectangle.

◆ bottom_right()

constexpr EGT_NODISCARD PointType<Dim, DimCompat> bottom_right ( ) const
inlineconstexprnoexcept

Get the bottom right point of the rectangle.

◆ center()

constexpr EGT_NODISCARD PointType<Dim, DimCompat> center ( ) const
inlineconstexprnoexcept

Return the center point of the rectangle.

◆ clear()

constexpr void clear ( )
inlineconstexprnoexcept

Clear the rectangle by giving it no width or height.

◆ contains()

constexpr EGT_NODISCARD 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()

constexpr EGT_NODISCARD bool empty ( ) const
inlineconstexprnoexcept

Returns true if the rectangle has no width or height.

◆ grow_around_center()

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]

constexpr EGT_NODISCARD Dim height ( ) const
inlineconstexprnoexcept

Get the height value.

◆ height() [2/2]

constexpr void height ( Dim  height)
inlineconstexprnoexcept

Set the height value.

◆ intersect() [1/2]

constexpr EGT_NODISCARD 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]

constexpr EGT_NODISCARD bool intersect ( const RectType< Dim, DimCompat > &  rect) const
inlineconstexprnoexcept

Determine if two rectangles intersect, or, overlap.

Parameters
rectThe rect to test.

◆ intersection()

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()

constexpr EGT_NODISCARD Dim left ( ) const
inlineconstexprnoexcept

Get the left side the rectangle.

◆ merge()

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()

constexpr void move_to_center ( const PointType< Dim, DimCompat > &  center)
inlineconstexprnoexcept

Move the rectangle's center to the specified point.

◆ operator+=() [1/2]

constexpr RectType& operator+= ( const PointType< Dim, DimCompat > &  rhs)
inlineconstexprnoexcept

RectType operator.

◆ operator+=() [2/2]

constexpr RectType& operator+= ( const SizeType< Dim, DimCompat > &  rhs)
inlineconstexprnoexcept

RectType operator.

◆ operator-=() [1/2]

constexpr RectType& operator-= ( const PointType< Dim, DimCompat > &  rhs)
inlineconstexprnoexcept

RectType operator.

◆ operator-=() [2/2]

constexpr RectType& operator-= ( const SizeType< Dim, DimCompat > &  rhs)
inlineconstexprnoexcept

RectType operator.

◆ point() [1/2]

constexpr EGT_NODISCARD const PointType<Dim, DimCompat>& point ( ) const
inlineconstexprnoexcept

Get the PointType of the rectangle.

◆ point() [2/2]

constexpr void point ( const PointType< Dim, DimCompat > &  p)
inlineconstexprnoexcept

Set the rectangle's origin to the specified point.

◆ right()

constexpr EGT_NODISCARD Dim right ( ) const
inlineconstexprnoexcept

Get the right side the rectangle.

◆ shrink_around_center()

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]

constexpr EGT_NODISCARD const SizeType<Dim, DimCompat>& size ( ) const
inlineconstexprnoexcept

Get the SizeType of the rectangle.

◆ size() [2/2]

constexpr void size ( const SizeType< Dim, DimCompat > &  size)
inlineconstexprnoexcept

Set the SizeType of the rectangle.

◆ top()

constexpr EGT_NODISCARD Dim top ( ) const
inlineconstexprnoexcept

Get the top side of the rectangle.

◆ top_left()

constexpr EGT_NODISCARD 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()

constexpr EGT_NODISCARD PointType<Dim, DimCompat> top_right ( ) const
inlineconstexprnoexcept

Get the top right point of the rectangle.

◆ width() [1/2]

constexpr EGT_NODISCARD Dim width ( ) const
inlineconstexprnoexcept

Get the width value.

◆ width() [2/2]

constexpr void width ( Dim  width)
inlineconstexprnoexcept

Set the width value.

◆ x() [1/2]

constexpr EGT_NODISCARD Dim x ( ) const
inlineconstexprnoexcept

Get the x value.

◆ x() [2/2]

constexpr void x ( Dim  x)
inlineconstexprnoexcept

Set the x value.

◆ y() [1/2]

constexpr EGT_NODISCARD Dim y ( ) const
inlineconstexprnoexcept

Get the y value.

◆ y() [2/2]

constexpr void y ( Dim  y)
inlineconstexprnoexcept

Set the y value.

Member Data Documentation

◆ m_origin

PointType<Dim, DimCompat> m_origin
protected

Origin.

◆ m_size

SizeType<Dim, DimCompat> m_size
protected

Size.