Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
sf::TRectangle2D< T > Class Template Reference

Class to store and manipulate a rectangle based on floating point values. More...

#include <TRectangle2D.h>

Collaboration diagram for sf::TRectangle2D< T >:

Classes

union  data_type
 Rectangle structure for binary storage purposes. More...
 

Public Types

typedef T value_type
 Type accessible when implemented.
 

Public Member Functions

 TRectangle2D ()=default
 Default constructor.
 
 TRectangle2D (const TRectangle2D &rect)
 Copy constructor.
 
 TRectangle2D (const TRectangle2D &&rect) noexcept
 Move constructor.
 
 TRectangle2D (T left, T bottom, T right, T top)
 Initializing constructor.
 
 TRectangle2D (std::initializer_list< T > list)
 Initializer list constructor.
 
 TRectangle2D (const TVector2D< T > &loLeft, const TVector2D< T > &upRight)
 Initializing constructor using two points.
 
TRectangle2Dassign (const TRectangle2D &)
 Assigns new values from the passed instance.
 
TRectangle2Dassign (T left, T bottom, T right, T top)
 Assigns new coordinate values.
 
TRectangle2Dassign (const TVector2D< T > &loLeft, const TVector2D< T > &upRight)
 Assigns new coordinate using two points.
 
TRectangle2DassignWidthHeight (T left, T bottom, T w, T h)
 Assigns new coordinates using position x, y, width and height values.
 
TRectangle2DassignWidthHeight (const TVector2D< T > &bottom_left, const TVector2D< T > &size)
 Assigns new coordinates using position and size vector.
 
void clear ()
 Empties the rectangle setting it to the initial state.
 
bool isEmpty () const
 Tests if all values are near zero according the tolerance value.
 
bool isEqual (const TRectangle2D &other, T tol=tolerance) const
 Compare passes rectangle with this instance taking the tolerance value in to account.
 
bool operator== (const TRectangle2D &) const
 Call the isEqual() function to compare.
 
bool operator!= (const TRectangle2D &) const
 Call the isEqual() function to compare.
 
bool contains (const TVector2D< T > &point) const
 Returns true when the passed point represented by a vector resides within this rectangle.
 
bool contains (const TRectangle2D &other) const
 Returns true when the passed rectangle resides within this rectangle.
 
bool touches (const TRectangle2D &other) const
 Returns true when the passed rectangle overlaps with this rectangle.
 
TVector2D< T > bottomLeft () const
 Gets the bottom-left corner of the rectangle as a vector.
 
TVector2D< T > topRight () const
 Gets the top-right corner of the rectangle as a vector.
 
TVector2D< T > bottomRight () const
 Gets the bottom-right corner of the rectangle as a vector.
 
TVector2D< T > topLeft () const
 Gets the top-left corner of the rectangle as a vector.
 
width () const
 Gets the width of the rectangle.
 
height () const
 Gets the height of the rectangle.
 
TVector2D< T > Size () const
 Gets the height and width of the rectangle as a vector.
 
area () const
 Gets the area formed by the rectangles width and height.
 
TVector2D< T > center () const
 Gets the center of the rectangle as vector.
 
TRectangle2Dnormalize ()
 Normalizes this instance so that top-right and bottom-left are correct.
 
TRectangle2D normalized () const
 Gets a normalized instance of this instance so that top-right and bottom-left are correct.
 
TRectangle2Doffset (T dx, T dy)
 Offsets this instance by the passed values x and y keeping the same size.
 
TRectangle2D offsetBy (T dx, T dy) const
 Gets an instance offset by the passed values x and y keeping the same size.
 
TRectangle2D movedTo (T x, T y)
 Gets a moved instance from this instance where left-bottom represented by the passed values x and y having the same size.
 
TRectangle2DmoveTo (T x, T y)
 Moves this instance to a different left-bottom represented by the passed values x and y having the same size.
 
TRectangle2Doperator+= (const TVector2D< T > &delta)
 Offsets this instance using the passed delta vector as a positive.
 
TRectangle2Doperator-= (const TVector2D< T > &delta)
 Offsets this instance using the passed delta vector as a negative.
 
TRectangle2Dinflate (T dx, T dy)
 Inflates this instance using the passed delta values for x and y.
 
TRectangle2Dinflate (const TVector2D< T > &delta)
 Inflates this instance using the passed delta vector (x, y).
 
TRectangle2D inflatedBy (T dx, T dy) const
 Gets an inflated rectangle using the passed delta values for x and y.
 
TRectangle2D inflatedBy (const TVector2D< T > &delta) const
 Gets inflated instance using the passed delta vector (x, y).
 
TRectangle2Doperator&= (const TRectangle2D &other)
 Sets this instance to the overlapping part of both rectangles.
 
TRectangle2D operator& (const TRectangle2D &other) const
 Gets an instance of the overlapping part of both rectangles.
 
TRectangle2Doperator|= (const TRectangle2D &other)
 Sets this instance to the combined rectangle containing both rectangles.
 
TRectangle2D operator| (const TRectangle2D &other) const
 Gets an instance of the combined rectangle containing both rectangles.
 
std::string toString () const
 Gets the string representation of the rectangle formed like '(left, bottom, right, top)'.
 
TRectangle2DfromString (const std::string &s) noexcept(false)
 Gets rectangle value from the string representation formed like '(left, bottom, right, top)'. Throws an exception when the string is not in the correct format.
 

Static Public Attributes

static constexpr auto tolerance = TVector2D<T>::tolerance
 Tolerance for when comparing in the equal operator. Used as: std::fabs(x1 - x2) < tolerance.
 

Protected Types

typedef TVector2D< T >::data_type::point_type point_type
 Use the same point type as the one of the 2D vector.
 

Protected Attributes

union sf::TRectangle2D::data_type _data
 

Detailed Description

template<typename T>
class sf::TRectangle2D< T >

Class to store and manipulate a rectangle based on floating point values.

Right-Top
+--------------+
| |
| |
| |
+--------------+
Left-Bottom

Member Typedef Documentation

◆ point_type

template<typename T >
typedef TVector2D<T>::data_type::point_type sf::TRectangle2D< T >::point_type
protected

Use the same point type as the one of the 2D vector.

◆ value_type

template<typename T >
typedef T sf::TRectangle2D< T >::value_type

Type accessible when implemented.

Constructor & Destructor Documentation

◆ TRectangle2D() [1/6]

template<typename T >
sf::TRectangle2D< T >::TRectangle2D ( )
default

Default constructor.

◆ TRectangle2D() [2/6]

template<typename T >
sf::TRectangle2D< T >::TRectangle2D ( const TRectangle2D< T > &  rect)

Copy constructor.

◆ TRectangle2D() [3/6]

template<typename T >
sf::TRectangle2D< T >::TRectangle2D ( const TRectangle2D< T > &&  rect)
noexcept

Move constructor.

◆ TRectangle2D() [4/6]

template<typename T >
sf::TRectangle2D< T >::TRectangle2D ( left,
bottom,
right,
top 
)

Initializing constructor.

◆ TRectangle2D() [5/6]

template<typename T >
sf::TRectangle2D< T >::TRectangle2D ( std::initializer_list< T >  list)

Initializer list constructor.

◆ TRectangle2D() [6/6]

template<typename T >
sf::TRectangle2D< T >::TRectangle2D ( const TVector2D< T > &  loLeft,
const TVector2D< T > &  upRight 
)

Initializing constructor using two points.

Member Function Documentation

◆ area()

template<typename T >
T sf::TRectangle2D< T >::area ( ) const

Gets the area formed by the rectangles width and height.

◆ assign() [1/3]

template<typename T >
TRectangle2D & sf::TRectangle2D< T >::assign ( const TRectangle2D< T > &  )

Assigns new values from the passed instance.

◆ assign() [2/3]

template<typename T >
TRectangle2D & sf::TRectangle2D< T >::assign ( const TVector2D< T > &  loLeft,
const TVector2D< T > &  upRight 
)

Assigns new coordinate using two points.

◆ assign() [3/3]

template<typename T >
TRectangle2D & sf::TRectangle2D< T >::assign ( left,
bottom,
right,
top 
)

Assigns new coordinate values.

◆ assignWidthHeight() [1/2]

template<typename T >
TRectangle2D & sf::TRectangle2D< T >::assignWidthHeight ( const TVector2D< T > &  bottom_left,
const TVector2D< T > &  size 
)

Assigns new coordinates using position and size vector.

◆ assignWidthHeight() [2/2]

template<typename T >
TRectangle2D & sf::TRectangle2D< T >::assignWidthHeight ( left,
bottom,
w,
h 
)

Assigns new coordinates using position x, y, width and height values.

◆ bottomLeft()

template<typename T >
TVector2D< T > sf::TRectangle2D< T >::bottomLeft ( ) const

Gets the bottom-left corner of the rectangle as a vector.

◆ bottomRight()

template<typename T >
TVector2D< T > sf::TRectangle2D< T >::bottomRight ( ) const

Gets the bottom-right corner of the rectangle as a vector.

◆ center()

template<typename T >
TVector2D< T > sf::TRectangle2D< T >::center ( ) const

Gets the center of the rectangle as vector.

◆ clear()

template<typename T >
void sf::TRectangle2D< T >::clear ( )

Empties the rectangle setting it to the initial state.

◆ contains() [1/2]

template<typename T >
bool sf::TRectangle2D< T >::contains ( const TRectangle2D< T > &  other) const

Returns true when the passed rectangle resides within this rectangle.

◆ contains() [2/2]

template<typename T >
bool sf::TRectangle2D< T >::contains ( const TVector2D< T > &  point) const

Returns true when the passed point represented by a vector resides within this rectangle.

◆ fromString()

template<typename T >
TRectangle2D & sf::TRectangle2D< T >::fromString ( const std::string &  s)

Gets rectangle value from the string representation formed like '(left, bottom, right, top)'. Throws an exception when the string is not in the correct format.

Exceptions
std::invalid_argument

◆ height()

template<typename T >
T sf::TRectangle2D< T >::height ( ) const

Gets the height of the rectangle.

◆ inflate() [1/2]

template<typename T >
TRectangle2D & sf::TRectangle2D< T >::inflate ( const TVector2D< T > &  delta)

Inflates this instance using the passed delta vector (x, y).

◆ inflate() [2/2]

template<typename T >
TRectangle2D & sf::TRectangle2D< T >::inflate ( dx,
dy 
)

Inflates this instance using the passed delta values for x and y.

◆ inflatedBy() [1/2]

template<typename T >
TRectangle2D sf::TRectangle2D< T >::inflatedBy ( const TVector2D< T > &  delta) const

Gets inflated instance using the passed delta vector (x, y).

◆ inflatedBy() [2/2]

template<typename T >
TRectangle2D sf::TRectangle2D< T >::inflatedBy ( dx,
dy 
) const

Gets an inflated rectangle using the passed delta values for x and y.

◆ isEmpty()

template<typename T >
bool sf::TRectangle2D< T >::isEmpty ( ) const

Tests if all values are near zero according the tolerance value.

See also
tolerance
Returns
True when empty.

◆ isEqual()

template<typename T >
bool sf::TRectangle2D< T >::isEqual ( const TRectangle2D< T > &  other,
tol = tolerance 
) const

Compare passes rectangle with this instance taking the tolerance value in to account.

See also
tolerance
Returns
True when equal.

◆ movedTo()

template<typename T >
TRectangle2D sf::TRectangle2D< T >::movedTo ( x,
y 
)

Gets a moved instance from this instance where left-bottom represented by the passed values x and y having the same size.

◆ moveTo()

template<typename T >
TRectangle2D & sf::TRectangle2D< T >::moveTo ( x,
y 
)

Moves this instance to a different left-bottom represented by the passed values x and y having the same size.

◆ normalize()

template<typename T >
TRectangle2D & sf::TRectangle2D< T >::normalize ( )

Normalizes this instance so that top-right and bottom-left are correct.

◆ normalized()

template<typename T >
TRectangle2D sf::TRectangle2D< T >::normalized ( ) const

Gets a normalized instance of this instance so that top-right and bottom-left are correct.

◆ offset()

template<typename T >
TRectangle2D & sf::TRectangle2D< T >::offset ( dx,
dy 
)

Offsets this instance by the passed values x and y keeping the same size.

◆ offsetBy()

template<typename T >
TRectangle2D sf::TRectangle2D< T >::offsetBy ( dx,
dy 
) const

Gets an instance offset by the passed values x and y keeping the same size.

◆ operator!=()

template<typename T >
bool sf::TRectangle2D< T >::operator!= ( const TRectangle2D< T > &  ) const

Call the isEqual() function to compare.

See also
isEqual()
Returns
True when unequal.

◆ operator&()

template<typename T >
TRectangle2D sf::TRectangle2D< T >::operator& ( const TRectangle2D< T > &  other) const

Gets an instance of the overlapping part of both rectangles.

◆ operator&=()

template<typename T >
TRectangle2D & sf::TRectangle2D< T >::operator&= ( const TRectangle2D< T > &  other)

Sets this instance to the overlapping part of both rectangles.

◆ operator+=()

template<typename T >
TRectangle2D & sf::TRectangle2D< T >::operator+= ( const TVector2D< T > &  delta)

Offsets this instance using the passed delta vector as a positive.

◆ operator-=()

template<typename T >
TRectangle2D & sf::TRectangle2D< T >::operator-= ( const TVector2D< T > &  delta)

Offsets this instance using the passed delta vector as a negative.

◆ operator==()

template<typename T >
bool sf::TRectangle2D< T >::operator== ( const TRectangle2D< T > &  ) const

Call the isEqual() function to compare.

See also
isEqual()
Returns
True when equal.

◆ operator|()

template<typename T >
TRectangle2D sf::TRectangle2D< T >::operator| ( const TRectangle2D< T > &  other) const

Gets an instance of the combined rectangle containing both rectangles.

◆ operator|=()

template<typename T >
TRectangle2D & sf::TRectangle2D< T >::operator|= ( const TRectangle2D< T > &  other)

Sets this instance to the combined rectangle containing both rectangles.

◆ Size()

template<typename T >
TVector2D< T > sf::TRectangle2D< T >::Size ( ) const

Gets the height and width of the rectangle as a vector.

◆ topLeft()

template<typename T >
TVector2D< T > sf::TRectangle2D< T >::topLeft ( ) const

Gets the top-left corner of the rectangle as a vector.

◆ topRight()

template<typename T >
TVector2D< T > sf::TRectangle2D< T >::topRight ( ) const

Gets the top-right corner of the rectangle as a vector.

◆ toString()

template<typename T >
std::string sf::TRectangle2D< T >::toString ( ) const

Gets the string representation of the rectangle formed like '(left, bottom, right, top)'.

◆ touches()

template<typename T >
bool sf::TRectangle2D< T >::touches ( const TRectangle2D< T > &  other) const

Returns true when the passed rectangle overlaps with this rectangle.

◆ width()

template<typename T >
T sf::TRectangle2D< T >::width ( ) const

Gets the width of the rectangle.

Member Data Documentation

◆ _data

template<typename T >
union sf::TRectangle2D::data_type sf::TRectangle2D< T >::_data
protected

◆ tolerance

template<typename T >
constexpr auto sf::TRectangle2D< T >::tolerance = TVector2D<T>::tolerance
staticconstexpr

Tolerance for when comparing in the equal operator. Used as: std::fabs(x1 - x2) < tolerance.


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