IDS peak AFL v2.0.2
Loading...
Searching...
No Matches
peak_common_rectangle.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
17
18#include <cstdint>
19#include <sstream>
20
21namespace peak
22{
23namespace common
24{
25
26namespace detail
27{
40template <typename PointType, typename SizeType>
42{
43
44public:
45 static_assert(std::is_arithmetic<PointType>::value, "Template argument of Rect must be arithmetic.");
46
54 constexpr RectangleT() = default;
55
64 constexpr RectangleT(const PointT<PointType>& point, const SizeT<SizeType>& size)
65 : m_point(point)
66 , m_size(size)
67 {}
68
79 constexpr RectangleT(PointType x, PointType y, SizeType width, SizeType height)
80 : RectangleT({ x, y }, { width, height })
81 {}
82
89 PEAK_COMMON_NO_DISCARD constexpr PointType GetX() const
90 {
91 return m_point.GetX();
92 }
93
99 PEAK_COMMON_NO_DISCARD constexpr PointType GetY() const
100 {
101 return m_point.GetY();
102 }
103
109 PEAK_COMMON_NO_DISCARD constexpr SizeType GetWidth() const
110 {
111 return m_size.GetWidth();
112 }
113
120 PEAK_COMMON_NO_DISCARD constexpr SizeType GetHeight() const
121 {
122 return m_size.GetHeight();
123 }
124
128 PEAK_COMMON_NO_DISCARD constexpr SizeT<SizeType> GetSize() const
129 {
130 return m_size;
131 }
132
136 PEAK_COMMON_NO_DISCARD constexpr PointT<PointType> GetPosition() const
137 {
138 return m_point;
139 }
140
151 template <typename RhsPointType, typename RhsSizeType>
152 constexpr bool operator==(const RectangleT<RhsPointType, RhsSizeType>& rhs) const
153 {
154 return GetPosition() == rhs.GetPosition() && GetSize() == rhs.GetSize();
155 }
156
167 template <typename RhsPointType, typename RhsSizeType>
168 constexpr bool operator!=(const RectangleT<RhsPointType, RhsSizeType>& rhs) const
169 {
170 return !(*this == rhs);
171 }
172
184 friend std::ostream& operator<<(std::ostream& os, RectangleT rectangle)
185 {
186 return os << "{ point: " << rectangle.m_point << ", size: " << rectangle.m_size << " }";
187 }
188
198 PEAK_COMMON_NO_DISCARD std::string ToString() const
199 {
200 std::ostringstream ss;
201 ss << *this;
202 return ss.str();
203 }
204
205private:
206 PointT<PointType> m_point;
207 SizeT<SizeType> m_size;
208
209 friend detail::BackendAccessor<RectangleT<PointType, SizeType>>;
210
212 template <typename T = PointType, typename U = SizeType,
213 typename std::enable_if<has_c_type_of<RectangleT<T, U>>::value, bool>::type = false>
214 constexpr explicit operator peak::common::detail::c_type_of_t<RectangleT<T, U>>() const // NOLINT
215 {
216 return { this->GetX(), this->GetY(), this->GetWidth(), this->GetHeight() };
217 }
218};
219
220} // namespace detail
221
237
252
268
269} // namespace common
270} // namespace peak
2D point template type.
Definition peak_common_point.hpp:192
A generic rectangle defined by a point and a size.
Definition peak_common_rectangle.hpp:42
constexpr SizeT< SizeType > GetSize() const
Returns the size of the rectangle.
Definition peak_common_rectangle.hpp:128
constexpr PointType GetX() const
Returns the x-coordinate of the rectangle's top-left corner.
Definition peak_common_rectangle.hpp:89
std::string ToString() const
Returns a string representation of the rectangle.
Definition peak_common_rectangle.hpp:198
constexpr RectangleT(PointType x, PointType y, SizeType width, SizeType height)
Constructs a rectangle from coordinates and dimensions.
Definition peak_common_rectangle.hpp:79
constexpr SizeType GetWidth() const
Returns the width of the rectangle.
Definition peak_common_rectangle.hpp:109
constexpr SizeType GetHeight() const
Returns the height of the rectangle.
Definition peak_common_rectangle.hpp:120
constexpr RectangleT(const PointT< PointType > &point, const SizeT< SizeType > &size)
Constructs a rectangle from a point and a size.
Definition peak_common_rectangle.hpp:64
constexpr RectangleT()=default
Default constructor for RectangleT.
constexpr PointType GetY() const
Returns the y-coordinate of the rectangle's top-left corner.
Definition peak_common_rectangle.hpp:99
constexpr bool operator==(const RectangleT< RhsPointType, RhsSizeType > &rhs) const
Equality operator.
Definition peak_common_rectangle.hpp:152
friend std::ostream & operator<<(std::ostream &os, RectangleT rectangle)
Stream output operator for RectangleT.
Definition peak_common_rectangle.hpp:184
constexpr PointT< PointType > GetPosition() const
Returns the top-left corner of the rectangle as a Point.
Definition peak_common_rectangle.hpp:136
constexpr bool operator!=(const RectangleT< RhsPointType, RhsSizeType > &rhs) const
Inequality operator.
Definition peak_common_rectangle.hpp:168
Represents a two-dimensional size with non-negative width and height.
Definition peak_common_size.hpp:42
detail::RectangleT< uint32_t, uint32_t > RectangleU
Rectangle with unsigned coordinates and unsigned dimensions.
Definition peak_common_rectangle.hpp:267
detail::RectangleT< float, float > RectangleF
Rectangle with floating-point coordinates and dimensions.
Definition peak_common_rectangle.hpp:251
detail::RectangleT< int32_t, uint32_t > Rectangle
Rectangle with integer coordinates and unsigned dimensions.
Definition peak_common_rectangle.hpp:236
Namespace for internal implementation details and low-level types.
Definition peak_common_math.hpp:24
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:22