291{
292 std::stringstream
gcode;
293
294 double x = min_x;
295 double y = min_y;
296 const double max_x = min_x + size_x;
297 const double max_y = min_y + size_y;
298
299 const double spacing = opt_args.line_width - opt_args.height * (1 -
M_PI / 4);
300
301
302 const int max_perimeters = std::min(
303
306
307 opt_args.num_perimeters = std::min(opt_args.num_perimeters, max_perimeters);
308
310
311
312 auto line_arg_height = opt_args.height;
313 auto line_arg_line_width = opt_args.line_width;
314 auto line_arg_speed = opt_args.speed;
315 std::string comment = "";
316
317 for (int i = 0; i < opt_args.num_perimeters; ++i) {
318 if (i != 0) {
319 x += spacing;
320 y += spacing;
322 }
323
324 y += size_y - i * spacing * 2;
325 comment = "Draw perimeter (up)";
326 gcode <<
draw_line(writer,
Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
327
328 x += size_x - i * spacing * 2;
329 comment = "Draw perimeter (right)";
330 gcode <<
draw_line(writer,
Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
331
332 y -= size_y - i * spacing * 2;
333 comment = "Draw perimeter (down)";
334 gcode <<
draw_line(writer,
Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
335
336 x -= size_x - i * spacing * 2;
337 comment = "Draw perimeter (left)";
338 gcode <<
draw_line(writer,
Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
339 }
340
341 if (!opt_args.is_filled) {
343 }
344
345
346 const double spacing_45 = spacing / std::sin(
to_radians(45));
347
348 const double bound_modifier = (spacing * (opt_args.num_perimeters - 1)) + (opt_args.line_width * (1 -
m_encroachment));
349 const double x_min_bound = min_x + bound_modifier;
350 const double x_max_bound = max_x - bound_modifier;
351 const double y_min_bound = min_y + bound_modifier;
352 const double y_max_bound = max_y - bound_modifier;
353 const int x_count = std::floor((x_max_bound - x_min_bound) / spacing_45);
354 const int y_count = std::floor((y_max_bound - y_min_bound) / spacing_45);
355
356 double x_remainder = std::fmod((x_max_bound - x_min_bound), spacing_45);
357 double y_remainder = std::fmod((y_max_bound - y_min_bound), spacing_45);
358
359 x = x_min_bound;
360 y = y_min_bound;
361
363
364 for (int i = 0; i < x_count + y_count + (x_remainder + y_remainder >= spacing_45 ? 1 : 0);
365 ++i) {
366 if (i < std::min(x_count, y_count)) {
367 if (i % 2 == 0) {
368 x += spacing_45;
369 y = y_min_bound;
371
372 y += x - x_min_bound;
373 x = x_min_bound;
374 comment = "Fill: Print up/left";
375 gcode <<
draw_line(writer,
Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
376 } else {
377 y += spacing_45;
378 x = x_min_bound;
380
381 x += y - y_min_bound;
382 y = y_min_bound;
383 comment = "Fill: Print down/right";
384 gcode <<
draw_line(writer,
Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
385 }
386 } else if (i < std::max(x_count, y_count)) {
387 if (x_count > y_count) {
388
389 if (i % 2 == 0) {
390 x += spacing_45;
391 y = y_min_bound;
393
394 x -= y_max_bound - y_min_bound;
395 y = y_max_bound;
396 comment = "Fill: Print up/left";
397 gcode <<
draw_line(writer,
Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
398 } else {
399 if (i == y_count) {
400 x += spacing_45 - y_remainder;
401 y_remainder = 0;
402 } else {
403 x += spacing_45;
404 }
405 y = y_max_bound;
407
408 x += y_max_bound - y_min_bound;
409 y = y_min_bound;
410 comment = "Fill: Print down/right";
411 gcode <<
draw_line(writer,
Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
412 }
413 } else {
414
415 if (i % 2 == 0) {
416 x = x_max_bound;
417 if (i == x_count) {
418 y += spacing_45 - x_remainder;
419 x_remainder = 0;
420 } else {
421 y += spacing_45;
422 }
424
425 x = x_min_bound;
426 y += x_max_bound - x_min_bound;
427 comment = "Fill: Print up/left";
428 gcode <<
draw_line(writer,
Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
429 } else {
430 x = x_min_bound;
431 y += spacing_45;
433
434 x = x_max_bound;
435 y -= x_max_bound - x_min_bound;
436 comment = "Fill: Print down/right";
437 gcode <<
draw_line(writer,
Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
438 }
439 }
440 } else {
441 if (i % 2 == 0) {
442 x = x_max_bound;
443 if (i == x_count) {
444 y += spacing_45 - x_remainder;
445 } else {
446 y += spacing_45;
447 }
449
450 x -= y_max_bound - y;
451 y = y_max_bound;
452 comment = "Fill: Print up/left";
453 gcode <<
draw_line(writer,
Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
454 } else {
455 if (i == y_count) {
456 x += spacing_45 - y_remainder;
457 } else {
458 x += spacing_45;
459 }
460 y = y_max_bound;
462
463 y -= x_max_bound - x;
464 x = x_max_bound;
465 comment = "Fill: Print down/right";
466 gcode <<
draw_line(writer,
Vec2d(x, y), line_arg_line_width, line_arg_height, line_arg_speed, comment);
467 }
468 }
469 }
470
472}
#define M_PI
Definition ExtrusionSimulator.cpp:31
const double m_encroachment
Definition calib.hpp:249
double to_radians(double degrees) const
Definition calib.hpp:243
std::string move_to(Vec2d pt, GCodeWriter &writer, std::string comment=std::string(), double z=0, double layer_height=-1)
Definition calib.cpp:54
std::string draw_line(GCodeWriter &writer, Vec2d to_pt, double line_width, double layer_height, double speed, const std::string &comment=std::string())
Definition calib.cpp:269
@ gcode
Definition Time.hpp:14
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67