test_gaps.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <catch2/catch.hpp>
  2. #include "libslic3r/GCodeReader.hpp"
  3. #include "libslic3r/Geometry/ConvexHull.hpp"
  4. #include "libslic3r/Layer.hpp"
  5. #include "test_data.hpp" // get access to init_print, etc
  6. using namespace Slic3r::Test;
  7. using namespace Slic3r;
  8. SCENARIO("Gaps", "[Gaps]") {
  9. GIVEN("Two hollow squares") {
  10. auto config = Slic3r::DynamicPrintConfig::full_print_config_with({
  11. { "skirts", 0 },
  12. { "perimeter_speed", 66 },
  13. { "external_perimeter_speed", 66 },
  14. { "small_perimeter_speed", 66 },
  15. { "gap_fill_speed", 99 },
  16. { "perimeters", 1 },
  17. // to prevent speeds from being altered
  18. { "cooling", 0 },
  19. // to prevent speeds from being altered
  20. { "first_layer_speed", "100%" },
  21. { "perimeter_extrusion_width", 0.35 },
  22. { "first_layer_extrusion_width", 0.35 }
  23. });
  24. GCodeReader parser;
  25. const double perimeter_speed = config.opt_float("perimeter_speed") * 60;
  26. const double gap_fill_speed = config.opt_float("gap_fill_speed") * 60;
  27. std::string last; // perimeter or gap
  28. Points perimeter_points;
  29. int gap_fills_outside_last_perimeters = 0;
  30. parser.parse_buffer(
  31. Slic3r::Test::slice({ Slic3r::Test::TestMesh::two_hollow_squares }, config),
  32. [&perimeter_points, &gap_fills_outside_last_perimeters, &last, perimeter_speed, gap_fill_speed]
  33. (Slic3r::GCodeReader &self, const Slic3r::GCodeReader::GCodeLine &line)
  34. {
  35. if (line.extruding(self) && line.dist_XY(self) > 0) {
  36. double f = line.new_F(self);
  37. Point point = line.new_XY_scaled(self);
  38. if (is_approx(f, perimeter_speed)) {
  39. if (last == "gap")
  40. perimeter_points.clear();
  41. perimeter_points.emplace_back(point);
  42. last = "perimeter";
  43. } else if (is_approx(f, gap_fill_speed)) {
  44. Polygon convex_hull = Geometry::convex_hull(perimeter_points);
  45. if (! convex_hull.contains(point))
  46. ++ gap_fills_outside_last_perimeters;
  47. last = "gap";
  48. }
  49. }
  50. });
  51. THEN("gap fills are printed before leaving islands") {
  52. REQUIRE(gap_fills_outside_last_perimeters == 0);
  53. }
  54. }
  55. }