37 std::vector<std::pair<float, float>> _shape;
39 std::vector<std::pair<float, float>> _points;
45 std::array<float, 4> _transformation_matrix;
75 [[nodiscard]]
float circumradius()
const;
84 [[nodiscard]] std::pair<float, float>
85 project(std::pair<float, float>
const& vector)
const;
95 [[nodiscard]] std::vector<std::pair<float, float>>
const& shape()
const;
103 [[nodiscard]]
float shape_radius()
const;
111 [[nodiscard]] std::vector<std::pair<float, float>>
const& points()
const;
119 [[nodiscard]]
float points_radius()
const;
127 [[nodiscard]]
float x()
const;
135 void set_x(
float x)
final;
143 [[nodiscard]]
float y()
const;
151 void set_y(
float y)
final;
159 [[nodiscard]]
float angle()
const;
167 void set_angle(
float angle)
final;
175 [[nodiscard]]
float scale()
const;
183 void set_scale(
float scale);
191 [[nodiscard]] std::array<float, 4>
const& transformation_matrix()
const;
199 [[nodiscard]]
float x_offset()
const final;
207 void set_x_offset(
float x_offset);
215 [[nodiscard]]
float y_offset()
const final;
223 void set_y_offset(
float y_offset);
231 [[nodiscard]]
float angle_offset()
const final;
239 void set_angle_offset(
float angle_offset);
247 [[nodiscard]]
bool attach_x()
const final;
255 void set_attach_x(
bool attach_x);
263 [[nodiscard]]
bool attach_y()
const final;
271 void set_attach_y(
bool attach_y);
279 [[nodiscard]]
bool attach_angle()
const final;
287 void set_attach_angle(
bool attach_angle);
295 [[nodiscard]]
bool x_angle_lock()
const final;
303 void set_x_angle_lock(
bool x_angle_lock);
311 [[nodiscard]]
bool y_angle_lock()
const final;
319 void set_y_angle_lock(
bool y_angle_lock);
340 explicit polygon(std::vector<std::pair<float, float>>
const& shape =
341 {{0, 0}, {0, 0}, {0, 0}},
342 float x = 0,
float y = 0,
float angle = 0,
float scale = 1,
343 float x_offset = 0,
float y_offset = 0,
344 float angle_offset = 0,
bool attach_x =
true,
345 bool attach_y =
true,
bool attach_angle =
true,
346 bool x_angle_lock =
true,
bool y_angle_lock =
true);
356 [[nodiscard]]
bool inside(
float x,
float y)
const;
366 template <
typename T>
367 [[nodiscard]] std::enable_if_t<
368 std::is_same_v<T, bool> || std::is_same_v<T, float>, T>
369 overlap(
polygon const& other)
const {
374 std::vector<std::pair<float, float>>::const_iterator point1;
375 std::vector<std::pair<float, float>>::const_iterator point2;
376 std::pair<float, float> normal;
377 std::pair<float, float> projection1;
378 std::pair<float, float> projection2;
380 if (points_radius() + other.points_radius() <
382 return std::is_same_v<T, bool> ? false : 0;
388 std::is_same_v<T, bool> ? true : std::numeric_limits<float>::max();
390 for (i = 0; i != 2; ++i) {
391 for (point1 = polygon1->points().begin(),
392 point2 = polygon1->points().begin() + 1;
393 point1 != polygon1->points().end(); ++point1, ++point2) {
394 if (point2 == polygon1->points().end()) {
395 point2 = polygon1->points().begin();
399 point2->second - point1->second);
400 if constexpr (std::is_same_v<T, float>) {
403 projection1 = polygon1->project(normal);
404 projection2 = polygon2->project(normal);
406 if (projection2.second < projection1.first ||
407 projection1.second < projection2.first) {
408 return std::is_same_v<T, bool> ? false : 0;
411 if constexpr (std::is_same_v<T, float>) {
413 std::min(projection1.second, projection2.second) -
414 std::max(projection1.first, projection2.first),