99
1010namespace Slic3r {
1111
12- // Helper to emit current polyline segment into output, rotated back to model frame.
13- // We reset multiple multiple times per row to avoid overlapping polylines
14- static inline void reset_polyline (
15- const float angle,
16- const Point &hex_center,
17- Polyline &polyline,
18- Polylines &all_polylines)
19- {
20- if (polyline.points .size () == 0 ) return ;
21- if (polyline.points .size () > 1 ) {
22- polyline.rotate (-angle, hex_center); // rotate back to model frame if any points were collected
23- all_polylines.emplace_back (std::move (polyline));
24- }
25- polyline.points .clear ();
26- }
27-
2812void FillRhodo::_fill_surface_single (
2913 const FillParams ¶ms,
30- unsigned int /* thickness_layers*/ ,
14+ unsigned int thickness_layers,
3115 const std::pair<float , Point> &direction,
3216 ExPolygon expolygon,
3317 Polylines &polylines_out)
3418{
35- const coord_t min_spacing = coord_t (scale_ (this ->spacing ));
36- const coord_t hex_side = coord_t (min_spacing / params.density );
37- const coord_t hex_width = coord_t (hex_side * sqrt (3 ));
38- const coord_t pattern_height = coord_t (hex_side * 3 / 2 ); // pattern height = hex_side * 1.5
39- const coord_t tile_height = coord_t (hex_side * 3 ); // tilable / periodic every other row
40- const Point hex_center = Point (hex_width / 2 , hex_side);
19+ const coord_t min_spacing = coord_t (scale_ (this ->spacing ));
20+ const coord_t min_spacing_half = coord_t (scale_ (this ->spacing )) / 2 ;
21+ const coord_t hex_side = coord_t (min_spacing / params.density );
22+ const coord_t hex_width = coord_t (hex_side * sqrt (3 ));
23+ const coord_t tile_height = coord_t (hex_side * 3 ) + min_spacing; // tilable / periodic every other row
24+ const coord_t pattern_height = tile_height / 2 ; // pattern height = hex_side * 1.5
25+ const Point hex_center = Point (hex_width / 2 , hex_side);
4126
4227 // Compute normalized z phase in [0, 4.5) relative to hex_side, using double for phase only.
4328 const double unscaled_z = this ->z ; // mm
@@ -96,7 +81,7 @@ void FillRhodo::_fill_surface_single(
9681 Polygon bb_polygon = bbox.polygon ();
9782 bb_polygon.rotate (angle, hex_center);
9883 bbox = bb_polygon.bounding_box ();
99- bbox.merge (align_to_grid (bbox.min , Point (hex_width, tile_height)));
84+ bbox.merge (align_to_grid (bbox.min , Point (hex_width + min_spacing , tile_height)));
10085 }
10186
10287 // Expand bbox to cover entire surface with a margin of two cells as in reference.
@@ -106,11 +91,11 @@ void FillRhodo::_fill_surface_single(
10691 const size_t num_cols = size_t (2 + (w + hex_width - 1 ) / std::max<coord_t >(hex_width, 1 ));
10792
10893 Polylines all_polylines;
109- all_polylines.reserve (num_rows * num_cols * 2 );
110- // Start one row above to guarantee coverage before clipping, similar to Python (i-1)
94+ all_polylines.reserve (1 );
95+ Polyline polyline;
96+ // Start one row above to guarantee coverage before
11197 const coord_t y_start = bbox.min (1 ) - pattern_height;
11298 for (size_t i = 0 ; i < num_rows; ++i) {
113- Polyline polyline;
11499 // Row y origin in aligned grid frame
115100 coord_t y_offset = y_start + phase_y_offset + coord_t (i) * pattern_height;
116101 if (permutation == 0 ) {
@@ -122,43 +107,39 @@ void FillRhodo::_fill_surface_single(
122107 // top-left tri right
123108 polyline.points .emplace_back (x_offset - hex_width / 2 + tri_half_w, y_offset - hex_side / 2 + coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
124109 // hex top left
125- polyline.points .emplace_back (x_offset, y_offset);
110+ polyline.points .emplace_back (x_offset + min_spacing_half , y_offset);
126111 // left tri top
127- polyline.points .emplace_back (x_offset, y_offset + coord_t (std::llround (double (hex_side) - double (tri_w) * sqrt (3 ) / 3.0 )));
112+ polyline.points .emplace_back (x_offset + min_spacing_half , y_offset + coord_t (std::llround (double (hex_side) - double (tri_w) * sqrt (3 ) / 3.0 )));
128113 // left tri left
129114 polyline.points .emplace_back (x_offset - tri_half_w, y_offset + hex_side + coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
130115 if (j + 1 == num_cols) break ;
131116 // left tri right
132117 polyline.points .emplace_back (x_offset + tri_half_w, y_offset + hex_side + coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
133118 // left tri top
134- polyline.points .emplace_back (x_offset, y_offset + coord_t (std::llround (double (hex_side) - double (tri_w) * sqrt (3 ) / 3.0 )));
135- reset_polyline (angle, hex_center, polyline, all_polylines);
119+ polyline.points .emplace_back (x_offset - min_spacing_half, y_offset + coord_t (std::llround (double (hex_side) - double (tri_w) * sqrt (3 ) / 3.0 )));
136120 // hex top left
137- polyline.points .emplace_back (x_offset, y_offset);
121+ polyline.points .emplace_back (x_offset - min_spacing_half , y_offset);
138122 // top tri left
139123 polyline.points .emplace_back (x_offset + hex_width / 2 - tri_half_w, y_offset - hex_side / 2 + coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
140- reset_polyline (angle, hex_center, polyline, all_polylines);
141124 }
142125 } else {
143126 for (size_t j = num_cols; j-- > 0 ; ) {
144127 coord_t x_offset = bbox.min (0 ) + phase_x_offset + coord_t (j) * hex_width - hex_width / 2 ;
145128 // hex top right
146- polyline.points .emplace_back (x_offset, y_offset);
129+ polyline.points .emplace_back (x_offset - min_spacing_half , y_offset);
147130 // right tri top
148- polyline.points .emplace_back (x_offset, y_offset + coord_t (std::llround (double (hex_side) - double (tri_w) * sqrt (3 ) / 3.0 )));
131+ polyline.points .emplace_back (x_offset - min_spacing_half , y_offset + coord_t (std::llround (double (hex_side) - double (tri_w) * sqrt (3 ) / 3.0 )));
149132 // right tri right
150133 polyline.points .emplace_back (x_offset + tri_half_w, y_offset + hex_side + coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
151134 if (j == 0 ) break ;
152135 // right tri left
153136 polyline.points .emplace_back (x_offset - tri_half_w, y_offset + hex_side + coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
154137 // right tri top
155- polyline.points .emplace_back (x_offset, y_offset + coord_t (std::llround (double (hex_side) - double (tri_w) * sqrt (3 ) / 3.0 )));
156- reset_polyline (angle, hex_center, polyline, all_polylines);
138+ polyline.points .emplace_back (x_offset + min_spacing_half, y_offset + coord_t (std::llround (double (hex_side) - double (tri_w) * sqrt (3 ) / 3.0 )));
157139 // hex top right
158- polyline.points .emplace_back (x_offset, y_offset);
140+ polyline.points .emplace_back (x_offset + min_spacing_half , y_offset);
159141 // top tri right
160142 polyline.points .emplace_back (x_offset - hex_width / 2 + tri_half_w, y_offset - hex_side / 2 + coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
161- reset_polyline (angle, hex_center, polyline, all_polylines);
162143 // top tri left
163144 polyline.points .emplace_back (x_offset - hex_width / 2 - tri_half_w, y_offset - hex_side / 2 + coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
164145 }
@@ -170,52 +151,49 @@ void FillRhodo::_fill_surface_single(
170151 // left tri right
171152 polyline.points .emplace_back (x_offset + tri_half_w, y_offset - coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
172153 // left tri bottom
173- polyline.points .emplace_back (x_offset, y_offset + coord_t (std::llround (double (tri_w) * sqrt (3 ) / 3.0 )));
154+ polyline.points .emplace_back (x_offset - min_spacing_half , y_offset + coord_t (std::llround (double (tri_w) * sqrt (3 ) / 3.0 )));
174155 // hex bottom left
175- polyline.points .emplace_back (x_offset, y_offset + hex_side);
156+ polyline.points .emplace_back (x_offset - min_spacing_half , y_offset + hex_side);
176157 // bottom tri left
177158 polyline.points .emplace_back (x_offset + hex_width / 2 - tri_half_w, y_offset + 3 * hex_side / 2 - coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
178159 if (j + 1 == num_cols) break ;
179160 // bottom tri right
180161 polyline.points .emplace_back (x_offset + hex_width / 2 + tri_half_w, y_offset + 3 * hex_side / 2 - coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
181162 // hex bottom right
182- polyline.points .emplace_back (x_offset + hex_width, y_offset + hex_side);
183- reset_polyline (angle, hex_center, polyline, all_polylines);
163+ polyline.points .emplace_back (x_offset + hex_width + min_spacing_half, y_offset + hex_side);
184164 // right tri bottom
185- polyline.points .emplace_back (x_offset + hex_width, y_offset + coord_t (std::llround (double (tri_w) * sqrt (3 ) / 3.0 )));
165+ polyline.points .emplace_back (x_offset + hex_width + min_spacing_half , y_offset + coord_t (std::llround (double (tri_w) * sqrt (3 ) / 3.0 )));
186166 // right tri left
187167 polyline.points .emplace_back (x_offset + hex_width - tri_half_w, y_offset - coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
188- reset_polyline (angle, hex_center, polyline, all_polylines);
189168 }
190169 } else {
191170 for (size_t j = num_cols; j-- > 0 ; ) {
192171 coord_t x_offset = bbox.min (0 ) + phase_x_offset + coord_t (j) * hex_width;
193172 // right tri left
194173 polyline.points .emplace_back (x_offset - tri_half_w, y_offset - coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
195174 // right tri bottom
196- polyline.points .emplace_back (x_offset, y_offset + coord_t (std::llround (double (tri_w) * sqrt (3 ) / 3.0 )));
175+ polyline.points .emplace_back (x_offset + min_spacing_half , y_offset + coord_t (std::llround (double (tri_w) * sqrt (3 ) / 3.0 )));
197176 // hex bottom right
198- polyline.points .emplace_back (x_offset, y_offset + hex_side);
177+ polyline.points .emplace_back (x_offset + min_spacing_half , y_offset + hex_side);
199178 // bottom tri right
200179 polyline.points .emplace_back (x_offset - hex_width / 2 + tri_half_w, y_offset + 3 * hex_side / 2 - coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
201180 if (j == 0 ) break ;
202181 // bottom tri left
203182 polyline.points .emplace_back (x_offset - hex_width / 2 - tri_half_w, y_offset + 3 * hex_side / 2 - coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
204183 // hex bottom left
205- polyline.points .emplace_back (x_offset - hex_width, y_offset + hex_side);
206- reset_polyline (angle, hex_center, polyline, all_polylines);
184+ polyline.points .emplace_back (x_offset - hex_width - min_spacing_half, y_offset + hex_side);
207185 // left tri bottom
208- polyline.points .emplace_back (x_offset - hex_width, y_offset + coord_t (std::llround (double (tri_w) * sqrt (3 ) / 3.0 )));
186+ polyline.points .emplace_back (x_offset - hex_width - min_spacing_half , y_offset + coord_t (std::llround (double (tri_w) * sqrt (3 ) / 3.0 )));
209187 // left tri right
210188 polyline.points .emplace_back (x_offset - hex_width + tri_half_w, y_offset - coord_t (std::llround (double (tri_half_w) / sqrt (3 ))));
211- reset_polyline (angle, hex_center, polyline, all_polylines);
212189 }
213190 }
214191 }
215-
216- reset_polyline (angle, hex_center, polyline, all_polylines);
192+
217193 }
218194
195+ all_polylines.emplace_back (std::move (polyline));
196+
219197 // Clip to the surface polygon
220198 all_polylines = intersection_pl (std::move (all_polylines), expolygon);
221199 if (params.dont_connect () || all_polylines.size () <= 1 )
0 commit comments