IDS peak genericC++ v1.12.0
Loading...
Searching...
No Matches
peak_common_rectangle.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
16
17#include <cstdint>
18#include <sstream>
19
20namespace peak
21{
22namespace common
23{
24
25namespace detail
26{
39template <typename PointType, typename SizeType>
41{
42
43public:
44 static_assert(std::is_arithmetic<PointType>::value, "Template argument of Rect must be arithmetic.");
45
53 constexpr RectangleT() = default;
54
63 constexpr RectangleT(const PointT<PointType>& point, const SizeT<SizeType>& size)
64 : m_point(point)
65 , m_size(size)
66 {}
67
78 constexpr RectangleT(PointType x, PointType y, SizeType width, SizeType height)
79 : RectangleT({ x, y }, { width, height })
80 {}
81
88 PEAK_COMMON_NO_DISCARD constexpr PointType GetX() const
89 {
90 return m_point.GetX();
91 }
92
98 PEAK_COMMON_NO_DISCARD constexpr PointType GetY() const
99 {
100 return m_point.GetY();
101 }
102
108 PEAK_COMMON_NO_DISCARD constexpr SizeType GetWidth() const
109 {
110 return m_size.GetWidth();
111 }
112
119 PEAK_COMMON_NO_DISCARD constexpr SizeType GetHeight() const
120 {
121 return m_size.GetHeight();
122 }
123
128 {
129 return m_size;
130 }
131
136 {
137 return m_point;
138 }
139
150 template <typename RhsPointType, typename RhsSizeType>
151 constexpr bool operator==(const RectangleT<RhsPointType, RhsSizeType>& rhs) const
152 {
153 return GetPosition() == rhs.GetPosition() && GetSize() == rhs.GetSize();
154 }
155
166 template <typename RhsPointType, typename RhsSizeType>
167 constexpr bool operator!=(const RectangleT<RhsPointType, RhsSizeType>& rhs) const
168 {
169 return !(*this == rhs);
170 }
171
183 friend std::ostream& operator<<(std::ostream& os, RectangleT rectangle)
184 {
185 return os << "{ point: " << rectangle.m_point << ", size: " << rectangle.m_size << " }";
186 }
187
198 {
199 std::ostringstream ss;
200 ss << *this;
201 return ss.str();
202 }
203
204private:
205 PointT<PointType> m_point;
206 SizeT<SizeType> m_size;
207
208 friend detail::BackendAccessor<RectangleT<PointType, SizeType>>;
209
211 template <typename T = PointType, typename U = SizeType,
212 typename std::enable_if<has_c_type_of<RectangleT<T, U>>::value, bool>::type = false>
213 constexpr explicit operator peak::common::detail::c_type_of_t<RectangleT<T, U>>() const // NOLINT
214 {
215 return { this->GetX(), this->GetY(), this->GetWidth(), this->GetHeight() };
216 }
217};
218
219} // namespace detail
220
236
251
252} // namespace common
253} // 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:41
PEAK_COMMON_NO_DISCARD constexpr SizeType GetWidth() const
Returns the width of the rectangle.
Definition peak_common_rectangle.hpp:108
constexpr bool operator==(const RectangleT< RhsPointType, RhsSizeType > &rhs) const
Equality operator.
Definition peak_common_rectangle.hpp:151
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:135
constexpr RectangleT(const PointT< PointType > &point, const SizeT< SizeType > &size)
Constructs a rectangle from a point and a size.
Definition peak_common_rectangle.hpp:63
PEAK_COMMON_NO_DISCARD constexpr PointType GetX() const
Returns the x-coordinate of the rectangle's top-left corner.
Definition peak_common_rectangle.hpp:88
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:127
constexpr bool operator!=(const RectangleT< RhsPointType, RhsSizeType > &rhs) const
Inequality operator.
Definition peak_common_rectangle.hpp:167
PEAK_COMMON_NO_DISCARD constexpr PointType GetY() const
Returns the y-coordinate of the rectangle's top-left corner.
Definition peak_common_rectangle.hpp:98
constexpr RectangleT(PointType x, PointType y, SizeType width, SizeType height)
Constructs a rectangle from coordinates and dimensions.
Definition peak_common_rectangle.hpp:78
PEAK_COMMON_NO_DISCARD std::string ToString() const
Returns a string representation of the rectangle.
Definition peak_common_rectangle.hpp:197
PEAK_COMMON_NO_DISCARD constexpr SizeType GetHeight() const
Returns the height of the rectangle.
Definition peak_common_rectangle.hpp:119
friend std::ostream & operator<<(std::ostream &os, RectangleT rectangle)
Stream output operator for RectangleT.
Definition peak_common_rectangle.hpp:183
Represents a two-dimensional size with non-negative width and height.
Definition peak_common_size.hpp:42
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
Definition peak_common_defines.hpp:91
detail::RectangleT< int32_t, uint32_t > Rectangle
Rectangle with integer coordinates and unsigned dimensions.
Definition peak_common_rectangle.hpp:235
detail::RectangleT< float, float > RectangleF
Rectangle with floating-point coordinates and dimensions.
Definition peak_common_rectangle.hpp:250
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
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_dynamic_loader.h:33