TeiaCareSDK  v0.1.0
TeiaCareSDK is a collection of reusable C++ components
Loading...
Searching...
No Matches
tc::sdk::rectangle< T > Class Template Reference

2D rectangle specified by a position point (top-left corner) and a pair of width/height dimensions. More...

#include <rectangle.hpp>

Public Member Functions

constexpr rectangle ()=default
 Default Constructor. Creates a default tc::sdk::rectangle instance.
 
constexpr rectangle (const rectangle &)=default
 Copy Constructor. Copy a tc::sdk::rectangle instance into another one.
 
constexpr rectangle (rectangle &&)=default
 Move Constructor. Copy a tc::sdk::rectangle instance into another one.
 
constexpr rectangle (tc::sdk::point< T > position, T w, T h) noexcept
 Constructor. Creates tc::sdk::rectangle instance with given width and height dimensions.
 
constexpr rectangle (T x, T y, T w, T h) noexcept
 Constructor. Creates tc::sdk::rectangle instance with given width and height dimensions.
 
rectangleoperator= (const rectangle &)=default
 Assignment operator. Assign a tc::sdk::rectangle instance to another one.
 
rectangleoperator= (rectangle &&)=default
 Move assignment operator. Assign a tc::sdk::rectangle instance to another one.
 
constexpr bool operator== (const rectangle &other) const noexcept
 Equality operator.
 
constexpr bool operator!= (const rectangle &other) const noexcept
 Inequality operator.
 
constexpr bool is_null () const noexcept
 Check if the rectangle is the null.
 
constexprwidth () const noexcept
 Width dimension getter.
 
constexprheight () const noexcept
 Height dimension getter.
 
void set_width (T width) noexcept
 Width coordinate setter. Set the width dimension of the rectangle.
 
void set_height (T height) noexcept
 Height coordinate setter. Set the height dimension of the rectangle.
 
constexpr void set_size (T width, T height) noexcept
 Size setter.
 
constexpr void set_position (tc::sdk::point< T > position) noexcept
 Set the rectangle position.
 
constexpr tc::sdk::point< T > top_left () const noexcept
 Top left coordinate getter.
 
constexpr tc::sdk::point< T > top_right () const noexcept
 Top right coordinate getter.
 
constexpr tc::sdk::point< T > bottom_left () const noexcept
 Bottom left coordinate getter.
 
constexpr tc::sdk::point< T > bottom_right () const noexcept
 Bottom right coordinate getter.
 
constexpr tc::sdk::size< T > size () const noexcept
 Size getter.
 
constexprarea () const noexcept
 Area getter.
 
constexpr tc::sdk::point< doublecenter () const noexcept
 Center getter.
 
bool contains (tc::sdk::point< T > point) const noexcept
 Check if the given point is strictly contained within the current rectangle.
 
bool contains (tc::sdk::rectangle< T > other) const noexcept
 Check if the given rectangle is strictly contained within the current rectangle.
 
bool intersects (tc::sdk::rectangle< T > other) const noexcept
 Check if the given rectangle overlaps the current rectangle.
 
bool intersects (tc::sdk::line< T > line) const noexcept
 Check if the given line pass through the current rectangle.
 
tc::sdk::rectangle< T > get_intersection (tc::sdk::rectangle< T > other) const noexcept
 
tc::sdk::rectangle< T > get_union (tc::sdk::rectangle< T > other) const noexcept
 
void translate (T delta_x, T delta_y) noexcept
 Translate the rectangle by a given delta_x and delta_y offsets.
 
tc::sdk::rectangle< T > translated (T delta_x, T delta_y) const noexcept
 Create a copy of the rectangle translated by a given delta_x and delta_y offsets.
 
constexpr std::string to_string () const
 Get the rectangle string representation.
 

Friends

std::ostream & operator<< (std::ostream &stream, const rectangle &r)
 Output stream operator.
 

Detailed Description

template<typename T>
class tc::sdk::rectangle< T >

2D rectangle specified by a position point (top-left corner) and a pair of width/height dimensions.

Template Parameters
TUnderlying coordinates and dimensions type

Definition at line 33 of file rectangle.hpp.

Constructor & Destructor Documentation

◆ rectangle() [1/2]

template<typename T >
constexpr tc::sdk::rectangle< T >::rectangle ( tc::sdk::point< T >  position,
w,
h 
)
inlineexplicitconstexprnoexcept

Constructor. Creates tc::sdk::rectangle instance with given width and height dimensions.

Parameters
positionthe position of the rectangle (top-left corner).
wthe width of the rectangle.
hthe height of the rectangle.

Definition at line 57 of file rectangle.hpp.

◆ rectangle() [2/2]

template<typename T >
constexpr tc::sdk::rectangle< T >::rectangle ( x,
y,
w,
h 
)
inlineexplicitconstexprnoexcept

Constructor. Creates tc::sdk::rectangle instance with given width and height dimensions.

Parameters
xthe x coordinate of the rectangle position (top-left corner).
ythe y coordinate of the rectangle position (top-left corner).
wthe width of the rectangle.
hthe height of the rectangle.

Definition at line 71 of file rectangle.hpp.

Member Function Documentation

◆ operator==()

template<typename T >
constexpr bool tc::sdk::rectangle< T >::operator== ( const rectangle< T > &  other) const
inlineconstexprnoexcept

Equality operator.

Parameters
otherthe rectangle to compare against.
Returns
true if the two rectangles have the same dimensions and the same position.

Definition at line 93 of file rectangle.hpp.

◆ operator!=()

template<typename T >
constexpr bool tc::sdk::rectangle< T >::operator!= ( const rectangle< T > &  other) const
inlineconstexprnoexcept

Inequality operator.

Parameters
otherthe rectangle to compare against.
Returns
true if the two rectangles have the different dimensions or different position.

Definition at line 105 of file rectangle.hpp.

◆ is_null()

template<typename T >
constexpr bool tc::sdk::rectangle< T >::is_null ( ) const
inlineconstexprnoexcept

Check if the rectangle is the null.

Returns
true if both width and height are zero or negative.

Definition at line 114 of file rectangle.hpp.

◆ width()

template<typename T >
constexpr T tc::sdk::rectangle< T >::width ( ) const
inlineconstexprnoexcept

Width dimension getter.

Returns
Width dimension of the rectangle.

Definition at line 123 of file rectangle.hpp.

◆ height()

template<typename T >
constexpr T tc::sdk::rectangle< T >::height ( ) const
inlineconstexprnoexcept

Height dimension getter.

Returns
Height dimension of the rectangle.

Definition at line 132 of file rectangle.hpp.

◆ set_width()

template<typename T >
void tc::sdk::rectangle< T >::set_width ( width)
inlinenoexcept

Width coordinate setter. Set the width dimension of the rectangle.

Definition at line 140 of file rectangle.hpp.

◆ set_height()

template<typename T >
void tc::sdk::rectangle< T >::set_height ( height)
inlinenoexcept

Height coordinate setter. Set the height dimension of the rectangle.

Definition at line 148 of file rectangle.hpp.

◆ set_size()

template<typename T >
constexpr void tc::sdk::rectangle< T >::set_size ( width,
height 
)
inlineconstexprnoexcept

Size setter.

Returns
Set the size of the rectangle.

Definition at line 157 of file rectangle.hpp.

◆ set_position()

template<typename T >
constexpr void tc::sdk::rectangle< T >::set_position ( tc::sdk::point< T >  position)
inlineconstexprnoexcept

Set the rectangle position.

Parameters
positionthe new top left coordinate of the rectangle.

Definition at line 167 of file rectangle.hpp.

◆ top_left()

template<typename T >
constexpr tc::sdk::point< T > tc::sdk::rectangle< T >::top_left ( ) const
inlineconstexprnoexcept

Top left coordinate getter.

Returns
Top left coordinate of the rectangle.

Definition at line 176 of file rectangle.hpp.

◆ top_right()

template<typename T >
constexpr tc::sdk::point< T > tc::sdk::rectangle< T >::top_right ( ) const
inlineconstexprnoexcept

Top right coordinate getter.

Returns
Top right coordinate of the rectangle.

Definition at line 185 of file rectangle.hpp.

◆ bottom_left()

template<typename T >
constexpr tc::sdk::point< T > tc::sdk::rectangle< T >::bottom_left ( ) const
inlineconstexprnoexcept

Bottom left coordinate getter.

Returns
Bottom left coordinate of the rectangle.

Definition at line 194 of file rectangle.hpp.

◆ bottom_right()

template<typename T >
constexpr tc::sdk::point< T > tc::sdk::rectangle< T >::bottom_right ( ) const
inlineconstexprnoexcept

Bottom right coordinate getter.

Returns
Bottom right coordinate of the rectangle.

Definition at line 203 of file rectangle.hpp.

◆ size()

template<typename T >
constexpr tc::sdk::size< T > tc::sdk::rectangle< T >::size ( ) const
inlineconstexprnoexcept

Size getter.

Returns
The size of the rectangle.

Definition at line 212 of file rectangle.hpp.

◆ area()

template<typename T >
constexpr T tc::sdk::rectangle< T >::area ( ) const
inlineconstexprnoexcept

Area getter.

Returns
The area of the rectangle.

Definition at line 221 of file rectangle.hpp.

◆ center()

template<typename T >
constexpr tc::sdk::point< double > tc::sdk::rectangle< T >::center ( ) const
inlineconstexprnoexcept

Center getter.

Returns
The center coordinate of the rectangle.

Definition at line 230 of file rectangle.hpp.

◆ contains() [1/2]

template<typename T >
bool tc::sdk::rectangle< T >::contains ( tc::sdk::point< T >  point) const
inlinenoexcept

Check if the given point is strictly contained within the current rectangle.

Parameters
pointThe point that is checked.
Returns
true if the point is strictly contained in the current rectangle.

Definition at line 240 of file rectangle.hpp.

◆ contains() [2/2]

template<typename T >
bool tc::sdk::rectangle< T >::contains ( tc::sdk::rectangle< T >  other) const
inlinenoexcept

Check if the given rectangle is strictly contained within the current rectangle.

Parameters
otherThe rectangle that is checked.
Returns
true if the other rectangle is strictly contained in the current rectangle.

Definition at line 253 of file rectangle.hpp.

◆ intersects() [1/2]

template<typename T >
bool tc::sdk::rectangle< T >::intersects ( tc::sdk::rectangle< T >  other) const
inlinenoexcept

Check if the given rectangle overlaps the current rectangle.

Parameters
otherThe rectangle to check the intersection with.
Returns
true if this and the other rectangles are overlapped.

Definition at line 266 of file rectangle.hpp.

◆ intersects() [2/2]

template<typename T >
bool tc::sdk::rectangle< T >::intersects ( tc::sdk::line< T >  line) const
inlinenoexcept

Check if the given line pass through the current rectangle.

Parameters
lineThe line to check the intersection with.
Returns
true if the given line intersects the current rectangle.

Definition at line 281 of file rectangle.hpp.

◆ get_intersection()

template<typename T >
tc::sdk::rectangle< T > tc::sdk::rectangle< T >::get_intersection ( tc::sdk::rectangle< T >  other) const
inlinenoexcept

Returns the region that is the overlap between this and another rectangle. If the two rectangles don't overlap, the rectangle returned will be empty.

Definition at line 294 of file rectangle.hpp.

◆ get_union()

template<typename T >
tc::sdk::rectangle< T > tc::sdk::rectangle< T >::get_union ( tc::sdk::rectangle< T >  other) const
inlinenoexcept

Returns the smallest rectangle that contains both this one and the one passed-in.

If either this or the other rectangle are empty, they will not be counted as part of the resulting region.

Definition at line 319 of file rectangle.hpp.

◆ translate()

template<typename T >
void tc::sdk::rectangle< T >::translate ( delta_x,
delta_y 
)
inlinenoexcept

Translate the rectangle by a given delta_x and delta_y offsets.

Parameters
delta_xthe offset to be applied on the x direction
delta_ythe offset to be applied on the y direction

Definition at line 342 of file rectangle.hpp.

◆ translated()

template<typename T >
tc::sdk::rectangle< T > tc::sdk::rectangle< T >::translated ( delta_x,
delta_y 
) const
inlinenoexcept

Create a copy of the rectangle translated by a given delta_x and delta_y offsets.

Parameters
delta_xthe offset to be applied on the x direction
delta_ythe offset to be applied on the y direction
Returns
a translated copy of the current rectangle

Definition at line 353 of file rectangle.hpp.

◆ to_string()

template<typename T >
constexpr std::string tc::sdk::rectangle< T >::to_string ( ) const
inlineconstexpr

Get the rectangle string representation.

Returns
String representation of the current rectangle.

Definition at line 364 of file rectangle.hpp.

Friends And Related Symbol Documentation

◆ operator<<

template<typename T >
std::ostream & operator<< ( std::ostream &  stream,
const rectangle< T > &  r 
)
friend

Output stream operator.

Parameters
streamthe output stream to write into.
rthe rectangle object to stream.
Returns
reference to the output stream operator, with the rectangle string representation written into it.

Definition at line 375 of file rectangle.hpp.


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