general.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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/arithmetic/arithmetic.hpp>
  13. #include <boost/geometry/algorithms/assign.hpp>
  14. #include <boost/geometry/geometries/point.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 P, typename P2>
  21. void test_addition()
  22. {
  23. P p1;
  24. bg::assign_values(p1, 1, 2, 3);
  25. bg::add_value(p1, 10);
  26. BOOST_CHECK(bg::get<0>(p1) == 11);
  27. BOOST_CHECK(bg::get<1>(p1) == 12);
  28. BOOST_CHECK(bg::get<2>(p1) == 13);
  29. P2 p2(4, 5, 6);
  30. bg::add_point(p1, p2);
  31. BOOST_CHECK(bg::get<0>(p1) == 15);
  32. BOOST_CHECK(bg::get<1>(p1) == 17);
  33. BOOST_CHECK(bg::get<2>(p1) == 19);
  34. }
  35. template <typename P, typename P2>
  36. void test_subtraction()
  37. {
  38. P p1;
  39. bg::assign_values(p1, 1, 2, 3);
  40. bg::subtract_value(p1, 10);
  41. BOOST_CHECK(bg::get<0>(p1) == -9);
  42. BOOST_CHECK(bg::get<1>(p1) == -8);
  43. BOOST_CHECK(bg::get<2>(p1) == -7);
  44. P2 p2(4, 6, 8);
  45. bg::subtract_point(p1, p2);
  46. BOOST_CHECK(bg::get<0>(p1) == -13);
  47. BOOST_CHECK(bg::get<1>(p1) == -14);
  48. BOOST_CHECK(bg::get<2>(p1) == -15);
  49. }
  50. template <typename P, typename P2>
  51. void test_multiplication()
  52. {
  53. P p1;
  54. bg::assign_values(p1, 1, 2, 3);
  55. bg::multiply_value(p1, 5);
  56. BOOST_CHECK(bg::get<0>(p1) == 5);
  57. BOOST_CHECK(bg::get<1>(p1) == 10);
  58. BOOST_CHECK(bg::get<2>(p1) == 15);
  59. P2 p2(4, 5, 6);
  60. bg::multiply_point(p1, p2);
  61. BOOST_CHECK(bg::get<0>(p1) == 20);
  62. BOOST_CHECK(bg::get<1>(p1) == 50);
  63. BOOST_CHECK(bg::get<2>(p1) == 90);
  64. }
  65. template <typename P, typename P2>
  66. void test_division()
  67. {
  68. P p1;
  69. bg::assign_values(p1, 50, 100, 150);
  70. bg::divide_value(p1, 5);
  71. BOOST_CHECK(bg::get<0>(p1) == 10);
  72. BOOST_CHECK(bg::get<1>(p1) == 20);
  73. BOOST_CHECK(bg::get<2>(p1) == 30);
  74. P2 p2(2, 4, 6);
  75. bg::divide_point(p1, p2);
  76. BOOST_CHECK(bg::get<0>(p1) == 5);
  77. BOOST_CHECK(bg::get<1>(p1) == 5);
  78. BOOST_CHECK(bg::get<2>(p1) == 5);
  79. }
  80. template <typename P, typename P2>
  81. void test_assign()
  82. {
  83. P p1;
  84. P2 p2(12, 34, 56);
  85. bg::assign_values(p1, 12, 34, 56);
  86. bg::assign_point(p1, p2);
  87. BOOST_CHECK(bg::get<0>(p1) == 12);
  88. BOOST_CHECK(bg::get<1>(p1) == 34);
  89. BOOST_CHECK(bg::get<2>(p1) == 56);
  90. bg::assign_value(p1, 78);
  91. BOOST_CHECK(bg::get<0>(p1) == 78);
  92. BOOST_CHECK(bg::get<1>(p1) == 78);
  93. BOOST_CHECK(bg::get<2>(p1) == 78);
  94. }
  95. template <typename P>
  96. void test_all()
  97. {
  98. typedef test::test_const_point P2;
  99. test_addition<P, P2>();
  100. test_subtraction<P, P2>();
  101. test_multiplication<P, P2>();
  102. test_division<P, P2>();
  103. test_assign<P, P2>();
  104. }
  105. int test_main(int, char* [])
  106. {
  107. test_all<int[3]>();
  108. test_all<float[3]>();
  109. test_all<double[3]>();
  110. test_all<test::test_point>();
  111. test_all<bg::model::point<int, 3, bg::cs::cartesian> >();
  112. test_all<bg::model::point<float, 3, bg::cs::cartesian> >();
  113. test_all<bg::model::point<double, 3, bg::cs::cartesian> >();
  114. return 0;
  115. }