assign_values.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. // This file was modified by Oracle on 2018-2021.
  8. // Modifications copyright (c) 2018-2021, Oracle and/or its affiliates.
  9. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  10. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_ALGORITHMS_ASSIGN_VALUES_HPP
  15. #define BOOST_GEOMETRY_ALGORITHMS_ASSIGN_VALUES_HPP
  16. #include <cstddef>
  17. #include <type_traits>
  18. #include <boost/concept/requires.hpp>
  19. #include <boost/concept_check.hpp>
  20. #include <boost/numeric/conversion/bounds.hpp>
  21. #include <boost/numeric/conversion/cast.hpp>
  22. #include <boost/geometry/algorithms/append.hpp>
  23. #include <boost/geometry/algorithms/clear.hpp>
  24. #include <boost/geometry/core/access.hpp>
  25. #include <boost/geometry/core/exterior_ring.hpp>
  26. #include <boost/geometry/core/static_assert.hpp>
  27. #include <boost/geometry/core/tags.hpp>
  28. #include <boost/geometry/geometries/concepts/check.hpp>
  29. #include <boost/geometry/util/algorithm.hpp>
  30. #include <boost/geometry/util/is_inverse_spheroidal_coordinates.hpp>
  31. namespace boost { namespace geometry
  32. {
  33. #ifndef DOXYGEN_NO_DETAIL
  34. namespace detail { namespace assign
  35. {
  36. struct assign_zero_point
  37. {
  38. template <typename Point>
  39. static inline void apply(Point& point)
  40. {
  41. typedef typename coordinate_type<Point>::type coordinate_type;
  42. coordinate_type const zero = 0;
  43. detail::for_each_dimension<Point>([&](auto dimension)
  44. {
  45. set<dimension>(point, zero);
  46. });
  47. }
  48. };
  49. struct assign_inverse_box_or_segment
  50. {
  51. template <typename BoxOrSegment>
  52. static inline void apply(BoxOrSegment& geometry)
  53. {
  54. typedef typename coordinate_type<BoxOrSegment>::type coordinate_type;
  55. coordinate_type const highest = geometry::bounds<coordinate_type>::highest();
  56. coordinate_type const lowest = geometry::bounds<coordinate_type>::lowest();
  57. detail::for_each_dimension<BoxOrSegment>([&](auto dimension)
  58. {
  59. set<0, dimension>(geometry, highest);
  60. set<1, dimension>(geometry, lowest);
  61. });
  62. }
  63. };
  64. struct assign_zero_box_or_segment
  65. {
  66. template <typename BoxOrSegment>
  67. static inline void apply(BoxOrSegment& geometry)
  68. {
  69. typedef typename coordinate_type<BoxOrSegment>::type coordinate_type;
  70. coordinate_type const zero = 0;
  71. detail::for_each_dimension<BoxOrSegment>([&](auto dimension)
  72. {
  73. set<0, dimension>(geometry, zero);
  74. set<1, dimension>(geometry, zero);
  75. });
  76. }
  77. };
  78. template
  79. <
  80. std::size_t Corner1, std::size_t Corner2,
  81. typename Box, typename Point
  82. >
  83. inline void assign_box_2d_corner(Box const& box, Point& point)
  84. {
  85. // Be sure both are 2-Dimensional
  86. assert_dimension<Box, 2>();
  87. assert_dimension<Point, 2>();
  88. // Copy coordinates
  89. typedef typename coordinate_type<Point>::type coordinate_type;
  90. geometry::set<0>(point, boost::numeric_cast<coordinate_type>(get<Corner1, 0>(box)));
  91. geometry::set<1>(point, boost::numeric_cast<coordinate_type>(get<Corner2, 1>(box)));
  92. }
  93. template <typename Geometry>
  94. struct assign_2d_box_or_segment
  95. {
  96. typedef typename coordinate_type<Geometry>::type coordinate_type;
  97. // Here we assign 4 coordinates to a box of segment
  98. // -> Most logical is: x1,y1,x2,y2
  99. // In case the user reverses x1/x2 or y1/y2, for a box, we could reverse them (THAT IS NOT IMPLEMENTED)
  100. template <typename Type>
  101. static inline void apply(Geometry& geometry,
  102. Type const& x1, Type const& y1, Type const& x2, Type const& y2)
  103. {
  104. geometry::set<0, 0>(geometry, boost::numeric_cast<coordinate_type>(x1));
  105. geometry::set<0, 1>(geometry, boost::numeric_cast<coordinate_type>(y1));
  106. geometry::set<1, 0>(geometry, boost::numeric_cast<coordinate_type>(x2));
  107. geometry::set<1, 1>(geometry, boost::numeric_cast<coordinate_type>(y2));
  108. }
  109. };
  110. }} // namespace detail::assign
  111. #endif // DOXYGEN_NO_DETAIL
  112. #ifndef DOXYGEN_NO_DISPATCH
  113. namespace dispatch
  114. {
  115. template <typename GeometryTag, typename Geometry, std::size_t DimensionCount>
  116. struct assign
  117. {
  118. BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
  119. "Not or not yet implemented for this Geometry type.",
  120. GeometryTag, Geometry, std::integral_constant<std::size_t, DimensionCount>);
  121. };
  122. template <typename Point>
  123. struct assign<point_tag, Point, 2>
  124. {
  125. typedef typename coordinate_type<Point>::type coordinate_type;
  126. template <typename T>
  127. static inline void apply(Point& point, T const& c1, T const& c2)
  128. {
  129. set<0>(point, boost::numeric_cast<coordinate_type>(c1));
  130. set<1>(point, boost::numeric_cast<coordinate_type>(c2));
  131. }
  132. };
  133. template <typename Point>
  134. struct assign<point_tag, Point, 3>
  135. {
  136. typedef typename coordinate_type<Point>::type coordinate_type;
  137. template <typename T>
  138. static inline void apply(Point& point, T const& c1, T const& c2, T const& c3)
  139. {
  140. set<0>(point, boost::numeric_cast<coordinate_type>(c1));
  141. set<1>(point, boost::numeric_cast<coordinate_type>(c2));
  142. set<2>(point, boost::numeric_cast<coordinate_type>(c3));
  143. }
  144. };
  145. template <typename Box>
  146. struct assign<box_tag, Box, 2>
  147. : detail::assign::assign_2d_box_or_segment<Box>
  148. {};
  149. template <typename Segment>
  150. struct assign<segment_tag, Segment, 2>
  151. : detail::assign::assign_2d_box_or_segment<Segment>
  152. {};
  153. template <typename GeometryTag, typename Geometry>
  154. struct assign_zero {};
  155. template <typename Point>
  156. struct assign_zero<point_tag, Point>
  157. : detail::assign::assign_zero_point
  158. {};
  159. template <typename Box>
  160. struct assign_zero<box_tag, Box>
  161. : detail::assign::assign_zero_box_or_segment
  162. {};
  163. template <typename Segment>
  164. struct assign_zero<segment_tag, Segment>
  165. : detail::assign::assign_zero_box_or_segment
  166. {};
  167. template <typename GeometryTag, typename Geometry>
  168. struct assign_inverse {};
  169. template <typename Box>
  170. struct assign_inverse<box_tag, Box>
  171. : detail::assign::assign_inverse_box_or_segment
  172. {};
  173. template <typename Segment>
  174. struct assign_inverse<segment_tag, Segment>
  175. : detail::assign::assign_inverse_box_or_segment
  176. {};
  177. } // namespace dispatch
  178. #endif // DOXYGEN_NO_DISPATCH
  179. }} // namespace boost::geometry
  180. #endif // BOOST_GEOMETRY_ALGORITHMS_ASSIGN_VALUES_HPP