IDS peak ICV v1.1.0
Loading...
Searching...
No Matches
peak_icv_polygon.hpp
Go to the documentation of this file.
1
11#pragma once
12
16#include <peak_icv_c/types/peak_icv_polygon.h>
17#include <vector>
18
19namespace peak
20{
21namespace icv
22{
23namespace detail
24{
34template <typename PointType>
35class Polygon
36 : private detail::IBackendAccessible<Polygon<PointType>>
37 , private detail::IBackendExchangeable<Polygon<PointType>>
38{
39public:
45 Polygon();
46
52 ~Polygon() override;
53
61 explicit Polygon(const std::vector<peak::common::detail::PointT<PointType>>& points);
62
68 Polygon(const Polygon& other);
69
75 Polygon(Polygon&& other) noexcept;
76
82 Polygon& operator=(const Polygon& other);
83
89 Polygon& operator=(Polygon&& other) noexcept;
90
98 PEAK_COMMON_NO_DISCARD std::vector<peak::common::detail::PointT<PointType>> GetPoints() const;
99
107 PEAK_COMMON_NO_DISCARD bool IsClosed() const;
108
109private:
110 friend peak::common::detail::BackendAccessor<Polygon>;
111
113
114 explicit Polygon(peak_icv_polygon_handle handle);
115 PEAK_COMMON_NO_DISCARD detail::handle_of_t<Polygon> GetHandle() const override;
116 PEAK_COMMON_NO_DISCARD detail::handle_of_t<Polygon>* GetHandleAddress() override;
117
118 peak_icv_polygon_handle m_handle{};
119};
120
121template <typename PointType>
123{
125 return PEAK_ICV_C_ABI_PREFIX peak_icv_Polygon_Create(&m_handle);
126 });
127}
128
129template <typename PointType>
131{
132 std::vector<PointTypeC> cPoints;
133 cPoints.reserve(points.size());
134 std::transform(points.begin(), points.end(), std::back_inserter(cPoints), [](const auto& cppPoint) {
135 return peak::common::detail::BackendAccessor<peak::common::detail::PointT<PointType>>::CreateCType(cppPoint);
136 });
138 return PEAK_ICV_C_ABI_PREFIX peak_icv_Polygon_CreateFromPoints(
139 &m_handle, cPoints.data(), cPoints.size(), point_enum_of_<PointTypeC>::value);
140 });
141}
142
143template <typename PointType>
144inline Polygon<PointType>::Polygon(peak_icv_polygon_handle polygonHandle)
145 : m_handle{ polygonHandle }
146{}
147
148template <typename PointType>
150{
151 if (m_handle != other.m_handle)
152 {
154 return PEAK_ICV_C_ABI_PREFIX peak_icv_Polygon_IncreaseUseCount(other.m_handle);
155 });
156 m_handle = other.m_handle;
157 }
158}
159
160template <typename PointType>
161inline Polygon<PointType>::Polygon(Polygon&& other) noexcept
162{
163 if (m_handle != other.m_handle)
164 {
165 m_handle = other.m_handle;
166 other.m_handle = nullptr;
167 }
168}
169
170template <typename PointType>
172{
173 static_cast<void>(PEAK_ICV_C_ABI_PREFIX peak_icv_Polygon_Destroy(m_handle));
174}
175
176template <typename PointType>
178{
179 if (m_handle != other.m_handle)
180 {
181 if (m_handle != nullptr)
182 {
184 return PEAK_ICV_C_ABI_PREFIX peak_icv_Polygon_Destroy(m_handle);
185 });
186 }
187
189 return PEAK_ICV_C_ABI_PREFIX peak_icv_Polygon_IncreaseUseCount(other.m_handle);
190 });
191 m_handle = other.m_handle;
192 }
193 return *this;
194}
195
196template <typename PointType>
198{
199 if (m_handle != other.m_handle)
200 {
201 if (m_handle != nullptr)
202 {
204 return PEAK_ICV_C_ABI_PREFIX peak_icv_Polygon_Destroy(m_handle);
205 });
206 }
207
208 m_handle = other.m_handle;
209 other.m_handle = nullptr;
210 }
211 return *this;
212}
213
214template <typename PointType>
215inline std::vector<peak::common::detail::PointT<PointType>> Polygon<PointType>::GetPoints() const
216{
217 size_t numPoints = 0;
219 return PEAK_ICV_C_ABI_PREFIX peak_icv_Polygon_GetPoints_GetCount(m_handle, &numPoints);
220 });
221 if (numPoints == 0)
222 {
223 return {};
224 }
225
226 std::vector<PointTypeC> cPoints(numPoints);
228 return PEAK_ICV_C_ABI_PREFIX peak_icv_Polygon_GetPoints(m_handle, cPoints.data(), numPoints * sizeof(PointTypeC));
229 });
230
231 std::vector<peak::common::detail::PointT<PointType>> cppPoints{};
232 cppPoints.reserve(numPoints);
233 std::transform(cPoints.begin(), cPoints.end(), std::back_inserter(cppPoints), [](const auto& cPoint) {
234 return peak::common::detail::BackendAccessor<peak::common::detail::PointT<PointType>>::CreateInstance(cPoint);
235 });
236
237 return cppPoints;
238}
239
240template <typename PointType>
242{
243 bool isClosed = false;
245 return PEAK_ICV_C_ABI_PREFIX peak_icv_Polygon_IsClosed(m_handle, &isClosed);
246 });
247
248 return isClosed;
249}
250
251template <typename PointType>
253{
254 return m_handle;
255}
256
257template <typename PointType>
258inline detail::handle_of_t<Polygon<PointType>>* Polygon<PointType>::GetHandleAddress()
259{
260 return &m_handle;
261}
262
263} // namespace detail
264
271} /* namespace icv */
272} /* namespace peak */
A polygon is a two-dimensional geometric shape that is made up of a finite number of straight line se...
std::vector< peak::common::detail::PointT< PointType > > GetPoints() const
Provides the points from a polygon.
Polygon & operator=(const Polygon &other)
bool IsClosed() const
Checks if a polygon is closed. A closed polygon contains the same point as first and last point....
Polygon()
Creates an empty polygon.
typename c_type_of_< Type >::type c_type_of_t
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
peak::common::detail::c_type_of_t< Type > * handle_of_t