|
2 | 2 |
|
3 | 3 | #include "packingsolver/algorithms/common.hpp" |
4 | 4 |
|
| 5 | +#include "packingsolver/irregular/shape.hpp" |
| 6 | + |
5 | 7 | namespace packingsolver |
6 | 8 | { |
7 | 9 | namespace irregular |
8 | 10 | { |
9 | 11 |
|
10 | | -using LengthDbl = double; |
11 | | -using AreaDbl = double; |
12 | | -using ElementPos = int64_t; |
13 | | -using ItemShapePos = int64_t; |
14 | | -using ShapePos = int64_t; |
15 | | - |
16 | | -/** |
17 | | - * Structure for a point. |
18 | | - */ |
19 | | -struct Point |
20 | | -{ |
21 | | - /** x-coordinate. */ |
22 | | - LengthDbl x; |
23 | | - |
24 | | - /** y-coordiante. */ |
25 | | - LengthDbl y; |
26 | | - |
27 | | - /* |
28 | | - * Transformations |
29 | | - */ |
30 | | - |
31 | | - Point& shift( |
32 | | - LengthDbl x, |
33 | | - LengthDbl y); |
34 | | - |
35 | | - Point rotate(Angle angle) const; |
36 | | - |
37 | | - Point axial_symmetry_identity_line() const; |
38 | | - |
39 | | - Point axial_symmetry_y_axis() const; |
40 | | - |
41 | | - Point axial_symmetry_x_axis() const; |
42 | | - |
43 | | - /* |
44 | | - * Export |
45 | | - */ |
46 | | - |
47 | | - std::string to_string() const; |
48 | | - |
49 | | - /* |
50 | | - * Others |
51 | | - */ |
52 | | - |
53 | | - bool operator==(const Point& point) const { return x == point.x && y == point.y; } |
54 | | -}; |
55 | | - |
56 | | -Point operator+( |
57 | | - const Point& point_1, |
58 | | - const Point& point_2); |
59 | | - |
60 | | -Point operator-( |
61 | | - const Point& point_1, |
62 | | - const Point& point_2); |
63 | | - |
64 | | -LengthDbl norm( |
65 | | - const Point& vector); |
66 | | - |
67 | | -LengthDbl distance( |
68 | | - const Point& point_1, |
69 | | - const Point& point_2); |
70 | | - |
71 | | -LengthDbl dot_product( |
72 | | - const Point& vector_1, |
73 | | - const Point& vector_2); |
74 | | - |
75 | | -LengthDbl cross_product( |
76 | | - const Point& vector_1, |
77 | | - const Point& vector_2); |
78 | | - |
79 | | -Angle angle_radian( |
80 | | - const Point& vector); |
81 | | - |
82 | | -/** |
83 | | - * Return the angle between two vectors. |
84 | | - * |
85 | | - * The angle is measured anticlockwise and always belongs to [0, 2 * pi[. |
86 | | - */ |
87 | | -Angle angle_radian( |
88 | | - const Point& vector_1, |
89 | | - const Point& vector_2); |
90 | | - |
91 | | -enum class ShapeElementType |
92 | | -{ |
93 | | - LineSegment, |
94 | | - CircularArc, |
95 | | -}; |
96 | | - |
97 | | -std::string element2str(ShapeElementType type); |
98 | | -ShapeElementType str2element(const std::string& str); |
99 | | - |
100 | | -char element2char(ShapeElementType type); |
101 | | - |
102 | | -/** |
103 | | - * Structure for the elementary elements composing a shape. |
104 | | - */ |
105 | | -struct ShapeElement |
106 | | -{ |
107 | | - /** Type of element. */ |
108 | | - ShapeElementType type; |
109 | | - |
110 | | - /** Start point of the element. */ |
111 | | - Point start; |
112 | | - |
113 | | - /** End point of the element. */ |
114 | | - Point end; |
115 | | - |
116 | | - /** If the element is a CircularArc, center of the circle. */ |
117 | | - Point center = {0, 0}; |
118 | | - |
119 | | - /** If the element is a CircularArc, direction of the rotation. */ |
120 | | - bool anticlockwise = true; |
121 | | - |
122 | | - /** Length of the element. */ |
123 | | - LengthDbl length() const; |
124 | | - |
125 | | - ShapeElement rotate(Angle angle) const; |
126 | | - |
127 | | - ShapeElement axial_symmetry_identity_line() const; |
128 | | - |
129 | | - ShapeElement axial_symmetry_x_axis() const; |
130 | | - |
131 | | - ShapeElement axial_symmetry_y_axis() const; |
132 | | - |
133 | | - std::string to_string() const; |
134 | | -}; |
135 | | - |
136 | | -enum class ShapeType |
137 | | -{ |
138 | | - Circle, |
139 | | - Square, |
140 | | - Rectangle, |
141 | | - Polygon, |
142 | | - MultiPolygon, |
143 | | - PolygonWithHoles, |
144 | | - MultiPolygonWithHoles, |
145 | | - GeneralShape, |
146 | | -}; |
147 | | - |
148 | | -std::string shape2str(ShapeType type); |
149 | | - |
150 | | -/** |
151 | | - * Structure for a shape. |
152 | | - * |
153 | | - * A shape is connected and provided in anticlockwise direction. |
154 | | - */ |
155 | | -struct Shape |
156 | | -{ |
157 | | - /** |
158 | | - * List of elements. |
159 | | - * |
160 | | - * The end point of an element must be the start point of the next element. |
161 | | - */ |
162 | | - std::vector<ShapeElement> elements; |
163 | | - |
164 | | - /** Return true iff the shape is a circle. */ |
165 | | - bool is_circle() const; |
166 | | - |
167 | | - /** Return true iff the shape is a square. */ |
168 | | - bool is_square() const; |
169 | | - |
170 | | - /** Return true iff the shape is a rectangle. */ |
171 | | - bool is_rectangle() const; |
172 | | - |
173 | | - /** Return true iff the shape is a polygon. */ |
174 | | - bool is_polygon() const; |
175 | | - |
176 | | - /** Compute the area of the shape. */ |
177 | | - AreaDbl compute_area() const; |
178 | | - |
179 | | - /** Compute the smallest and greatest x and y of the shape. */ |
180 | | - std::pair<Point, Point> compute_min_max( |
181 | | - Angle angle = 0.0, |
182 | | - bool mirror = false) const; |
183 | | - |
184 | | - /** Compute the width and length of the shape. */ |
185 | | - std::pair<LengthDbl, LengthDbl> compute_width_and_length( |
186 | | - Angle angle = 0.0, |
187 | | - bool mirror = false) const; |
188 | | - |
189 | | - /* Check if the shape is connected and in anticlockwise direction. */ |
190 | | - bool check() const; |
191 | | - |
192 | | - Shape& shift( |
193 | | - LengthDbl x, |
194 | | - LengthDbl y); |
195 | | - |
196 | | - Shape rotate(Angle angle) const; |
197 | | - |
198 | | - Shape axial_symmetry_identity_line() const; |
199 | | - |
200 | | - Shape axial_symmetry_y_axis() const; |
201 | | - |
202 | | - Shape axial_symmetry_x_axis() const; |
203 | | - |
204 | | - Shape reverse() const; |
205 | | - |
206 | | - std::string to_string(Counter indentation) const; |
207 | | - |
208 | | - std::string to_svg(double factor) const; |
209 | | - |
210 | | - void write_svg( |
211 | | - const std::string& file_path) const; |
212 | | -}; |
213 | | - |
214 | | -Shape build_polygon_shape(const std::vector<Point>& points); |
215 | | - |
216 | | -double compute_svg_factor(double width); |
217 | | - |
218 | | -std::string to_svg( |
219 | | - const Shape& shape, |
220 | | - const std::vector<Shape>& holes, |
221 | | - double factor, |
222 | | - const std::string& fill_color = "blue"); |
223 | | - |
224 | | -void write_svg( |
225 | | - const Shape& shape, |
226 | | - const std::vector<Shape>& holes, |
227 | | - const std::string& file_path); |
228 | | - |
229 | 12 | struct ItemShape |
230 | 13 | { |
231 | 14 | /** Main shape. */ |
|
0 commit comments