test_polygon.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <catch2/catch.hpp>
  2. #include "libslic3r/Point.hpp"
  3. #include "libslic3r/Polygon.hpp"
  4. using namespace Slic3r;
  5. // This test currently only covers remove_collinear_points.
  6. // All remaining tests are to be ported from xs/t/06_polygon.t
  7. Slic3r::Points collinear_circle({
  8. Slic3r::Point::new_scale(0, 0), // 3 collinear points at beginning
  9. Slic3r::Point::new_scale(10, 0),
  10. Slic3r::Point::new_scale(20, 0),
  11. Slic3r::Point::new_scale(30, 10),
  12. Slic3r::Point::new_scale(40, 20), // 2 collinear points
  13. Slic3r::Point::new_scale(40, 30),
  14. Slic3r::Point::new_scale(30, 40), // 3 collinear points
  15. Slic3r::Point::new_scale(20, 40),
  16. Slic3r::Point::new_scale(10, 40),
  17. Slic3r::Point::new_scale(-10, 20),
  18. Slic3r::Point::new_scale(-20, 10),
  19. Slic3r::Point::new_scale(-20, 0), // 3 collinear points at end
  20. Slic3r::Point::new_scale(-10, 0),
  21. Slic3r::Point::new_scale(-5, 0)
  22. });
  23. SCENARIO("Remove collinear points from Polygon", "[Polygon]") {
  24. GIVEN("Polygon with collinear points"){
  25. Slic3r::Polygon p(collinear_circle);
  26. WHEN("collinear points are removed") {
  27. remove_collinear(p);
  28. THEN("Leading collinear points are removed") {
  29. REQUIRE(p.points.front() == Slic3r::Point::new_scale(20, 0));
  30. }
  31. THEN("Trailing collinear points are removed") {
  32. REQUIRE(p.points.back() == Slic3r::Point::new_scale(-20, 0));
  33. }
  34. THEN("Number of remaining points is correct") {
  35. REQUIRE(p.points.size() == 7);
  36. }
  37. }
  38. }
  39. }