assign_box_corners.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_DETAIL_ASSIGN_BOX_CORNERS_HPP
  11. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_ASSIGN_BOX_CORNERS_HPP
  12. #include <cstddef>
  13. #include <boost/geometry/geometries/concepts/check.hpp>
  14. #include <boost/geometry/algorithms/detail/assign_values.hpp>
  15. #include <boost/geometry/util/range.hpp>
  16. namespace boost { namespace geometry
  17. {
  18. #ifndef DOXYGEN_NO_DETAIL
  19. namespace detail
  20. {
  21. // Note: this is moved to namespace detail because the names and parameter orders
  22. // are not yet 100% clear.
  23. /*!
  24. \brief Assign the four points of a 2D box
  25. \ingroup assign
  26. \note The order is crucial. Most logical is LOWER, UPPER and sub-order LEFT, RIGHT
  27. so this is how it is implemented.
  28. \tparam Box \tparam_box
  29. \tparam Point \tparam_point
  30. \param box \param_box
  31. \param lower_left point being assigned to lower left coordinates of the box
  32. \param lower_right point being assigned to lower right coordinates of the box
  33. \param upper_left point being assigned to upper left coordinates of the box
  34. \param upper_right point being assigned to upper right coordinates of the box
  35. \qbk{
  36. [heading Example]
  37. [assign_box_corners] [assign_box_corners_output]
  38. }
  39. */
  40. template <typename Box, typename Point>
  41. inline void assign_box_corners(Box const& box,
  42. Point& lower_left, Point& lower_right,
  43. Point& upper_left, Point& upper_right)
  44. {
  45. concepts::check<Box const>();
  46. concepts::check<Point>();
  47. detail::assign::assign_box_2d_corner
  48. <min_corner, min_corner>(box, lower_left);
  49. detail::assign::assign_box_2d_corner
  50. <max_corner, min_corner>(box, lower_right);
  51. detail::assign::assign_box_2d_corner
  52. <min_corner, max_corner>(box, upper_left);
  53. detail::assign::assign_box_2d_corner
  54. <max_corner, max_corner>(box, upper_right);
  55. }
  56. // Silence warning C4127: conditional expression is constant
  57. #if defined(_MSC_VER)
  58. #pragma warning(push)
  59. #pragma warning(disable : 4127)
  60. #endif
  61. template <bool Reverse, typename Box, typename Range>
  62. inline void assign_box_corners_oriented(Box const& box, Range& corners)
  63. {
  64. if (Reverse)
  65. {
  66. // make counterclockwise ll,lr,ur,ul
  67. assign_box_corners(box,
  68. range::at(corners, 0), range::at(corners, 1),
  69. range::at(corners, 3), range::at(corners, 2));
  70. }
  71. else
  72. {
  73. // make clockwise ll,ul,ur,lr
  74. assign_box_corners(box,
  75. range::at(corners, 0), range::at(corners, 3),
  76. range::at(corners, 1), range::at(corners, 2));
  77. }
  78. }
  79. #if defined(_MSC_VER)
  80. #pragma warning(pop)
  81. #endif
  82. } // namespace detail
  83. #endif // DOXYGEN_NO_DETAIL
  84. }} // namespace boost::geometry
  85. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_ASSIGN_BOX_CORNERS_HPP