test_clipper.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <catch2/catch.hpp>
  2. #include "test_data.hpp"
  3. #include "clipper/clipper_z.hpp"
  4. using namespace Slic3r;
  5. // Test case for an issue with duplicity vertices (same XY coordinates but differ in Z coordinates) in Clipper 6.2.9,
  6. // (related to https://sourceforge.net/p/polyclipping/bugs/160/) that was fixed in Clipper 6.4.2.
  7. SCENARIO("Clipper Z", "[ClipperZ]")
  8. {
  9. ClipperLib_Z::Path subject;
  10. subject.emplace_back(-2000, -1000, 10);
  11. subject.emplace_back(-2000, 1000, 10);
  12. subject.emplace_back( 2000, 1000, 10);
  13. subject.emplace_back( 2000, -1000, 10);
  14. ClipperLib_Z::Path clip;
  15. clip.emplace_back(-1000, -2000, -5);
  16. clip.emplace_back(-1000, 2000, -5);
  17. clip.emplace_back( 1000, 2000, -5);
  18. clip.emplace_back( 1000, -2000, -5);
  19. ClipperLib_Z::Clipper clipper;
  20. clipper.ZFillFunction([](const ClipperLib_Z::IntPoint &e1bot, const ClipperLib_Z::IntPoint &e1top, const ClipperLib_Z::IntPoint &e2bot,
  21. const ClipperLib_Z::IntPoint &e2top, ClipperLib_Z::IntPoint &pt) {
  22. pt.z() = 1;
  23. });
  24. clipper.AddPath(subject, ClipperLib_Z::ptSubject, false);
  25. clipper.AddPath(clip, ClipperLib_Z::ptClip, true);
  26. ClipperLib_Z::PolyTree polytree;
  27. ClipperLib_Z::Paths paths;
  28. clipper.Execute(ClipperLib_Z::ctIntersection, polytree, ClipperLib_Z::pftNonZero, ClipperLib_Z::pftNonZero);
  29. ClipperLib_Z::PolyTreeToPaths(polytree, paths);
  30. REQUIRE(paths.size() == 1);
  31. REQUIRE(paths.front().size() == 2);
  32. for (const ClipperLib_Z::IntPoint &pt : paths.front())
  33. REQUIRE(pt.z() == 1);
  34. }