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.
 
double calculate_iou (const tc::sdk::rectangle< T > &other) const noexcept
 Calculate Intersection over Union (IoU) with another rectangle.
 
tc::sdk::rectangle< T > reshape (T input_width, T input_height, T output_width, T output_height) const noexcept
 Transform this rectangle from input coordinate space back to output coordinate space. This method handles the inverse transformation of letterboxing/padding applied during scaling.
 
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 34 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 58 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 72 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 94 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 106 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 115 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 124 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 133 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 141 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 149 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 158 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 168 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 177 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 186 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 195 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 204 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 213 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 222 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 231 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 241 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 254 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 267 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 282 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 295 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 320 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 343 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 354 of file rectangle.hpp.

◆ calculate_iou()

template<typename T >
double tc::sdk::rectangle< T >::calculate_iou ( const tc::sdk::rectangle< T > &  other) const
inlinenoexcept

Calculate Intersection over Union (IoU) with another rectangle.

Parameters
otherThe rectangle to calculate IoU with.
Returns
The IoU value as a ratio of the intersection area to the union area.

Definition at line 366 of file rectangle.hpp.

◆ reshape()

template<typename T >
tc::sdk::rectangle< T > tc::sdk::rectangle< T >::reshape ( input_width,
input_height,
output_width,
output_height 
) const
inlinenoexcept

Transform this rectangle from input coordinate space back to output coordinate space. This method handles the inverse transformation of letterboxing/padding applied during scaling.

Parameters
input_widthThe width of the input coordinate space.
input_heightThe height of the input coordinate space.
output_widthThe width of the output coordinate space.
output_heightThe height of the output coordinate space.
Returns
A rectangle transformed back to output coordinates.

Definition at line 401 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 461 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 472 of file rectangle.hpp.


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