-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtransformed_shape.cpp
95 lines (89 loc) · 3.33 KB
/
transformed_shape.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "transformed_shape.h"
namespace nesting {
TransformedShape::TransformedShape(const geo::Polygon_with_holes_2* _base,
const geo::FT& _x,
const geo::FT& _y,
const uint32_t& _rotation,
const uint32_t& _allowed_rotations,
const bool _simplified,
const size_t _item_idx)
: base(_base),
translate_ft_x(_x),
translate_ft_y(_y),
rotation(_rotation),
allowed_rotations(_allowed_rotations),
simplified(_simplified),
item_idx(_item_idx) {
this->translate_double_x = CGAL::to_double(translate_ft_x);
this->translate_double_y = CGAL::to_double(translate_ft_y);
set_reduced_rotations();
update();
}
TransformedShape::TransformedShape(const Polygon_with_holes_2* _base,
const double& _x,
const double& _y,
const uint32_t& _rotation,
const uint32_t& _allowed_rotations,
const bool _simplified,
const size_t _item_idx)
: base(_base),
translate_double_x(_x),
translate_double_y(_y),
rotation(_rotation),
allowed_rotations(_allowed_rotations),
simplified(_simplified),
item_idx(_item_idx) {
this->translate_ft_x = translate_double_x;
this->translate_ft_y = translate_double_y;
set_reduced_rotations();
update();
}
TransformedShape::TransformedShape(const TransformedShape& other)
: base(other.base),
translate_double_x(other.translate_double_x),
translate_double_y(other.translate_double_y),
rotation(other.rotation),
allowed_rotations(other.allowed_rotations),
simplified(other.simplified),
item_idx(other.item_idx),
translate_ft_x(other.translate_ft_x),
translate_ft_y(other.translate_ft_y),
transformed(other.transformed),
reduced_rotations(other.reduced_rotations) {}
void TransformedShape::update() {
auto rotate = geo::get_rotate(this->rotation, this->allowed_rotations);
auto translate = get_translate();
if (rotate) {
this->transformed =
geo::transform_polygon_with_holes(translate * (*rotate), *base);
} else {
this->transformed = geo::transform_polygon_with_holes(translate, *base);
}
}
void TransformedShape::set_reduced_rotations() {
reduced_rotations.push_back(0);
for (uint32_t i = 1; i < allowed_rotations; i++) {
auto rotate = geo::get_rotate(i, allowed_rotations);
if (rotate) {
auto rotated = geo::transform_polygon_with_holes(*rotate, *base);
bool flag = true;
for (auto& j : reduced_rotations) {
auto rotate_j = geo::get_rotate(j, allowed_rotations);
Polygon_with_holes_2 existed;
if (rotate_j) {
existed = geo::transform_polygon_with_holes(*rotate_j, *base);
} else {
existed = *base;
}
if (geo::is_translated(existed, rotated)) {
flag = false;
break;
}
}
if (flag) {
reduced_rotations.push_back(i);
}
}
}
}
} // namespace nesting