test_point.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef GEOMETRY_TEST_TEST_COMMON_TEST_POINT_HPP
  9. #define GEOMETRY_TEST_TEST_COMMON_TEST_POINT_HPP
  10. #include <boost/geometry/core/access.hpp>
  11. #include <boost/geometry/core/coordinate_type.hpp>
  12. #include <boost/geometry/core/coordinate_system.hpp>
  13. #include <boost/geometry/core/coordinate_dimension.hpp>
  14. #include <boost/geometry/core/cs.hpp>
  15. #include <boost/geometry/core/tag.hpp>
  16. #include <boost/geometry/geometries/register/point.hpp>
  17. // NOTE: since Boost 1.51 the Point type may always be a pointer.
  18. // Therefore the traits class don't need to add a pointer.
  19. // This obsoletes this whole test-point-type
  20. namespace test
  21. {
  22. // Test point class
  23. struct test_point
  24. {
  25. float c1, c2, c3;
  26. };
  27. struct test_const_point
  28. {
  29. test_const_point()
  30. : c1(0.0), c2(0.0), c3(0.0) { }
  31. test_const_point(float c1, float c2, float c3)
  32. : c1(c1), c2(c2), c3(c3) { }
  33. const float c1, c2, c3;
  34. };
  35. } // namespace test
  36. namespace boost { namespace geometry { namespace traits {
  37. template<>
  38. struct tag<test::test_point> { typedef point_tag type; };
  39. template<>
  40. struct coordinate_type<test::test_point> { typedef float type; };
  41. template<>
  42. struct coordinate_system<test::test_point> { typedef cs::cartesian type; };
  43. template<>
  44. struct dimension<test::test_point>: boost::mpl::int_<3> {};
  45. template<> struct access<test::test_point, 0>
  46. {
  47. static inline const float& get(const test::test_point& p)
  48. {
  49. return p.c1;
  50. }
  51. static inline void set(test::test_point& p, const float& value)
  52. {
  53. p.c1 = value;
  54. }
  55. };
  56. template<> struct access<test::test_point, 1>
  57. {
  58. static inline const float& get(const test::test_point& p)
  59. {
  60. return p.c2;
  61. }
  62. static inline void set(test::test_point& p, const float& value)
  63. {
  64. p.c2 = value;
  65. }
  66. };
  67. template<> struct access<test::test_point, 2>
  68. {
  69. static inline const float& get(const test::test_point& p)
  70. {
  71. return p.c3;
  72. }
  73. static inline void set(test::test_point& p, const float& value)
  74. {
  75. p.c3 = value;
  76. }
  77. };
  78. }}} // namespace bg::traits
  79. BOOST_GEOMETRY_REGISTER_POINT_3D_CONST(test::test_const_point,
  80. float,
  81. boost::geometry::cs::cartesian,
  82. c1, c2, c3)
  83. #endif // GEOMETRY_TEST_TEST_COMMON_TEST_POINT_HPP