envelope.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2015, 2016, 2018, 2019.
  6. // Modifications copyright (c) 2015-2019, Oracle and/or its affiliates.
  7. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  8. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  9. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  10. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  11. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  12. // Distributed under the Boost Software License, Version 1.0.
  13. // (See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_ENVELOPE_HPP
  16. #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_ENVELOPE_HPP
  17. #include <boost/range/begin.hpp>
  18. #include <boost/range/end.hpp>
  19. #include <boost/geometry/algorithms/detail/envelope/initialize.hpp>
  20. #include <boost/geometry/strategies/cartesian/envelope_box.hpp>
  21. #include <boost/geometry/strategies/cartesian/envelope_segment.hpp>
  22. #include <boost/geometry/strategies/cartesian/expand_box.hpp>
  23. #include <boost/geometry/strategies/cartesian/expand_segment.hpp>
  24. namespace boost { namespace geometry
  25. {
  26. namespace strategy { namespace envelope
  27. {
  28. template <typename CalculationType = void>
  29. class cartesian
  30. {
  31. public:
  32. typedef cartesian_tag cs_tag;
  33. typedef cartesian_point element_envelope_strategy_type;
  34. static inline element_envelope_strategy_type get_element_envelope_strategy()
  35. {
  36. return element_envelope_strategy_type();
  37. }
  38. typedef expand::cartesian_point element_expand_strategy_type;
  39. static inline element_expand_strategy_type get_element_expand_strategy()
  40. {
  41. return element_expand_strategy_type();
  42. }
  43. typedef expand::cartesian_box box_expand_strategy_type;
  44. static inline box_expand_strategy_type get_box_expand_strategy()
  45. {
  46. return box_expand_strategy_type();
  47. }
  48. // Linestring, Ring, Polygon
  49. template <typename Range>
  50. static inline typename boost::range_iterator<Range const>::type begin(Range const& range)
  51. {
  52. return boost::begin(range);
  53. }
  54. template <typename Range>
  55. static inline typename boost::range_iterator<Range const>::type end(Range const& range)
  56. {
  57. return boost::end(range);
  58. }
  59. // MultiLinestring, MultiPolygon
  60. template <typename Box>
  61. struct multi_state
  62. {
  63. multi_state()
  64. : m_initialized(false)
  65. {}
  66. void apply(Box const& single_box)
  67. {
  68. if (! m_initialized)
  69. {
  70. m_box = single_box;
  71. m_initialized = true;
  72. }
  73. else
  74. {
  75. box_expand_strategy_type::apply(m_box, single_box);
  76. }
  77. }
  78. void result(Box & box)
  79. {
  80. if (m_initialized)
  81. {
  82. box = m_box;
  83. }
  84. else
  85. {
  86. geometry::detail::envelope::initialize<Box, 0, dimension<Box>::value>::apply(box);
  87. }
  88. }
  89. private:
  90. bool m_initialized;
  91. Box m_box;
  92. };
  93. // Segment
  94. template <typename Point1, typename Point2, typename Box>
  95. static inline void apply(Point1 const& point1, Point2 const& point2,
  96. Box& box)
  97. {
  98. cartesian_segment<CalculationType>::apply(point1, point2, box);
  99. }
  100. // Box
  101. template <typename BoxIn, typename Box>
  102. static inline void apply(BoxIn const& box_in, Box& box)
  103. {
  104. cartesian_box::apply(box_in, box);
  105. }
  106. };
  107. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  108. namespace services
  109. {
  110. template <typename Tag, typename CalculationType>
  111. struct default_strategy<Tag, cartesian_tag, CalculationType>
  112. {
  113. typedef strategy::envelope::cartesian<CalculationType> type;
  114. };
  115. } // namespace services
  116. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  117. }} // namespace strategy::envelope
  118. }} //namepsace boost::geometry
  119. #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_ENVELOPE_HPP