test_seam_shells.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <catch2/catch.hpp>
  2. #include <filesystem>
  3. #include <fstream>
  4. #include "libslic3r/ClipperUtils.hpp"
  5. #include "libslic3r/GCode/SeamPainting.hpp"
  6. #include "test_data.hpp"
  7. #include "libslic3r/GCode/SeamShells.hpp"
  8. using namespace Slic3r;
  9. using namespace Slic3r::Seams;
  10. constexpr bool debug_files{false};
  11. struct ProjectionFixture
  12. {
  13. Polygon extrusion_path{
  14. Point{scaled(Vec2d{-1.0, -1.0})}, Point{scaled(Vec2d{1.0, -1.0})},
  15. Point{scaled(Vec2d{1.0, 1.0})}, Point{scaled(Vec2d{-1.0, 1.0})}};
  16. ExPolygon island_boundary;
  17. Seams::Geometry::Extrusions extrusions;
  18. double extrusion_width{0.2};
  19. ProjectionFixture() {
  20. extrusions.emplace_back(Polygon{extrusion_path}, extrusion_path.bounding_box(), extrusion_width, island_boundary);
  21. }
  22. };
  23. TEST_CASE_METHOD(ProjectionFixture, "Project to geometry matches", "[Seams][SeamShells]") {
  24. Polygon boundary_polygon{extrusion_path};
  25. // Add + 0.1 to check that boundary polygon has been picked.
  26. boundary_polygon.scale(1.0 + extrusion_width / 2.0 + 0.1);
  27. island_boundary.contour = boundary_polygon;
  28. Seams::Geometry::BoundedPolygons result{Seams::Geometry::project_to_geometry(extrusions, 5.0)};
  29. REQUIRE(result.size() == 1);
  30. REQUIRE(result[0].polygon.size() == 4);
  31. // Boundary polygon is picked.
  32. CHECK(result[0].polygon[0].x() == Approx(scaled(-(1.0 + extrusion_width / 2.0 + 0.1))));
  33. }
  34. TEST_CASE_METHOD(ProjectionFixture, "Project to geometry does not match", "[Seams][SeamShells]") {
  35. Polygon boundary_polygon{extrusion_path};
  36. // Island boundary is far from the extrusion.
  37. boundary_polygon.scale(5.0);
  38. island_boundary.contour = boundary_polygon;
  39. Seams::Geometry::BoundedPolygons result{Seams::Geometry::project_to_geometry(extrusions, 1.0)};
  40. REQUIRE(result.size() == 1);
  41. REQUIRE(result[0].polygon.size() == 4);
  42. const Polygon expanded{expand(extrusions.front().polygon, extrusion_width / 2.0).front()};
  43. // The extrusion is expanded and returned.
  44. CHECK(result[0].polygon == expanded);
  45. }