test_line.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Ported from xs/t/10_line.t
  3. */
  4. #include <catch2/catch.hpp>
  5. #include <libslic3r/Line.hpp>
  6. #include "test_utils.hpp"
  7. using namespace Slic3r;
  8. TEST_CASE("Line can be translated", "[Line]") {
  9. Line line{{100, 100}, {200, 100}};
  10. line.translate(10, -5);
  11. CHECK(Points{line.a, line.b} == Points{{110, 95}, {210, 95}});
  12. }
  13. TEST_CASE("Check if lines are parallel", "[Line]") {
  14. CHECK(Line{{0, 0}, {100, 0}}.parallel_to(Line{{200, 200}, {0, 200}}));
  15. }
  16. TEST_CASE("Parallel lines under angles", "[Line]") {
  17. auto base_angle = GENERATE(0, M_PI/3, M_PI/2, M_PI);
  18. Line line{{0, 0}, {100, 0}};
  19. line.rotate(base_angle, {0, 0});
  20. Line clone{line};
  21. INFO("Line is parallel to self");
  22. CHECK(line.parallel_to(clone));
  23. clone.reverse();
  24. INFO("Line is parallel to self + PI");
  25. CHECK(line.parallel_to(clone));
  26. INFO("Line is parallel to its direction");
  27. CHECK(line.parallel_to(line.direction()));
  28. INFO("Line is parallel to its direction + PI");
  29. line.parallel_to(line.direction() + M_PI);
  30. INFO("line is parallel to its direction - PI")
  31. line.parallel_to(line.direction() - M_PI);
  32. SECTION("Line is parallel within epsilon") {
  33. clone = line;
  34. clone.rotate(EPSILON/2, {0, 0});
  35. CHECK(line.parallel_to(clone));
  36. clone = line;
  37. clone.rotate(-EPSILON/2, {0, 0});
  38. CHECK(line.parallel_to(clone));
  39. }
  40. }
  41. TEST_CASE("Intersection infinite", "[Line]") {
  42. const Line a{{100, 0}, {200, 0}};
  43. const Line b{{300, 300}, {300, 100}};
  44. Point r;
  45. a.intersection_infinite(b, &r);
  46. CHECK(r == Point{300, 0});
  47. }