// Boost.Geometry (aka GGL, Generic Geometry Library) // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. // Copyright (c) 2014 Samuel Debionne, Grenoble, France. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_GEOMETRY_ALGORITHMS_EXPAND_HPP #define BOOST_GEOMETRY_ALGORITHMS_EXPAND_HPP #include #include #include #include #include #include #include #include #include #include namespace boost { namespace geometry { #ifndef DOXYGEN_NO_DETAIL namespace detail { namespace expand { template < typename StrategyLess, typename StrategyGreater, std::size_t Dimension, std::size_t DimensionCount > struct point_loop { template static inline void apply(Box& box, Point const& source) { typedef typename strategy::compare::detail::select_strategy < StrategyLess, 1, Point, Dimension >::type less_type; typedef typename strategy::compare::detail::select_strategy < StrategyGreater, -1, Point, Dimension >::type greater_type; typedef typename select_coordinate_type::type coordinate_type; less_type less; greater_type greater; coordinate_type const coord = get(source); if (less(coord, get(box))) { set(box, coord); } if (greater(coord, get(box))) { set(box, coord); } point_loop < StrategyLess, StrategyGreater, Dimension + 1, DimensionCount >::apply(box, source); } }; template < typename StrategyLess, typename StrategyGreater, std::size_t DimensionCount > struct point_loop < StrategyLess, StrategyGreater, DimensionCount, DimensionCount > { template static inline void apply(Box&, Point const&) {} }; template < typename StrategyLess, typename StrategyGreater, std::size_t Index, std::size_t Dimension, std::size_t DimensionCount > struct indexed_loop { template static inline void apply(Box& box, Geometry const& source) { typedef typename strategy::compare::detail::select_strategy < StrategyLess, 1, Box, Dimension >::type less_type; typedef typename strategy::compare::detail::select_strategy < StrategyGreater, -1, Box, Dimension >::type greater_type; typedef typename select_coordinate_type < Box, Geometry >::type coordinate_type; less_type less; greater_type greater; coordinate_type const coord = get(source); if (less(coord, get(box))) { set(box, coord); } if (greater(coord, get(box))) { set(box, coord); } indexed_loop < StrategyLess, StrategyGreater, Index, Dimension + 1, DimensionCount >::apply(box, source); } }; template < typename StrategyLess, typename StrategyGreater, std::size_t Index, std::size_t DimensionCount > struct indexed_loop < StrategyLess, StrategyGreater, Index, DimensionCount, DimensionCount > { template static inline void apply(Box&, Geometry const&) {} }; // Changes a box such that the other box is also contained by the box template < typename StrategyLess, typename StrategyGreater > struct expand_indexed { template static inline void apply(Box& box, Geometry const& geometry) { indexed_loop < StrategyLess, StrategyGreater, 0, 0, dimension::type::value >::apply(box, geometry); indexed_loop < StrategyLess, StrategyGreater, 1, 0, dimension::type::value >::apply(box, geometry); } }; }} // namespace detail::expand #endif // DOXYGEN_NO_DETAIL #ifndef DOXYGEN_NO_DISPATCH namespace dispatch { template < typename GeometryOut, typename Geometry, typename StrategyLess = strategy::compare::default_strategy, typename StrategyGreater = strategy::compare::default_strategy, typename TagOut = typename tag::type, typename Tag = typename tag::type > struct expand: not_implemented {}; // Box + point -> new box containing also point template < typename BoxOut, typename Point, typename StrategyLess, typename StrategyGreater > struct expand : detail::expand::point_loop < StrategyLess, StrategyGreater, 0, dimension::type::value > {}; // Box + box -> new box containing two input boxes template < typename BoxOut, typename BoxIn, typename StrategyLess, typename StrategyGreater > struct expand : detail::expand::expand_indexed {}; template < typename Box, typename Segment, typename StrategyLess, typename StrategyGreater > struct expand : detail::expand::expand_indexed {}; } // namespace dispatch #endif // DOXYGEN_NO_DISPATCH namespace resolve_variant { template struct expand { template static inline void apply(Box& box, Geometry const& geometry) { concept::check(); concept::check(); concept::check_concepts_and_equal_dimensions(); dispatch::expand::apply(box, geometry); } }; template struct expand > { template struct visitor: boost::static_visitor { Box& m_box; visitor(Box& box) : m_box(box) {} template void operator()(Geometry const& geometry) const { return expand::apply(m_box, geometry); } }; template static inline void apply(Box& box, boost::variant const& geometry) { return boost::apply_visitor(visitor(box), geometry); } }; } // namespace resolve_variant /*** *! \brief Expands a box using the extend (envelope) of another geometry (box, point) \ingroup expand \tparam Box type of the box \tparam Geometry of second geometry, to be expanded with the box \param box box to expand another geometry with, might be changed \param geometry other geometry \param strategy_less \param strategy_greater \note Strategy is currently ignored * template < typename Box, typename Geometry, typename StrategyLess, typename StrategyGreater > inline void expand(Box& box, Geometry const& geometry, StrategyLess const& strategy_less, StrategyGreater const& strategy_greater) { concept::check_concepts_and_equal_dimensions(); dispatch::expand::apply(box, geometry); } ***/ /*! \brief Expands a box using the bounding box (envelope) of another geometry (box, point) \ingroup expand \tparam Box type of the box \tparam Geometry \tparam_geometry \param box box to be expanded using another geometry, mutable \param geometry \param_geometry geometry which envelope (bounding box) will be added to the box \qbk{[include reference/algorithms/expand.qbk]} */ template inline void expand(Box& box, Geometry const& geometry) { resolve_variant::expand::apply(box, geometry); } }} // namespace boost::geometry #endif // BOOST_GEOMETRY_ALGORITHMS_EXPAND_HPP