HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends
tt::axis_aligned_rectangle< T > Class Template Reference

#include <ttauri/aarect.hpp>

Public Member Functions

 axis_aligned_rectangle (axis_aligned_rectangle const &rhs) noexcept=default
 
axis_aligned_rectangleoperator= (axis_aligned_rectangle const &rhs) noexcept=default
 
 axis_aligned_rectangle (axis_aligned_rectangle &&rhs) noexcept=default
 
axis_aligned_rectangleoperator= (axis_aligned_rectangle &&rhs) noexcept=default
 
 axis_aligned_rectangle (tt::arithmetic auto x, tt::arithmetic auto y, tt::arithmetic auto width, tt::arithmetic auto height) noexcept
 Create a box from the position and size.
 
 axis_aligned_rectangle (tt::arithmetic auto width, tt::arithmetic auto height) noexcept
 Create a box from the position and size.
 
 axis_aligned_rectangle (numeric_array< T, 4 > const &position, numeric_array< T, 4 > const &extent) noexcept
 Create a rectangle from the position and size.
 
 axis_aligned_rectangle (numeric_array< T, 4 > const &extent) noexcept
 Create a rectangle from the size.
 
bool valid () const noexcept
 Make sure p0 is left/bottom from p3.
 
bool empty () const noexcept
 Check if the rectangle has no area.
 
 operator bool () const noexcept
 True when the rectangle has an area.
 
axis_aligned_rectangleoperator|= (axis_aligned_rectangle const &rhs) noexcept
 Expand the current rectangle to include the new rectangle.
 
axis_aligned_rectangleoperator|= (numeric_array< T, 4 > const &rhs) noexcept
 Expand the current rectangle to include the new point.
 
axis_aligned_rectangleoperator+= (numeric_array< T, 4 > const &rhs) noexcept
 Translate the box to a new position.
 
axis_aligned_rectangleoperator-= (numeric_array< T, 4 > const &rhs) noexcept
 Translate the box to a new position.
 
axis_aligned_rectangleoperator*= (T rhs) noexcept
 Scale the box by moving the positions (scaling the vectors).
 
template<size_t I>
numeric_array< T, 4 > corner () const noexcept
 Get coordinate of a corner.
 
numeric_array< T, 4 > p0 () const noexcept
 
numeric_array< T, 4 > p3 () const noexcept
 
numeric_array< T, 4 > offset () const noexcept
 Get vector from origin to the bottom-left corner.
 
numeric_array< T, 4 > extent () const noexcept
 Get size of the rectangle.
 
x () const noexcept
 
y () const noexcept
 
width () const noexcept
 
height () const noexcept
 
bottom () const noexcept
 
top () const noexcept
 
left () const noexcept
 
right () const noexcept
 
middle () const noexcept
 The middle on the y-axis between bottom and top.
 
center () const noexcept
 The center on the x-axis between left and right.
 
axis_aligned_rectangleset_width (T newWidth) noexcept
 
axis_aligned_rectangleset_height (T newHeight) noexcept
 
bool contains (numeric_array< T, 4 > const &rhs) const noexcept
 Check if a 2D coordinate is inside the rectangle.
 

Static Public Member Functions

static axis_aligned_rectangle p0p3 (numeric_array< T, 4 > const &v) noexcept
 Create axis_aligned_rectangle from packed p0p3 coordinates.
 
static axis_aligned_rectangle p0p3 (numeric_array< T, 4 > const &p0, numeric_array< T, 4 > const &p3) noexcept
 Create axis_aligned_rectangle from two oposite points.
 
static axis_aligned_rectangle infinity () noexcept
 
static axis_aligned_rectangle _align (axis_aligned_rectangle outside, axis_aligned_rectangle inside, alignment alignment) noexcept
 Need to call the hiden friend function from within another class.
 

Friends

class sfloat_rgba32
 
axis_aligned_rectangle align (axis_aligned_rectangle haystack, axis_aligned_rectangle needle, alignment alignment) noexcept
 Align a rectangle within another rectangle.
 
bool operator== (axis_aligned_rectangle const &lhs, axis_aligned_rectangle const &rhs) noexcept
 
bool operator!= (axis_aligned_rectangle const &lhs, axis_aligned_rectangle const &rhs) noexcept
 
bool overlaps (axis_aligned_rectangle const &lhs, axis_aligned_rectangle const &rhs) noexcept
 
axis_aligned_rectangle operator| (axis_aligned_rectangle const &lhs, axis_aligned_rectangle const &rhs) noexcept
 
axis_aligned_rectangle operator| (axis_aligned_rectangle const &lhs, numeric_array< T, 4 > const &rhs) noexcept
 
axis_aligned_rectangle operator+ (axis_aligned_rectangle const &lhs, numeric_array< T, 4 > const &rhs) noexcept
 
axis_aligned_rectangle operator- (axis_aligned_rectangle const &lhs, numeric_array< T, 4 > const &rhs) noexcept
 
axis_aligned_rectangle operator* (axis_aligned_rectangle const &lhs, T rhs) noexcept
 
numeric_array< T, 4 > center (axis_aligned_rectangle const &rhs) noexcept
 Get the center of the rectangle.
 
axis_aligned_rectangle scale (axis_aligned_rectangle const &lhs, T rhs) noexcept
 Expand the rectangle for the same amount in all directions.
 
axis_aligned_rectangle expand (axis_aligned_rectangle const &lhs, T rhs) noexcept
 Expand the rectangle for the same amount in all directions.
 
axis_aligned_rectangle expand (axis_aligned_rectangle const &lhs, numeric_array< T, 4 > rhs) noexcept
 Expand the rectangle for the same amount in all directions.
 
axis_aligned_rectangle shrink (axis_aligned_rectangle const &lhs, T rhs) noexcept
 Shrink the rectangle for the same amount in all directions.
 
axis_aligned_rectangle shrink (axis_aligned_rectangle const &lhs, numeric_array< T, 4 > rhs) noexcept
 Shrink the rectangle for the same amount in all directions.
 
axis_aligned_rectangle round (axis_aligned_rectangle const &rhs) noexcept
 
axis_aligned_rectangle ceil (axis_aligned_rectangle const &rhs) noexcept
 Round rectangle by expanding to pixel edge.
 
axis_aligned_rectangle floor (axis_aligned_rectangle const &rhs) noexcept
 Round rectangle by shrinking to pixel edge.
 
axis_aligned_rectangle intersect (axis_aligned_rectangle const &lhs, axis_aligned_rectangle const &rhs) noexcept
 Return the overlapping part of two rectangles.
 
axis_aligned_rectangle fit (axis_aligned_rectangle const &bounds, axis_aligned_rectangle const &rectangle) noexcept
 Make a rectangle fit inside bounds.
 

Detailed Description

template<typename T>
class tt::axis_aligned_rectangle< T >

Class which represents an axis-aligned rectangle.

Constructor & Destructor Documentation

◆ axis_aligned_rectangle() [1/4]

template<typename T >
tt::axis_aligned_rectangle< T >::axis_aligned_rectangle ( tt::arithmetic auto x,
tt::arithmetic auto y,
tt::arithmetic auto width,
tt::arithmetic auto height )
inlinenoexcept

Create a box from the position and size.

Parameters
xThe x location of the left-bottom corner of the box
yThe y location of the left-bottom corner of the box
widthThe width of the box.
heightThe height of the box.

◆ axis_aligned_rectangle() [2/4]

template<typename T >
tt::axis_aligned_rectangle< T >::axis_aligned_rectangle ( tt::arithmetic auto width,
tt::arithmetic auto height )
inlinenoexcept

Create a box from the position and size.

Parameters
widthThe width of the box.
heightThe height of the box.

◆ axis_aligned_rectangle() [3/4]

template<typename T >
tt::axis_aligned_rectangle< T >::axis_aligned_rectangle ( numeric_array< T, 4 > const & position,
numeric_array< T, 4 > const & extent )
inlinenoexcept

Create a rectangle from the position and size.

Parameters
positionThe position of the left-bottom corner of the box
extentThe size of the box.

◆ axis_aligned_rectangle() [4/4]

template<typename T >
tt::axis_aligned_rectangle< T >::axis_aligned_rectangle ( numeric_array< T, 4 > const & extent)
inlineexplicitnoexcept

Create a rectangle from the size.

The rectangle's left bottom corner is at the origin.

Parameters
extentThe size of the box.

Member Function Documentation

◆ _align()

template<typename T >
static axis_aligned_rectangle tt::axis_aligned_rectangle< T >::_align ( axis_aligned_rectangle< T > outside,
axis_aligned_rectangle< T > inside,
alignment alignment )
inlinestaticnoexcept

Need to call the hiden friend function from within another class.

◆ center()

template<typename T >
T tt::axis_aligned_rectangle< T >::center ( ) const
inlinenoexcept

The center on the x-axis between left and right.

◆ contains()

template<typename T >
bool tt::axis_aligned_rectangle< T >::contains ( numeric_array< T, 4 > const & rhs) const
inlinenoexcept

Check if a 2D coordinate is inside the rectangle.

Parameters
rhsThe coordinate of the point to test.

◆ corner()

template<typename T >
template<size_t I>
numeric_array< T, 4 > tt::axis_aligned_rectangle< T >::corner ( ) const
inlinenoexcept

Get coordinate of a corner.

Parameters
ICorner number: 0 = left-bottom, 1 = right-bottom, 2 = left-top, 3 = right-top.
Returns
The homogeneous coordinate of the corner.

◆ empty()

template<typename T >
bool tt::axis_aligned_rectangle< T >::empty ( ) const
inlinenoexcept

Check if the rectangle has no area.

◆ extent()

template<typename T >
numeric_array< T, 4 > tt::axis_aligned_rectangle< T >::extent ( ) const
inlinenoexcept

Get size of the rectangle.

Returns
The (x, y) vector representing the width and height of the rectangle.

◆ middle()

template<typename T >
T tt::axis_aligned_rectangle< T >::middle ( ) const
inlinenoexcept

The middle on the y-axis between bottom and top.

◆ offset()

template<typename T >
numeric_array< T, 4 > tt::axis_aligned_rectangle< T >::offset ( ) const
inlinenoexcept

Get vector from origin to the bottom-left corner.

Returns
The homogeneous coordinate of the bottom-left corner.

◆ operator bool()

template<typename T >
tt::axis_aligned_rectangle< T >::operator bool ( ) const
inlinenoexcept

True when the rectangle has an area.

◆ operator*=()

template<typename T >
axis_aligned_rectangle & tt::axis_aligned_rectangle< T >::operator*= ( T rhs)
inlinenoexcept

Scale the box by moving the positions (scaling the vectors).

Parameters
rhsBy how much to scale the positions of the two points

◆ operator+=()

template<typename T >
axis_aligned_rectangle & tt::axis_aligned_rectangle< T >::operator+= ( numeric_array< T, 4 > const & rhs)
inlinenoexcept

Translate the box to a new position.

Parameters
rhsThe vector to add to the coordinates of the rectangle.

◆ operator-=()

template<typename T >
axis_aligned_rectangle & tt::axis_aligned_rectangle< T >::operator-= ( numeric_array< T, 4 > const & rhs)
inlinenoexcept

Translate the box to a new position.

Parameters
rhsThe vector to subtract from the coordinates of the rectangle.

◆ operator|=() [1/2]

template<typename T >
axis_aligned_rectangle & tt::axis_aligned_rectangle< T >::operator|= ( axis_aligned_rectangle< T > const & rhs)
inlinenoexcept

Expand the current rectangle to include the new rectangle.

This is mostly used for extending bounding a bounding box.

Parameters
rhsThe new rectangle to include in the current rectangle.

◆ operator|=() [2/2]

template<typename T >
axis_aligned_rectangle & tt::axis_aligned_rectangle< T >::operator|= ( numeric_array< T, 4 > const & rhs)
inlinenoexcept

Expand the current rectangle to include the new point.

This is mostly used for extending bounding a bounding box.

Parameters
rhsThe new rectangle to include in the current rectangle.

◆ p0p3() [1/2]

template<typename T >
static axis_aligned_rectangle tt::axis_aligned_rectangle< T >::p0p3 ( numeric_array< T, 4 > const & p0,
numeric_array< T, 4 > const & p3 )
inlinestaticnoexcept

Create axis_aligned_rectangle from two oposite points.

Parameters
p0The left bottom corner.
p3The right top corner.

◆ p0p3() [2/2]

template<typename T >
static axis_aligned_rectangle tt::axis_aligned_rectangle< T >::p0p3 ( numeric_array< T, 4 > const & v)
inlinestaticnoexcept

Create axis_aligned_rectangle from packed p0p3 coordinates.

Parameters
vp0 = (x, y), p3 = (z, w)

◆ valid()

template<typename T >
bool tt::axis_aligned_rectangle< T >::valid ( ) const
inlinenoexcept

Make sure p0 is left/bottom from p3.

Returns
True is p0 is left and below p3.

Friends And Related Symbol Documentation

◆ align

template<typename T >
axis_aligned_rectangle align ( axis_aligned_rectangle< T > haystack,
axis_aligned_rectangle< T > needle,
alignment alignment )
friend

Align a rectangle within another rectangle.

Parameters
haystackThe outside rectangle
needleThe inside rectangle; to be aligned.
alignmentHow the inside rectangle should be aligned.
Returns
The needle rectangle repositioned and aligned inside the haystack.

◆ ceil

template<typename T >
axis_aligned_rectangle ceil ( axis_aligned_rectangle< T > const & rhs)
friend

Round rectangle by expanding to pixel edge.

◆ center

template<typename T >
numeric_array< T, 4 > center ( axis_aligned_rectangle< T > const & rhs)
friend

Get the center of the rectangle.

◆ expand [1/2]

template<typename T >
axis_aligned_rectangle expand ( axis_aligned_rectangle< T > const & lhs,
numeric_array< T, 4 > rhs )
friend

Expand the rectangle for the same amount in all directions.

Parameters
lhsThe original rectangle.
rhsHow much should be added on each side of the rectangle, this value may be zero or negative.
Returns
A new rectangle expanded on each side.

◆ expand [2/2]

template<typename T >
axis_aligned_rectangle expand ( axis_aligned_rectangle< T > const & lhs,
T rhs )
friend

Expand the rectangle for the same amount in all directions.

Parameters
lhsThe original rectangle.
rhsHow much should be added on each side of the rectangle, this value may be zero or negative.
Returns
A new rectangle expanded on each side.

◆ fit

template<typename T >
axis_aligned_rectangle fit ( axis_aligned_rectangle< T > const & bounds,
axis_aligned_rectangle< T > const & rectangle )
friend

Make a rectangle fit inside bounds.

This algorithm will try to first move the rectangle and resist resizing it.

Parameters
boundsThe bounding box.
rectangleThe rectangle to fit inside the bounds.
Returns
A rectangle that fits inside the bounds

◆ floor

template<typename T >
axis_aligned_rectangle floor ( axis_aligned_rectangle< T > const & rhs)
friend

Round rectangle by shrinking to pixel edge.

◆ intersect

template<typename T >
axis_aligned_rectangle intersect ( axis_aligned_rectangle< T > const & lhs,
axis_aligned_rectangle< T > const & rhs )
friend

Return the overlapping part of two rectangles.

When the rectangles are not overlapping, the width and height are zero.

◆ scale

template<typename T >
axis_aligned_rectangle scale ( axis_aligned_rectangle< T > const & lhs,
T rhs )
friend

Expand the rectangle for the same amount in all directions.

Parameters
lhsThe original rectangle.
rhsHow much the width and height should be scaled by.
Returns
A new rectangle expanded on each side.

◆ shrink [1/2]

template<typename T >
axis_aligned_rectangle shrink ( axis_aligned_rectangle< T > const & lhs,
numeric_array< T, 4 > rhs )
friend

Shrink the rectangle for the same amount in all directions.

Parameters
lhsThe original rectangle.
rhsHow much should be added on each side of the rectangle, this value may be zero or negative.
Returns
A new rectangle shrank on each side.

◆ shrink [2/2]

template<typename T >
axis_aligned_rectangle shrink ( axis_aligned_rectangle< T > const & lhs,
T rhs )
friend

Shrink the rectangle for the same amount in all directions.

Parameters
lhsThe original rectangle.
rhsHow much should be added on each side of the rectangle, this value may be zero or negative.
Returns
A new rectangle shrank on each side.

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