make.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  6. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  7. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #include <geometry_test_common.hpp>
  12. #include <boost/geometry/algorithms/make.hpp>
  13. #include <boost/geometry/io/wkt/write.hpp>
  14. #include <boost/geometry/geometries/geometries.hpp>
  15. #include <boost/geometry/geometries/adapted/c_array.hpp>
  16. #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
  17. #include <test_common/test_point.hpp>
  18. BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
  19. BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
  20. template <typename T, typename P>
  21. void test_point_2d()
  22. {
  23. P p = bg::make<P>((T) 123, (T) 456);
  24. BOOST_CHECK_CLOSE(bg::get<0>(p), 123.0, 1.0e-6);
  25. BOOST_CHECK_CLOSE(bg::get<1>(p), 456.0, 1.0e-6);
  26. }
  27. template <typename T, typename P>
  28. void test_point_3d()
  29. {
  30. P p = bg::make<P>((T) 123, (T) 456, (T) 789);
  31. BOOST_CHECK_CLOSE( bg::get<0>(p), 123.0, 1.0e-6);
  32. BOOST_CHECK_CLOSE( bg::get<1>(p), 456.0, 1.0e-6);
  33. BOOST_CHECK_CLOSE( bg::get<2>(p), 789.0, 1.0e-6);
  34. }
  35. template <typename T, typename P>
  36. void test_box_2d()
  37. {
  38. typedef bg::model::box<P> B;
  39. B b = bg::make<B>((T) 123, (T) 456, (T) 789, (T) 1011);
  40. BOOST_CHECK_CLOSE( (bg::get<bg::min_corner, 0>(b)), 123.0, 1.0e-6);
  41. BOOST_CHECK_CLOSE( (bg::get<bg::min_corner, 1>(b)), 456.0, 1.0e-6);
  42. BOOST_CHECK_CLOSE( (bg::get<bg::max_corner, 0>(b)), 789.0, 1.0e-6);
  43. BOOST_CHECK_CLOSE( (bg::get<bg::max_corner, 1>(b)), 1011.0, 1.0e-6);
  44. b = bg::make_inverse<B>();
  45. }
  46. template <typename T, typename P>
  47. void test_linestring_2d()
  48. {
  49. typedef bg::model::linestring<P> L;
  50. T coors[][2] = {{1,2}, {3,4}};
  51. L line = bg::detail::make::make_points<L>(coors);
  52. BOOST_CHECK_EQUAL(line.size(), 2u);
  53. }
  54. template <typename T, typename P>
  55. void test_linestring_3d()
  56. {
  57. typedef bg::model::linestring<P> L;
  58. T coors[][3] = {{1,2,3}, {4,5,6}};
  59. L line = bg::detail::make::make_points<L>(coors);
  60. BOOST_CHECK_EQUAL(line.size(), 2u);
  61. //std::cout << dsv(line) << std::endl;
  62. }
  63. template <typename T, typename P>
  64. void test_2d_t()
  65. {
  66. test_point_2d<T, P>();
  67. test_box_2d<T, P>();
  68. test_linestring_2d<T, P>();
  69. }
  70. template <typename P>
  71. void test_2d()
  72. {
  73. test_2d_t<int, P>();
  74. test_2d_t<float, P>();
  75. test_2d_t<double, P>();
  76. }
  77. template <typename T, typename P>
  78. void test_3d_t()
  79. {
  80. test_linestring_3d<T, P>();
  81. // test_point_3d<T, test_point>();
  82. }
  83. template <typename P>
  84. void test_3d()
  85. {
  86. test_3d_t<int, P>();
  87. test_3d_t<float, P>();
  88. test_3d_t<double, P>();
  89. }
  90. int test_main(int, char* [])
  91. {
  92. //test_2d<int[2]>();
  93. //test_2d<float[2]>();
  94. //test_2d<double[2]>();
  95. test_2d<bg::model::point<int, 2, bg::cs::cartesian> >();
  96. test_2d<bg::model::point<float, 2, bg::cs::cartesian> >();
  97. test_2d<bg::model::point<double, 2, bg::cs::cartesian> >();
  98. test_3d<bg::model::point<double, 3, bg::cs::cartesian> >();
  99. #if defined(HAVE_TTMATH)
  100. test_2d<bg::model::point<ttmath_big, 2, bg::cs::cartesian> >();
  101. test_3d<bg::model::point<ttmath_big, 3, bg::cs::cartesian> >();
  102. #endif
  103. return 0;
  104. }