test_point.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Ported from xs/t/03_point.t
  3. * - it used to check ccw() but it does not exist anymore
  4. * and cross product uses doubles
  5. */
  6. #include <catch2/catch.hpp>
  7. #include <libslic3r/Point.hpp>
  8. #include "test_utils.hpp"
  9. using namespace Slic3r;
  10. TEST_CASE("Nearest point", "[Point]") {
  11. const Point point{10, 15};
  12. const Point point2{30, 15};
  13. const Point nearest{nearest_point({point2, Point{100, 200}}, point).first};
  14. CHECK(nearest == point2);
  15. }
  16. TEST_CASE("Distance to line", "[Point]") {
  17. const Line line{{0, 0}, {100, 0}};
  18. CHECK(line.distance_to(Point{0, 0}) == Approx(0));
  19. CHECK(line.distance_to(Point{100, 0}) == Approx(0));
  20. CHECK(line.distance_to(Point{50, 0}) == Approx(0));
  21. CHECK(line.distance_to(Point{150, 0}) == Approx(50));
  22. CHECK(line.distance_to(Point{0, 50}) == Approx(50));
  23. CHECK(line.distance_to(Point{50, 50}) == Approx(50));
  24. CHECK(line.perp_distance_to(Point{50, 50}) == Approx(50));
  25. CHECK(line.perp_distance_to(Point{150, 50}) == Approx(50));
  26. }
  27. TEST_CASE("Distance to diagonal line", "[Point]") {
  28. const Line line{{50, 50}, {125, -25}};
  29. CHECK(std::abs(line.distance_to(Point{100, 0})) == Approx(0));
  30. }
  31. TEST_CASE("Perp distance to line does not overflow", "[Point]") {
  32. const Line line{
  33. {18335846, 18335845},
  34. {18335846, 1664160},
  35. };
  36. CHECK(line.distance_to(Point{1664161, 18335848}) == Approx(16671685));
  37. }