make.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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_MAKE_HPP
  11. #define BOOST_GEOMETRY_ALGORITHMS_MAKE_HPP
  12. #include <boost/geometry/algorithms/assign.hpp>
  13. #include <boost/geometry/geometries/concepts/check.hpp>
  14. namespace boost { namespace geometry
  15. {
  16. #ifndef DOXYGEN_NO_DETAIL
  17. namespace detail { namespace make
  18. {
  19. /*!
  20. \brief Construct a geometry
  21. \ingroup make
  22. \tparam Geometry \tparam_geometry
  23. \tparam Range \tparam_range_point
  24. \param range \param_range_point
  25. \return The constructed geometry, here: a linestring or a ring
  26. \qbk{distinguish, with a range}
  27. \qbk{
  28. [heading Example]
  29. [make_with_range] [make_with_range_output]
  30. [heading See also]
  31. \* [link geometry.reference.algorithms.assign.assign_points assign]
  32. }
  33. */
  34. template <typename Geometry, typename Range>
  35. inline Geometry make_points(Range const& range)
  36. {
  37. concepts::check<Geometry>();
  38. Geometry geometry;
  39. geometry::append(geometry, range);
  40. return geometry;
  41. }
  42. }} // namespace detail::make
  43. #endif // DOXYGEN_NO_DETAIL
  44. /*!
  45. \brief Construct a geometry
  46. \ingroup make
  47. \details
  48. \note It does not work with array-point types, like int[2]
  49. \tparam Geometry \tparam_geometry
  50. \tparam Type \tparam_numeric to specify the coordinates
  51. \param c1 \param_x
  52. \param c2 \param_y
  53. \return The constructed geometry, here: a 2D point
  54. \qbk{distinguish, 2 coordinate values}
  55. \qbk{
  56. [heading Example]
  57. [make_2d_point] [make_2d_point_output]
  58. [heading See also]
  59. \* [link geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values assign]
  60. }
  61. */
  62. template <typename Geometry, typename Type>
  63. inline Geometry make(Type const& c1, Type const& c2)
  64. {
  65. concepts::check<Geometry>();
  66. Geometry geometry;
  67. dispatch::assign
  68. <
  69. typename tag<Geometry>::type,
  70. Geometry,
  71. geometry::dimension<Geometry>::type::value
  72. >::apply(geometry, c1, c2);
  73. return geometry;
  74. }
  75. /*!
  76. \brief Construct a geometry
  77. \ingroup make
  78. \tparam Geometry \tparam_geometry
  79. \tparam Type \tparam_numeric to specify the coordinates
  80. \param c1 \param_x
  81. \param c2 \param_y
  82. \param c3 \param_z
  83. \return The constructed geometry, here: a 3D point
  84. \qbk{distinguish, 3 coordinate values}
  85. \qbk{
  86. [heading Example]
  87. [make_3d_point] [make_3d_point_output]
  88. [heading See also]
  89. \* [link geometry.reference.algorithms.assign.assign_values_4_3_coordinate_values assign]
  90. }
  91. */
  92. template <typename Geometry, typename Type>
  93. inline Geometry make(Type const& c1, Type const& c2, Type const& c3)
  94. {
  95. concepts::check<Geometry>();
  96. Geometry geometry;
  97. dispatch::assign
  98. <
  99. typename tag<Geometry>::type,
  100. Geometry,
  101. geometry::dimension<Geometry>::type::value
  102. >::apply(geometry, c1, c2, c3);
  103. return geometry;
  104. }
  105. template <typename Geometry, typename Type>
  106. inline Geometry make(Type const& c1, Type const& c2, Type const& c3, Type const& c4)
  107. {
  108. concepts::check<Geometry>();
  109. Geometry geometry;
  110. dispatch::assign
  111. <
  112. typename tag<Geometry>::type,
  113. Geometry,
  114. geometry::dimension<Geometry>::type::value
  115. >::apply(geometry, c1, c2, c3, c4);
  116. return geometry;
  117. }
  118. /*!
  119. \brief Construct a box with inverse infinite coordinates
  120. \ingroup make
  121. \details The make_inverse function initializes a 2D or 3D box with large coordinates, the
  122. min corner is very large, the max corner is very small. This is useful e.g. in combination
  123. with the expand function, to determine the bounding box of a series of geometries.
  124. \tparam Geometry \tparam_geometry
  125. \return The constructed geometry, here: a box
  126. \qbk{
  127. [heading Example]
  128. [make_inverse] [make_inverse_output]
  129. [heading See also]
  130. \* [link geometry.reference.algorithms.assign.assign_inverse assign_inverse]
  131. }
  132. */
  133. template <typename Geometry>
  134. inline Geometry make_inverse()
  135. {
  136. concepts::check<Geometry>();
  137. Geometry geometry;
  138. dispatch::assign_inverse
  139. <
  140. typename tag<Geometry>::type,
  141. Geometry
  142. >::apply(geometry);
  143. return geometry;
  144. }
  145. /*!
  146. \brief Construct a geometry with its coordinates initialized to zero
  147. \ingroup make
  148. \details The make_zero function initializes a 2D or 3D point or box with coordinates of zero
  149. \tparam Geometry \tparam_geometry
  150. \return The constructed and zero-initialized geometry
  151. */
  152. template <typename Geometry>
  153. inline Geometry make_zero()
  154. {
  155. concepts::check<Geometry>();
  156. Geometry geometry;
  157. dispatch::assign_zero
  158. <
  159. typename tag<Geometry>::type,
  160. Geometry
  161. >::apply(geometry);
  162. return geometry;
  163. }
  164. }} // namespace boost::geometry
  165. #endif // BOOST_GEOMETRY_ALGORITHMS_MAKE_HPP