geometry_test_common.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  5. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  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. #ifndef GEOMETRY_TEST_GEOMETRY_TEST_COMMON_HPP
  11. #define GEOMETRY_TEST_GEOMETRY_TEST_COMMON_HPP
  12. #include <boost/config.hpp>
  13. // Determine debug/release mode
  14. // (it would be convenient if Boost.Config or Boost.Test would define this)
  15. // Note that they might be combined (e.g. for optimize+no inline)
  16. #if defined (BOOST_CLANG) || defined(BOOST_GCC)
  17. #if defined(__OPTIMIZE__)
  18. #define BOOST_GEOMETRY_COMPILER_MODE_RELEASE
  19. #endif
  20. #if defined(__NO_INLINE__)
  21. #define BOOST_GEOMETRY_COMPILER_MODE_DEBUG
  22. #endif
  23. #endif
  24. #if defined(BOOST_MSVC)
  25. #if defined(_DEBUG)
  26. #define BOOST_GEOMETRY_COMPILER_MODE_DEBUG
  27. #else
  28. #define BOOST_GEOMETRY_COMPILER_MODE_RELEASE
  29. #endif
  30. #endif
  31. #if defined(BOOST_MSVC)
  32. // We deliberately mix float/double's so turn off warnings
  33. #pragma warning( disable : 4244 )
  34. // For (new since Boost 1.40) warning in Boost.Test on putenv/posix
  35. #pragma warning( disable : 4996 )
  36. //#pragma warning( disable : 4305 )
  37. #endif // defined(BOOST_MSVC)
  38. #include <boost/config.hpp>
  39. #include <boost/concept_check.hpp>
  40. #include <boost/core/ignore_unused.hpp>
  41. #include <boost/foreach.hpp>
  42. #include <string_from_type.hpp>
  43. // Include some always-included-for-testing files
  44. #if ! defined(BOOST_GEOMETRY_NO_BOOST_TEST)
  45. // Until Boost.Test fixes it, silence warning issued by clang:
  46. #ifdef __clang__
  47. # pragma clang diagnostic push
  48. // warning: unused variable 'check_is_close' [-Wunused-variable]
  49. # pragma clang diagnostic ignored "-Wunused-variable"
  50. // warnings when -Wconversion is set
  51. # pragma clang diagnostic ignored "-Wsign-conversion"
  52. # pragma clang diagnostic ignored "-Wshorten-64-to-32"
  53. #endif
  54. # include <boost/test/tools/floating_point_comparison.hpp>
  55. #ifndef BOOST_TEST_MODULE
  56. # include <boost/test/included/test_exec_monitor.hpp>
  57. //# include <boost/test/included/prg_exec_monitor.hpp>
  58. # include <boost/test/impl/execution_monitor.ipp>
  59. #endif
  60. #ifdef __clang__
  61. # pragma clang diagnostic pop
  62. #endif
  63. #endif
  64. #if defined(HAVE_TTMATH)
  65. # include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
  66. #endif
  67. #if defined(HAVE_CLN) || defined(HAVE_GMP)
  68. # include <boost/numeric_adaptor/numeric_adaptor.hpp>
  69. #endif
  70. #if defined(HAVE_GMP)
  71. # include <boost/numeric_adaptor/gmp_value_type.hpp>
  72. #endif
  73. #if defined(HAVE_CLN)
  74. # include <boost/numeric_adaptor/cln_value_type.hpp>
  75. #endif
  76. // For all tests:
  77. // - do NOT use "using namespace boost::geometry" to make clear what is Boost.Geometry
  78. // - use bg:: as short alias
  79. #include <boost/geometry/core/coordinate_type.hpp>
  80. #include <boost/geometry/core/config.hpp>
  81. #include <boost/geometry/core/closure.hpp>
  82. #include <boost/geometry/core/point_order.hpp>
  83. #include <boost/geometry/core/tag.hpp>
  84. namespace bg = boost::geometry;
  85. template <typename CoordinateType, typename T1, typename T2>
  86. inline T1 if_typed_tt(T1 value_tt, T2 value)
  87. {
  88. #if defined(HAVE_TTMATH)
  89. return boost::is_same<CoordinateType, ttmath_big>::type::value ? value_tt : value;
  90. #else
  91. boost::ignore_unused(value_tt);
  92. return value;
  93. #endif
  94. }
  95. template <typename CoordinateType, typename Specified, typename T>
  96. inline T if_typed(T value_typed, T value)
  97. {
  98. return boost::is_same<CoordinateType, Specified>::value ? value_typed : value;
  99. }
  100. template <typename Geometry1, typename Geometry2>
  101. inline std::string type_for_assert_message()
  102. {
  103. bool const ccw =
  104. bg::point_order<Geometry1>::value == bg::counterclockwise
  105. || bg::point_order<Geometry2>::value == bg::counterclockwise;
  106. bool const open =
  107. bg::closure<Geometry1>::value == bg::open
  108. || bg::closure<Geometry2>::value == bg::open;
  109. std::ostringstream out;
  110. out << string_from_type<typename bg::coordinate_type<Geometry1>::type>::name()
  111. << (ccw ? " ccw" : "")
  112. << (open ? " open" : "");
  113. return out.str();
  114. }
  115. struct geographic_policy
  116. {
  117. template <typename CoordinateType>
  118. static inline CoordinateType apply(CoordinateType const& value)
  119. {
  120. return value;
  121. }
  122. };
  123. struct mathematical_policy
  124. {
  125. template <typename CoordinateType>
  126. static inline CoordinateType apply(CoordinateType const& value)
  127. {
  128. return 90 - value;
  129. }
  130. };
  131. typedef double default_test_type;
  132. #if defined(BOOST_GEOMETRY_USE_RESCALING)
  133. #define BG_IF_RESCALED(a, b) a
  134. #else
  135. #define BG_IF_RESCALED(a, b) b
  136. #endif
  137. #if defined(BOOST_GEOMETRY_USE_KRAMER_RULE)
  138. #define BG_IF_KRAMER(a, b) a
  139. #else
  140. #define BG_IF_KRAMER(a, b) b
  141. #endif
  142. inline void BoostGeometryWriteTestConfiguration()
  143. {
  144. std::cout << std::endl << "Test configuration:" << std::endl;
  145. #if defined(BOOST_GEOMETRY_USE_RESCALING)
  146. std::cout << " - Using rescaling" << std::endl;
  147. #endif
  148. #if defined(BOOST_GEOMETRY_USE_KRAMER_RULE)
  149. std::cout << " - Using Kramer rule" << std::endl;
  150. #else
  151. std::cout << " - Using general form" << std::endl;
  152. #endif
  153. #if defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
  154. std::cout << " - Testing only one type" << std::endl;
  155. #endif
  156. #if defined(BOOST_GEOMETRY_TEST_ONLY_ONE_ORDER)
  157. std::cout << " - Testing only one order" << std::endl;
  158. #endif
  159. #if defined(BOOST_GEOMETRY_TEST_FAILURES)
  160. std::cout << " - Including failing test cases" << std::endl;
  161. #endif
  162. std::cout << " - Default test type: " << string_from_type<default_test_type>::name() << std::endl;
  163. std::cout << std::endl;
  164. }
  165. #endif // GEOMETRY_TEST_GEOMETRY_TEST_COMMON_HPP