infinite_line.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Boost.Geometry
  2. // Unit Test
  3. // Copyright (c) 2019 Barend Gehrels, Amsterdam, the Netherlands.
  4. // This file was modified by Oracle on 2019.
  5. // Modifications copyright (c) 2019, Oracle and/or its affiliates.
  6. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #include <geometry_test_common.hpp>
  11. #include <boost/geometry/algorithms/detail/make/make.hpp>
  12. #include <boost/geometry/geometries/infinite_line.hpp>
  13. #include <boost/geometry/geometries/point.hpp>
  14. #include <boost/geometry/util/math.hpp>
  15. namespace
  16. {
  17. // Boost.Test does not support BOOST_CHECK_CLOSE for integral types
  18. template <typename T>
  19. bool is_small(T const& value)
  20. {
  21. static long double const epsilon = 1.0e-5;
  22. return bg::math::abs(value) < epsilon;
  23. }
  24. }
  25. template <typename T, typename C>
  26. void verify_point_on_line(bg::model::infinite_line<T> const& line,
  27. C const& x, C const& y)
  28. {
  29. BOOST_CHECK_MESSAGE(is_small(line.a * x + line.b * y + line.c),
  30. "Point is not located on the line");
  31. }
  32. template <typename T>
  33. void test_make()
  34. {
  35. typedef bg::model::infinite_line<T> line_type;
  36. // Horizontal through origin
  37. line_type line = bg::detail::make::make_infinite_line<T>(0, 0, 10, 0);
  38. verify_point_on_line(line, 0, 0);
  39. verify_point_on_line(line, 10, 0);
  40. // Horizontal line above origin
  41. line = bg::detail::make::make_infinite_line<T>(0, 5, 10, 5);
  42. verify_point_on_line(line, 0, 5);
  43. verify_point_on_line(line, 10, 5);
  44. // Vertical through origin
  45. line = bg::detail::make::make_infinite_line<T>(0, 0, 0, 10);
  46. verify_point_on_line(line, 0, 0);
  47. verify_point_on_line(line, 0, 10);
  48. // Vertical line left from origin
  49. line = bg::detail::make::make_infinite_line<T>(5, 0, 5, 10);
  50. verify_point_on_line(line, 5, 0);
  51. verify_point_on_line(line, 5, 10);
  52. // Diagonal through origin
  53. line = bg::detail::make::make_infinite_line<T>(0, 0, 8, 10);
  54. verify_point_on_line(line, 0, 0);
  55. verify_point_on_line(line, 8, 10);
  56. // Diagonal not through origin
  57. line = bg::detail::make::make_infinite_line<T>(5, 2, -8, 10);
  58. verify_point_on_line(line, 5, 2);
  59. verify_point_on_line(line, -8, 10);
  60. }
  61. template <typename T>
  62. void test_all()
  63. {
  64. test_make<T>();
  65. }
  66. int test_main(int, char* [])
  67. {
  68. test_all<double>();
  69. test_all<long double>();
  70. test_all<float>();
  71. test_all<int>();
  72. return 0;
  73. }