segment.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 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 BOOST_GEOMETRY_GEOMETRIES_REGISTER_SEGMENT_HPP
  11. #define BOOST_GEOMETRY_GEOMETRIES_REGISTER_SEGMENT_HPP
  12. #ifndef DOXYGEN_NO_SPECIALIZATIONS
  13. #define BOOST_GEOMETRY_DETAIL_SPECIALIZE_SEGMENT_ACCESS(Segment, Point, Index0, Index1) \
  14. template <size_t D> \
  15. struct indexed_access<Segment, min_corner, D> \
  16. { \
  17. typedef typename coordinate_type<Point>::type ct; \
  18. static inline ct get(Segment const& b) \
  19. { return geometry::get<D>(b. Index0); } \
  20. static inline void set(Segment& b, ct const& value) \
  21. { geometry::set<D>(b. Index0, value); } \
  22. }; \
  23. template <size_t D> \
  24. struct indexed_access<Segment, max_corner, D> \
  25. { \
  26. typedef typename coordinate_type<Point>::type ct; \
  27. static inline ct get(Segment const& b) \
  28. { return geometry::get<D>(b. Index1); } \
  29. static inline void set(Segment& b, ct const& value) \
  30. { geometry::set<D>(b. Index1, value); } \
  31. };
  32. #define BOOST_GEOMETRY_DETAIL_SPECIALIZE_SEGMENT_ACCESS_TEMPLATIZED(Segment, Index0, Index1) \
  33. template <typename P, size_t D> \
  34. struct indexed_access<Segment<P>, min_corner, D> \
  35. { \
  36. typedef typename coordinate_type<P>::type ct; \
  37. static inline ct get(Segment<P> const& b) \
  38. { return geometry::get<D>(b. Index0); } \
  39. static inline void set(Segment<P>& b, ct const& value) \
  40. { geometry::set<D>(b. Index0, value); } \
  41. }; \
  42. template <typename P, size_t D> \
  43. struct indexed_access<Segment<P>, max_corner, D> \
  44. { \
  45. typedef typename coordinate_type<P>::type ct; \
  46. static inline ct get(Segment<P> const& b) \
  47. { return geometry::get<D>(b. Index1); } \
  48. static inline void set(Segment<P>& b, ct const& value) \
  49. { geometry::set<D>(b. Index1, value); } \
  50. };
  51. #define BOOST_GEOMETRY_DETAIL_SPECIALIZE_SEGMENT_ACCESS_4VALUES(Segment, Point, Left, Bottom, Right, Top) \
  52. template <> struct indexed_access<Segment, min_corner, 0> \
  53. { \
  54. typedef coordinate_type<Point>::type ct; \
  55. static inline ct get(Segment const& b) { return b. Left; } \
  56. static inline void set(Segment& b, ct const& value) { b. Left = value; } \
  57. }; \
  58. template <> struct indexed_access<Segment, min_corner, 1> \
  59. { \
  60. typedef coordinate_type<Point>::type ct; \
  61. static inline ct get(Segment const& b) { return b. Bottom; } \
  62. static inline void set(Segment& b, ct const& value) { b. Bottom = value; } \
  63. }; \
  64. template <> struct indexed_access<Segment, max_corner, 0> \
  65. { \
  66. typedef coordinate_type<Point>::type ct; \
  67. static inline ct get(Segment const& b) { return b. Right; } \
  68. static inline void set(Segment& b, ct const& value) { b. Right = value; } \
  69. }; \
  70. template <> struct indexed_access<Segment, max_corner, 1> \
  71. { \
  72. typedef coordinate_type<Point>::type ct; \
  73. static inline ct get(Segment const& b) { return b. Top; } \
  74. static inline void set(Segment& b, ct const& value) { b. Top = value; } \
  75. };
  76. #define BOOST_GEOMETRY_DETAIL_SPECIALIZE_SEGMENT_TRAITS(Segment, PointType) \
  77. template<> struct tag<Segment > { typedef segment_tag type; }; \
  78. template<> struct point_type<Segment > { typedef PointType type; };
  79. #define BOOST_GEOMETRY_DETAIL_SPECIALIZE_SEGMENT_TRAITS_TEMPLATIZED(Segment) \
  80. template<typename P> struct tag<Segment<P> > { typedef segment_tag type; }; \
  81. template<typename P> struct point_type<Segment<P> > { typedef P type; };
  82. #endif // DOXYGEN_NO_SPECIALIZATIONS
  83. #define BOOST_GEOMETRY_REGISTER_SEGMENT(Segment, PointType, Index0, Index1) \
  84. namespace boost { namespace geometry { namespace traits { \
  85. BOOST_GEOMETRY_DETAIL_SPECIALIZE_SEGMENT_TRAITS(Segment, PointType) \
  86. BOOST_GEOMETRY_DETAIL_SPECIALIZE_SEGMENT_ACCESS(Segment, PointType, Index0, Index1) \
  87. }}}
  88. #define BOOST_GEOMETRY_REGISTER_SEGMENT_TEMPLATIZED(Segment, Index0, Index1) \
  89. namespace boost { namespace geometry { namespace traits { \
  90. BOOST_GEOMETRY_DETAIL_SPECIALIZE_SEGMENT_TRAITS_TEMPLATIZED(Segment) \
  91. BOOST_GEOMETRY_DETAIL_SPECIALIZE_SEGMENT_ACCESS_TEMPLATIZED(Segment, Index0, Index1) \
  92. }}}
  93. #define BOOST_GEOMETRY_REGISTER_SEGMENT_2D_4VALUES(Segment, PointType, Left, Bottom, Right, Top) \
  94. namespace boost { namespace geometry { namespace traits { \
  95. BOOST_GEOMETRY_DETAIL_SPECIALIZE_SEGMENT_TRAITS(Segment, PointType) \
  96. BOOST_GEOMETRY_DETAIL_SPECIALIZE_SEGMENT_ACCESS_4VALUES(Segment, PointType, Left, Bottom, Right, Top) \
  97. }}}
  98. // CONST versions are for segments probably not that common. Postponed.
  99. #endif // BOOST_GEOMETRY_GEOMETRIES_REGISTER_SEGMENT_HPP