assign_values.hpp 6.6 KB

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