assign.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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_ALGORITHMS_ASSIGN_HPP
  11. #define BOOST_GEOMETRY_ALGORITHMS_ASSIGN_HPP
  12. #include <cstddef>
  13. #include <boost/concept/requires.hpp>
  14. #include <boost/concept_check.hpp>
  15. #include <boost/mpl/assert.hpp>
  16. #include <boost/mpl/if.hpp>
  17. #include <boost/numeric/conversion/bounds.hpp>
  18. #include <boost/numeric/conversion/cast.hpp>
  19. #include <boost/type_traits.hpp>
  20. #include <boost/geometry/algorithms/detail/assign_box_corners.hpp>
  21. #include <boost/geometry/algorithms/detail/assign_indexed_point.hpp>
  22. #include <boost/geometry/algorithms/detail/assign_values.hpp>
  23. #include <boost/geometry/algorithms/convert.hpp>
  24. #include <boost/geometry/algorithms/append.hpp>
  25. #include <boost/geometry/algorithms/clear.hpp>
  26. #include <boost/geometry/arithmetic/arithmetic.hpp>
  27. #include <boost/geometry/core/access.hpp>
  28. #include <boost/geometry/core/exterior_ring.hpp>
  29. #include <boost/geometry/core/tags.hpp>
  30. #include <boost/geometry/geometries/concepts/check.hpp>
  31. #include <boost/geometry/util/for_each_coordinate.hpp>
  32. namespace boost { namespace geometry
  33. {
  34. /*!
  35. \brief Assign a range of points to a linestring, ring or polygon
  36. \note The point-type of the range might be different from the point-type of the geometry
  37. \ingroup assign
  38. \tparam Geometry \tparam_geometry
  39. \tparam Range \tparam_range_point
  40. \param geometry \param_geometry
  41. \param range \param_range_point
  42. \qbk{
  43. [heading Notes]
  44. [note Assign automatically clears the geometry before assigning (use append if you don't want that)]
  45. [heading Example]
  46. [assign_points] [assign_points_output]
  47. [heading See also]
  48. \* [link geometry.reference.algorithms.append append]
  49. }
  50. */
  51. template <typename Geometry, typename Range>
  52. inline void assign_points(Geometry& geometry, Range const& range)
  53. {
  54. concept::check<Geometry>();
  55. clear(geometry);
  56. geometry::append(geometry, range, -1, 0);
  57. }
  58. /*!
  59. \brief assign to a box inverse infinite
  60. \details The assign_inverse function initialize a 2D or 3D box with large coordinates, the
  61. min corner is very large, the max corner is very small. This is a convenient starting point to
  62. collect the minimum bounding box of a geometry.
  63. \ingroup assign
  64. \tparam Geometry \tparam_geometry
  65. \param geometry \param_geometry
  66. \qbk{
  67. [heading Example]
  68. [assign_inverse] [assign_inverse_output]
  69. [heading See also]
  70. \* [link geometry.reference.algorithms.make.make_inverse make_inverse]
  71. }
  72. */
  73. template <typename Geometry>
  74. inline void assign_inverse(Geometry& geometry)
  75. {
  76. concept::check<Geometry>();
  77. dispatch::assign_inverse
  78. <
  79. typename tag<Geometry>::type,
  80. Geometry
  81. >::apply(geometry);
  82. }
  83. /*!
  84. \brief assign zero values to a box, point
  85. \ingroup assign
  86. \details The assign_zero function initializes a 2D or 3D point or box with coordinates of zero
  87. \tparam Geometry \tparam_geometry
  88. \param geometry \param_geometry
  89. */
  90. template <typename Geometry>
  91. inline void assign_zero(Geometry& geometry)
  92. {
  93. concept::check<Geometry>();
  94. dispatch::assign_zero
  95. <
  96. typename tag<Geometry>::type,
  97. Geometry
  98. >::apply(geometry);
  99. }
  100. /*!
  101. \brief Assigns one geometry to another geometry
  102. \details The assign algorithm assigns one geometry, e.g. a BOX, to another
  103. geometry, e.g. a RING. This only works if it is possible and applicable.
  104. \ingroup assign
  105. \tparam Geometry1 \tparam_geometry
  106. \tparam Geometry2 \tparam_geometry
  107. \param geometry1 \param_geometry (target)
  108. \param geometry2 \param_geometry (source)
  109. \qbk{
  110. [heading Example]
  111. [assign] [assign_output]
  112. [heading See also]
  113. \* [link geometry.reference.algorithms.convert convert]
  114. }
  115. */
  116. template <typename Geometry1, typename Geometry2>
  117. inline void assign(Geometry1& geometry1, Geometry2 const& geometry2)
  118. {
  119. concept::check_concepts_and_equal_dimensions<Geometry1, Geometry2 const>();
  120. bool const same_point_order =
  121. point_order<Geometry1>::value == point_order<Geometry2>::value;
  122. bool const same_closure =
  123. closure<Geometry1>::value == closure<Geometry2>::value;
  124. BOOST_MPL_ASSERT_MSG
  125. (
  126. same_point_order, ASSIGN_IS_NOT_SUPPORTED_FOR_DIFFERENT_POINT_ORDER
  127. , (types<Geometry1, Geometry2>)
  128. );
  129. BOOST_MPL_ASSERT_MSG
  130. (
  131. same_closure, ASSIGN_IS_NOT_SUPPORTED_FOR_DIFFERENT_CLOSURE
  132. , (types<Geometry1, Geometry2>)
  133. );
  134. dispatch::convert<Geometry2, Geometry1>::apply(geometry2, geometry1);
  135. }
  136. }} // namespace boost::geometry
  137. #endif // BOOST_GEOMETRY_ALGORITHMS_ASSIGN_HPP