HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
hi::v1::aarectangle Class Reference

#include <hikogui/geometry/aarectangle.hpp>

Public Types

using array_type = simd<float, 4>
using value_type = array_type::value_type

Public Member Functions

constexpr aarectangle (aarectangle const &rhs) noexcept=default
constexpr aarectangle & operator= (aarectangle const &rhs) noexcept=default
constexpr aarectangle (aarectangle &&rhs) noexcept=default
constexpr aarectangle & operator= (aarectangle &&rhs) noexcept=default
constexpr aarectangle (array_type const &other) noexcept
constexpr aarectangle (float x, float y, float width, float height) noexcept
 Create a box from the position and size.
constexpr aarectangle (extent2 const &extent) noexcept
 Create a rectangle from the size.
constexpr aarectangle (point2 const &p0, point2 const &p3) noexcept
 Create a rectangle from the left-bottom and right-top points.
constexpr aarectangle (point2 const &p0, extent2 const &extent) noexcept
 Create a rectangle from the size.
constexpr operator array_type () const noexcept
constexpr bool holds_invariant () const noexcept
 Make sure p0 is left/bottom from p3.
constexpr bool empty () const noexcept
 Check if the rectangle has no area.
constexpr operator bool () const noexcept
 True when the rectangle has an area.
constexpr aarectangle & operator|= (aarectangle const &rhs) noexcept
 Expand the current rectangle to include the new rectangle.
constexpr aarectangle & operator|= (point2 const &rhs) noexcept
 Expand the current rectangle to include the new rectangle.
constexpr point2 operator[] (std::size_t i) const noexcept
constexpr extent2 size () const noexcept
 Get size of the rectangle.
constexpr value_type x () const noexcept
constexpr value_type y () const noexcept
constexpr value_type width () const noexcept
constexpr value_type height () const noexcept
constexpr value_type bottom () const noexcept
constexpr value_type top () const noexcept
constexpr value_type left () const noexcept
constexpr value_type right () const noexcept
constexpr value_type middle () const noexcept
 The middle on the y-axis between bottom and top.
constexpr value_type center () const noexcept
 The center on the x-axis between left and right.
constexpr aarectangle & set_width (value_type newWidth) noexcept
constexpr aarectangle & set_height (value_type newHeight) noexcept
constexpr bool contains (point2 const &rhs) const noexcept
 Check if a 2D coordinate is inside the rectangle.
constexpr bool contains (point3 const &rhs) const noexcept
 Check if a 3D coordinate is inside the rectangle.

Static Public Member Functions

static constexpr aarectangle large () noexcept
 Create a large axis aligned rectangle.
static constexpr aarectangle _align (aarectangle outside, aarectangle inside, alignment alignment) noexcept
 Need to call the hidden friend function from within another class.

Friends

template<int I>
constexpr friend point2 get (aarectangle const &rhs) noexcept
constexpr friend point2 midpoint (aarectangle const &rhs) noexcept
 Get the center of the rectangle.
constexpr aarectangle align (aarectangle haystack, extent2 needle, alignment alignment) noexcept
 Align a rectangle within another rectangle.
constexpr aarectangle align (aarectangle haystack, aarectangle needle, alignment alignment) noexcept
 Align a rectangle within another rectangle.
constexpr bool operator== (aarectangle const &lhs, aarectangle const &rhs) noexcept
constexpr bool overlaps (aarectangle const &lhs, aarectangle const &rhs) noexcept
constexpr aarectangle operator| (aarectangle const &lhs, aarectangle const &rhs) noexcept
constexpr aarectangle operator| (aarectangle const &lhs, point2 const &rhs) noexcept
constexpr aarectangle operator* (aarectangle const &lhs, value_type rhs) noexcept
 Expand the rectangle for the same amount in all directions.
constexpr aarectangle operator+ (aarectangle const &lhs, value_type rhs) noexcept
 Expand the rectangle for the same amount in all directions.
constexpr aarectangle & operator+= (aarectangle &lhs, value_type rhs) noexcept
constexpr aarectangle operator- (aarectangle const &lhs, value_type rhs) noexcept
 Shrink the rectangle for the same amount in all directions.
constexpr aarectangle & operator-= (aarectangle &lhs, value_type rhs) noexcept
constexpr aarectangle round (aarectangle const &rhs) noexcept
constexpr aarectangle ceil (aarectangle const &rhs) noexcept
 Round rectangle by expanding to pixel edge.
constexpr aarectangle ceil (aarectangle const &lhs, extent2 const &rhs) noexcept
 Round rectangle by expanding to a certain granularity.
constexpr aarectangle floor (aarectangle const &rhs) noexcept
 Round rectangle by shrinking to pixel edge.
constexpr aarectangle bounding_rectangle (aarectangle const &rhs) noexcept
constexpr aarectangle intersect (aarectangle const &lhs, aarectangle const &rhs) noexcept
 Return the overlapping part of two rectangles.
value_type distance (aarectangle const &lhs, point2 const &rhs) noexcept

Detailed Description

Class which represents an axis-aligned rectangle.

Constructor & Destructor Documentation

◆ aarectangle() [1/4]

hi::v1::aarectangle::aarectangle ( float x,
float y,
float width,
float height )
inlineconstexprnoexcept

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.

◆ aarectangle() [2/4]

hi::v1::aarectangle::aarectangle ( extent2 const & extent)
inlineexplicitconstexprnoexcept

Create a rectangle from the size.

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

Parameters
extentThe size of the box.

◆ aarectangle() [3/4]

hi::v1::aarectangle::aarectangle ( point2 const & p0,
point2 const & p3 )
inlineconstexprnoexcept

Create a rectangle from the left-bottom and right-top points.

Parameters
p0The left bottom point.
p3The right opt point.

◆ aarectangle() [4/4]

hi::v1::aarectangle::aarectangle ( point2 const & p0,
extent2 const & extent )
inlineconstexprnoexcept

Create a rectangle from the size.

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

Parameters
p0The left-bottom point where the rectangle starts.
extentThe size of the rectangle.

Member Function Documentation

◆ _align()

constexpr aarectangle hi::v1::aarectangle::_align ( aarectangle outside,
aarectangle inside,
alignment alignment )
inlinestaticnodiscardconstexprnoexcept

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

◆ center()

value_type hi::v1::aarectangle::center ( ) const
inlinenodiscardconstexprnoexcept

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

◆ contains() [1/2]

bool hi::v1::aarectangle::contains ( point2 const & rhs) const
inlinenodiscardconstexprnoexcept

Check if a 2D coordinate is inside the rectangle.

Parameters
rhsThe coordinate of the point to test.

◆ contains() [2/2]

bool hi::v1::aarectangle::contains ( point3 const & rhs) const
inlinenodiscardconstexprnoexcept

Check if a 3D coordinate is inside the rectangle.

Parameters
rhsThe coordinate of the point to test. This point is converted to 2D by this function.

◆ empty()

bool hi::v1::aarectangle::empty ( ) const
inlinenodiscardconstexprnoexcept

Check if the rectangle has no area.

◆ holds_invariant()

bool hi::v1::aarectangle::holds_invariant ( ) const
inlinenodiscardconstexprnoexcept

Make sure p0 is left/bottom from p3.

Returns
True is p0 is left and below p3.

◆ large()

constexpr aarectangle hi::v1::aarectangle::large ( )
inlinestaticnodiscardconstexprnoexcept

Create a large axis aligned rectangle.

◆ middle()

value_type hi::v1::aarectangle::middle ( ) const
inlinenodiscardconstexprnoexcept

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

◆ operator bool()

hi::v1::aarectangle::operator bool ( ) const
inlineexplicitnodiscardconstexprnoexcept

True when the rectangle has an area.

◆ operator|=() [1/2]

aarectangle & hi::v1::aarectangle::operator|= ( aarectangle const & rhs)
inlineconstexprnoexcept

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]

aarectangle & hi::v1::aarectangle::operator|= ( point2 const & rhs)
inlineconstexprnoexcept

Expand the current rectangle to include the new rectangle.

This is mostly used for extending bounding a bounding box.

Parameters
rhsA new point to include in the current rectangle.

◆ size()

extent2 hi::v1::aarectangle::size ( ) const
inlinenodiscardconstexprnoexcept

Get size of the rectangle.

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

◆ align [1/2]

aarectangle align ( aarectangle haystack,
aarectangle 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.

◆ align [2/2]

aarectangle align ( aarectangle haystack,
extent2 needle,
alignment alignment )
friend

Align a rectangle within another rectangle.

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

◆ ceil [1/2]

aarectangle ceil ( aarectangle const & lhs,
extent2 const & rhs )
friend

Round rectangle by expanding to a certain granularity.

◆ ceil [2/2]

aarectangle ceil ( aarectangle const & rhs)
friend

Round rectangle by expanding to pixel edge.

◆ floor

aarectangle floor ( aarectangle const & rhs)
friend

Round rectangle by shrinking to pixel edge.

◆ intersect

aarectangle intersect ( aarectangle const & lhs,
aarectangle const & rhs )
friend

Return the overlapping part of two rectangles.

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

◆ midpoint

friend point2 midpoint ( aarectangle const & rhs)
friend

Get the center of the rectangle.

◆ operator*

aarectangle operator* ( aarectangle const & lhs,
value_type 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.

◆ operator+

aarectangle operator+ ( aarectangle const & lhs,
value_type 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.

◆ operator-

aarectangle operator- ( aarectangle const & lhs,
value_type 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: