envelope.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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.
  6. // Modifications copyright (c) 2015-2018, 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_point element_envelope_strategy_type;
  33. static inline element_envelope_strategy_type get_element_envelope_strategy()
  34. {
  35. return element_envelope_strategy_type();
  36. }
  37. typedef expand::cartesian_point element_expand_strategy_type;
  38. static inline element_expand_strategy_type get_element_expand_strategy()
  39. {
  40. return element_expand_strategy_type();
  41. }
  42. typedef expand::cartesian_box box_expand_strategy_type;
  43. static inline box_expand_strategy_type get_box_expand_strategy()
  44. {
  45. return box_expand_strategy_type();
  46. }
  47. // Linestring, Ring, Polygon
  48. template <typename Range>
  49. static inline typename boost::range_iterator<Range const>::type begin(Range const& range)
  50. {
  51. return boost::begin(range);
  52. }
  53. template <typename Range>
  54. static inline typename boost::range_iterator<Range const>::type end(Range const& range)
  55. {
  56. return boost::end(range);
  57. }
  58. // MultiLinestring, MultiPolygon
  59. template <typename Box>
  60. struct multi_state
  61. {
  62. multi_state()
  63. : m_initialized(false)
  64. {}
  65. void apply(Box const& single_box)
  66. {
  67. if (! m_initialized)
  68. {
  69. m_box = single_box;
  70. m_initialized = true;
  71. }
  72. else
  73. {
  74. box_expand_strategy_type::apply(m_box, single_box);
  75. }
  76. }
  77. void result(Box & box)
  78. {
  79. if (m_initialized)
  80. {
  81. box = m_box;
  82. }
  83. else
  84. {
  85. geometry::detail::envelope::initialize<Box, 0, dimension<Box>::value>::apply(box);
  86. }
  87. }
  88. private:
  89. bool m_initialized;
  90. Box m_box;
  91. };
  92. // Segment
  93. template <typename Point1, typename Point2, typename Box>
  94. static inline void apply(Point1 const& point1, Point2 const& point2,
  95. Box& box)
  96. {
  97. cartesian_segment<CalculationType>::apply(point1, point2, box);
  98. }
  99. // Box
  100. template <typename BoxIn, typename Box>
  101. static inline void apply(BoxIn const& box_in, Box& box)
  102. {
  103. cartesian_box::apply(box_in, box);
  104. }
  105. };
  106. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  107. namespace services
  108. {
  109. template <typename Tag, typename CalculationType>
  110. struct default_strategy<Tag, cartesian_tag, CalculationType>
  111. {
  112. typedef strategy::envelope::cartesian<CalculationType> type;
  113. };
  114. } // namespace services
  115. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  116. }} // namespace strategy::envelope
  117. }} //namepsace boost::geometry
  118. #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_ENVELOPE_HPP