assign_indexed_point.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. // This file was modified by Oracle on 2021.
  6. // Modifications copyright (c) 2021, Oracle and/or its affiliates.
  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_DETAIL_ASSIGN_INDEXED_POINT_HPP
  14. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ASSIGN_INDEXED_POINT_HPP
  15. #include <cstddef>
  16. #include <boost/geometry/core/access.hpp>
  17. #include <boost/geometry/core/coordinate_type.hpp>
  18. #include <boost/geometry/geometries/concepts/check.hpp>
  19. #include <boost/geometry/util/algorithm.hpp>
  20. #include <boost/geometry/util/numeric_cast.hpp>
  21. namespace boost { namespace geometry
  22. {
  23. #ifndef DOXYGEN_NO_DETAIL
  24. namespace detail
  25. {
  26. /*!
  27. \brief Assign a box or segment with the value of a point
  28. \ingroup assign
  29. \tparam Index indicates which box-corner, min_corner (0) or max_corner (1)
  30. or which point of segment (0/1)
  31. \tparam Point \tparam_point
  32. \tparam Geometry \tparam_box_or_segment
  33. \param point \param_point
  34. \param geometry \param_box_or_segment
  35. \qbk{
  36. [heading Example]
  37. [assign_point_to_index] [assign_point_to_index_output]
  38. }
  39. */
  40. template <std::size_t Index, typename Geometry, typename Point>
  41. inline void assign_point_to_index(Point const& point, Geometry& geometry)
  42. {
  43. concepts::check<Point const>();
  44. concepts::check<Geometry>();
  45. detail::for_each_dimension<Geometry>([&](auto dimension)
  46. {
  47. geometry::set<Index, dimension>(geometry,
  48. util::numeric_cast
  49. <
  50. typename coordinate_type<Geometry>::type
  51. >(geometry::get<dimension>(point)));
  52. });
  53. }
  54. /*!
  55. \brief Assign a point with a point of a box or segment
  56. \ingroup assign
  57. \tparam Index indicates which box-corner, min_corner (0) or max_corner (1)
  58. or which point of segment (0/1)
  59. \tparam Geometry \tparam_box_or_segment
  60. \tparam Point \tparam_point
  61. \param geometry \param_box_or_segment
  62. \param point \param_point
  63. \qbk{
  64. [heading Example]
  65. [assign_point_from_index] [assign_point_from_index_output]
  66. }
  67. */
  68. template <std::size_t Index, typename Point, typename Geometry>
  69. inline void assign_point_from_index(Geometry const& geometry, Point& point)
  70. {
  71. concepts::check<Geometry const>();
  72. concepts::check<Point>();
  73. detail::for_each_dimension<Geometry>([&](auto dimension)
  74. {
  75. geometry::set<dimension>(point,
  76. util::numeric_cast
  77. <
  78. typename coordinate_type<Point>::type
  79. >(geometry::get<Index, dimension>(geometry)));
  80. });
  81. }
  82. } // namespace detail
  83. #endif // DOXYGEN_NO_DETAIL
  84. }} // namespace boost::geometry
  85. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ASSIGN_INDEXED_POINT_HPP