radian_access.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/core/radian_access.hpp>
  13. #include <boost/geometry/core/cs.hpp>
  14. #include <boost/geometry/core/coordinate_type.hpp>
  15. #include <boost/geometry/geometries/point.hpp>
  16. template <std::size_t D, typename P, typename T>
  17. void test_get(T const& c, T const& e)
  18. {
  19. //std::cout << "get_as_radian " << typeid(P).name() << std::endl;
  20. typedef typename bg::coordinate_type<P>::type coordinate_type;
  21. P p;
  22. bg::set<D>(p, coordinate_type(c));
  23. coordinate_type g = bg::get_as_radian<D>(p);
  24. BOOST_CHECK_CLOSE(double(g), double(e), 0.0001);
  25. }
  26. template <std::size_t D, typename P, typename T>
  27. void test_set(T const& c, T const& e)
  28. {
  29. //std::cout << "set_from_radian " << typeid(P).name() << std::endl;
  30. typedef typename bg::coordinate_type<P>::type coordinate_type;
  31. P p;
  32. bg::set_from_radian<D>(p, coordinate_type(c));
  33. coordinate_type g = bg::get<D>(p);
  34. BOOST_CHECK_CLOSE(double(g), double(e), 0.0001);
  35. }
  36. template <typename T>
  37. void test()
  38. {
  39. double d2r = 3.1415926535897932384626433832795 / 180.0;
  40. // Degree
  41. test_get<0, bg::model::point<T, 2, bg::cs::spherical<bg::degree> > >
  42. (1.0, 1.0 * d2r);
  43. test_get<1, bg::model::point<T, 2, bg::cs::spherical<bg::degree> > >
  44. (2.0, 2.0 * d2r);
  45. test_set<0, bg::model::point<T, 2, bg::cs::spherical<bg::degree> > >
  46. (1.0, 1.0 / d2r);
  47. test_set<1, bg::model::point<T, 2, bg::cs::spherical<bg::degree> > >
  48. (2.0, 2.0 / d2r);
  49. // Radian
  50. test_get<0, bg::model::point<T, 2, bg::cs::spherical<bg::radian> > >
  51. (1.0, 1.0);
  52. test_get<1, bg::model::point<T, 2, bg::cs::spherical<bg::radian> > >
  53. (1.0, 1.0);
  54. test_set<0, bg::model::point<T, 2, bg::cs::spherical<bg::radian> > >
  55. (1.0, 1.0);
  56. test_set<1, bg::model::point<T, 2, bg::cs::spherical<bg::radian> > >
  57. (1.0, 1.0);
  58. // Cartesian (== untouched, no conversion)
  59. test_get<0, bg::model::point<T, 2, bg::cs::cartesian> >
  60. (1.0, 1.0);
  61. test_get<1, bg::model::point<T, 2, bg::cs::cartesian> >
  62. (1.0, 1.0);
  63. // Dimension >=2, should always be untouched, even for degree
  64. // (assuming lat/lon + height)
  65. test_set<2, bg::model::point<T, 3, bg::cs::spherical<bg::radian> > >
  66. (1.0, 1.0);
  67. test_set<2, bg::model::point<T, 3, bg::cs::spherical<bg::degree> > >
  68. (1.0, 1.0);
  69. }
  70. int test_main(int, char* [])
  71. {
  72. //test<float>();
  73. test<double>();
  74. return 0;
  75. }