make.hpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. // Copyright (c) 2020-2023, Oracle and/or its affiliates.
  6. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_ALGORITHMS_MAKE_HPP
  14. #define BOOST_GEOMETRY_ALGORITHMS_MAKE_HPP
  15. #include <type_traits>
  16. #include "boost/geometry/algorithms/detail/assign_values.hpp"
  17. #include <boost/geometry/core/make.hpp>
  18. #include <boost/geometry/geometries/concepts/check.hpp>
  19. namespace boost { namespace geometry
  20. {
  21. #ifndef DOXYGEN_NO_DETAIL
  22. namespace detail { namespace make
  23. {
  24. /*!
  25. \brief Construct a geometry
  26. \ingroup make
  27. \tparam Geometry \tparam_geometry
  28. \tparam Range \tparam_range_point
  29. \param range \param_range_point
  30. \return The constructed geometry, here: a linestring or a ring
  31. \qbk{distinguish, with a range}
  32. \qbk{
  33. [heading Example]
  34. [make_with_range] [make_with_range_output]
  35. [heading See also]
  36. \* [link geometry.reference.algorithms.assign.assign_points assign]
  37. }
  38. */
  39. template <typename Geometry, typename Range>
  40. inline Geometry make_points(Range const& range)
  41. {
  42. concepts::check<Geometry>();
  43. Geometry geometry;
  44. geometry::append(geometry, range);
  45. return geometry;
  46. }
  47. }} // namespace detail::make
  48. #endif // DOXYGEN_NO_DETAIL
  49. /*!
  50. \brief Construct a geometry
  51. \ingroup make
  52. \details
  53. \note It does not work with array-point types, like int[2]
  54. \tparam Geometry \tparam_geometry
  55. \tparam Type \tparam_numeric to specify the coordinates
  56. \param c1 \param_x
  57. \param c2 \param_y
  58. \return The constructed geometry, here: a 2D point
  59. \qbk{distinguish, 2 coordinate values}
  60. \qbk{
  61. [heading Example]
  62. [make_2d_point] [make_2d_point_output]
  63. [heading See also]
  64. \* [link geometry.reference.algorithms.assign.assign_values_3_2_coordinate_values assign]
  65. }
  66. */
  67. template
  68. <
  69. typename Geometry,
  70. typename Type,
  71. std::enable_if_t<! traits::make<Geometry>::is_specialized, int> = 0
  72. >
  73. inline Geometry make(Type const& c1, Type const& c2)
  74. {
  75. concepts::check<Geometry>();
  76. Geometry geometry;
  77. dispatch::assign
  78. <
  79. typename tag<Geometry>::type,
  80. Geometry,
  81. geometry::dimension<Geometry>::type::value
  82. >::apply(geometry, c1, c2);
  83. return geometry;
  84. }
  85. template
  86. <
  87. typename Geometry,
  88. typename Type,
  89. std::enable_if_t<traits::make<Geometry>::is_specialized, int> = 0
  90. >
  91. constexpr inline Geometry make(Type const& c1, Type const& c2)
  92. {
  93. concepts::check<Geometry>();
  94. // NOTE: This is not fully equivalent to the above because assign uses
  95. // numeric_cast which can't be used here since it's not constexpr.
  96. return traits::make<Geometry>::apply(c1, c2);
  97. }
  98. /*!
  99. \brief Construct a geometry
  100. \ingroup make
  101. \tparam Geometry \tparam_geometry
  102. \tparam Type \tparam_numeric to specify the coordinates
  103. \param c1 \param_x
  104. \param c2 \param_y
  105. \param c3 \param_z
  106. \return The constructed geometry, here: a 3D point
  107. \qbk{distinguish, 3 coordinate values}
  108. \qbk{
  109. [heading Example]
  110. [make_3d_point] [make_3d_point_output]
  111. [heading See also]
  112. \* [link geometry.reference.algorithms.assign.assign_values_4_3_coordinate_values assign]
  113. }
  114. */
  115. template
  116. <
  117. typename Geometry,
  118. typename Type,
  119. std::enable_if_t<! traits::make<Geometry>::is_specialized, int> = 0
  120. >
  121. inline Geometry make(Type const& c1, Type const& c2, Type const& c3)
  122. {
  123. concepts::check<Geometry>();
  124. Geometry geometry;
  125. dispatch::assign
  126. <
  127. typename tag<Geometry>::type,
  128. Geometry,
  129. geometry::dimension<Geometry>::type::value
  130. >::apply(geometry, c1, c2, c3);
  131. return geometry;
  132. }
  133. template
  134. <
  135. typename Geometry,
  136. typename Type,
  137. std::enable_if_t<traits::make<Geometry>::is_specialized, int> = 0
  138. >
  139. constexpr inline Geometry make(Type const& c1, Type const& c2, Type const& c3)
  140. {
  141. concepts::check<Geometry>();
  142. // NOTE: This is not fully equivalent to the above because assign uses
  143. // numeric_cast which can't be used here since it's not constexpr.
  144. return traits::make<Geometry>::apply(c1, c2, c3);
  145. }
  146. template <typename Geometry, typename Type>
  147. inline Geometry make(Type const& c1, Type const& c2, Type const& c3, Type const& c4)
  148. {
  149. concepts::check<Geometry>();
  150. Geometry geometry;
  151. dispatch::assign
  152. <
  153. typename tag<Geometry>::type,
  154. Geometry,
  155. geometry::dimension<Geometry>::type::value
  156. >::apply(geometry, c1, c2, c3, c4);
  157. return geometry;
  158. }
  159. /*!
  160. \brief Construct a box with inverse infinite coordinates
  161. \ingroup make
  162. \details The make_inverse function initializes a 2D or 3D box with large coordinates, the
  163. min corner is very large, the max corner is very small. This is useful e.g. in combination
  164. with the expand function, to determine the bounding box of a series of geometries.
  165. \tparam Geometry \tparam_geometry
  166. \return The constructed geometry, here: a box
  167. \qbk{
  168. [heading Example]
  169. [make_inverse] [make_inverse_output]
  170. [heading See also]
  171. \* [link geometry.reference.algorithms.assign.assign_inverse assign_inverse]
  172. }
  173. */
  174. template <typename Geometry>
  175. inline Geometry make_inverse()
  176. {
  177. concepts::check<Geometry>();
  178. Geometry geometry;
  179. dispatch::assign_inverse
  180. <
  181. typename tag<Geometry>::type,
  182. Geometry
  183. >::apply(geometry);
  184. return geometry;
  185. }
  186. /*!
  187. \brief Construct a geometry with its coordinates initialized to zero
  188. \ingroup make
  189. \details The make_zero function initializes a 2D or 3D point or box with coordinates of zero
  190. \tparam Geometry \tparam_geometry
  191. \return The constructed and zero-initialized geometry
  192. */
  193. template <typename Geometry>
  194. inline Geometry make_zero()
  195. {
  196. concepts::check<Geometry>();
  197. Geometry geometry;
  198. dispatch::assign_zero
  199. <
  200. typename tag<Geometry>::type,
  201. Geometry
  202. >::apply(geometry);
  203. return geometry;
  204. }
  205. }} // namespace boost::geometry
  206. #endif // BOOST_GEOMETRY_ALGORITHMS_MAKE_HPP