IDS peak IPL v1.18.0
Loading...
Searching...
No Matches
peak_common_rectangle.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
12
13#include <cstdint>
14#include <sstream>
15
16namespace peak
17{
18namespace common
19{
20
21namespace detail
22{
35template <typename PointType, typename SizeType>
37{
38
39public:
40 static_assert(std::is_arithmetic<PointType>::value, "Template argument of Rect must be arithmetic.");
41
49 constexpr RectangleT() = default;
50
59 constexpr RectangleT(const PointT<PointType>& point, const SizeT<SizeType>& size)
60 : m_point(point)
61 , m_size(size)
62 {}
63
74 constexpr RectangleT(PointType x, PointType y, SizeType width, SizeType height)
75 : RectangleT({ x, y }, { width, height })
76 {}
77
84 PEAK_COMMON_NO_DISCARD constexpr PointType GetX() const
85 {
86 return m_point.GetX();
87 }
88
94 PEAK_COMMON_NO_DISCARD constexpr PointType GetY() const
95 {
96 return m_point.GetY();
97 }
98
104 PEAK_COMMON_NO_DISCARD constexpr SizeType GetWidth() const
105 {
106 return m_size.GetWidth();
107 }
108
115 PEAK_COMMON_NO_DISCARD constexpr SizeType GetHeight() const
116 {
117 return m_size.GetHeight();
118 }
119
124 {
125 return m_size;
126 }
127
132 {
133 return m_point;
134 }
135
146 template <typename RhsPointType, typename RhsSizeType>
147 constexpr bool operator==(const RectangleT<RhsPointType, RhsSizeType>& rhs) const
148 {
149 return GetPosition() == rhs.GetPosition() && GetSize() == rhs.GetSize();
150 }
151
162 template <typename RhsPointType, typename RhsSizeType>
163 constexpr bool operator!=(const RectangleT<RhsPointType, RhsSizeType>& rhs) const
164 {
165 return !(*this == rhs);
166 }
167
179 friend std::ostream& operator<<(std::ostream& os, RectangleT rectangle)
180 {
181 return os << "{ point: " << rectangle.m_point << ", size: " << rectangle.m_size << " }";
182 }
183
194 {
195 std::ostringstream ss;
196 ss << *this;
197 return ss.str();
198 }
199
200private:
201 PointT<PointType> m_point;
202 SizeT<SizeType> m_size;
203
204 friend detail::BackendAccessor<RectangleT<PointType, SizeType>>;
205
207 template <typename T = PointType, typename U = SizeType,
208 typename std::enable_if<has_c_type_of<RectangleT<T, U>>::value, bool>::type = false>
209 constexpr explicit operator peak::common::detail::c_type_of_t<RectangleT<T, U>>() const // NOLINT
210 {
211 return { this->GetX(), this->GetY(), this->GetWidth(), this->GetHeight() };
212 }
213};
214
215} // namespace detail
216
232
247
263
264} // namespace common
265} // namespace peak
2D point template type.
Definition peak_common_point.hpp:187
A generic rectangle defined by a point and a size.
Definition peak_common_rectangle.hpp:37
PEAK_COMMON_NO_DISCARD constexpr SizeType GetWidth() const
Returns the width of the rectangle.
Definition peak_common_rectangle.hpp:104
constexpr bool operator==(const RectangleT< RhsPointType, RhsSizeType > &rhs) const
Equality operator.
Definition peak_common_rectangle.hpp:147
PEAK_COMMON_NO_DISCARD constexpr PointT< PointType > GetPosition() const
Returns the top-left corner of the rectangle as a Point.
Definition peak_common_rectangle.hpp:131
constexpr RectangleT(const PointT< PointType > &point, const SizeT< SizeType > &size)
Constructs a rectangle from a point and a size.
Definition peak_common_rectangle.hpp:59
PEAK_COMMON_NO_DISCARD constexpr PointType GetX() const
Returns the x-coordinate of the rectangle's top-left corner.
Definition peak_common_rectangle.hpp:84
constexpr RectangleT()=default
Default constructor for RectangleT.
PEAK_COMMON_NO_DISCARD constexpr SizeT< SizeType > GetSize() const
Returns the size of the rectangle.
Definition peak_common_rectangle.hpp:123
constexpr bool operator!=(const RectangleT< RhsPointType, RhsSizeType > &rhs) const
Inequality operator.
Definition peak_common_rectangle.hpp:163
PEAK_COMMON_NO_DISCARD constexpr PointType GetY() const
Returns the y-coordinate of the rectangle's top-left corner.
Definition peak_common_rectangle.hpp:94
constexpr RectangleT(PointType x, PointType y, SizeType width, SizeType height)
Constructs a rectangle from coordinates and dimensions.
Definition peak_common_rectangle.hpp:74
PEAK_COMMON_NO_DISCARD std::string ToString() const
Returns a string representation of the rectangle.
Definition peak_common_rectangle.hpp:193
PEAK_COMMON_NO_DISCARD constexpr SizeType GetHeight() const
Returns the height of the rectangle.
Definition peak_common_rectangle.hpp:115
friend std::ostream & operator<<(std::ostream &os, RectangleT rectangle)
Stream output operator for RectangleT.
Definition peak_common_rectangle.hpp:179
Represents a two-dimensional size with non-negative width and height.
Definition peak_common_size.hpp:37
detail::RectangleT< uint32_t, uint32_t > RectangleU
Rectangle with unsigned coordinates and unsigned dimensions.
Definition peak_common_rectangle.hpp:262
detail::RectangleT< int32_t, uint32_t > Rectangle
Rectangle with integer coordinates and unsigned dimensions.
Definition peak_common_rectangle.hpp:231
detail::RectangleT< float, float > RectangleF
Rectangle with floating-point coordinates and dimensions.
Definition peak_common_rectangle.hpp:246
Namespace for internal implementation details and low-level types.
Definition peak_common_math.hpp:19
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:17
#define PEAK_COMMON_NO_DISCARD
Definition peak_common_defines.h:89