3 // Copyright (c) 2015, Oracle and/or its affiliates.
5 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7 // Distributed under the Boost Software License, Version 1.0.
8 // (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_EXPAND_EXPAND_BY_EPSILON_HPP
12 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_EXPAND_EXPAND_BY_EPSILON_HPP
17 #include <boost/type_traits/is_floating_point.hpp>
19 #include <boost/geometry/core/access.hpp>
20 #include <boost/geometry/core/coordinate_dimension.hpp>
21 #include <boost/geometry/core/coordinate_type.hpp>
23 #include <boost/geometry/util/math.hpp>
25 #include <boost/geometry/views/detail/indexed_point_view.hpp>
27 namespace boost { namespace geometry
30 #ifndef DOXYGEN_NO_DETAIL
31 namespace detail { namespace expand
37 template <typename> class PlusOrMinus,
39 std::size_t D = dimension<Point>::value,
40 bool Enable = boost::is_floating_point
42 typename coordinate_type<Point>::type
45 struct corner_by_epsilon
47 static inline void apply(Point & point)
49 typedef typename coordinate_type<Point>::type coord_type;
50 coord_type const coord = get<I>(point);
51 coord_type const eps = math::scaled_epsilon(coord);
53 set<I>(point, PlusOrMinus<coord_type>()(coord, eps));
55 corner_by_epsilon<Point, PlusOrMinus, I+1>::apply(point);
62 template <typename> class PlusOrMinus,
66 struct corner_by_epsilon<Point, PlusOrMinus, I, D, false>
68 static inline void apply(Point const&) {}
74 template <typename> class PlusOrMinus,
78 struct corner_by_epsilon<Point, PlusOrMinus, D, D, Enable>
80 static inline void apply(Point const&) {}
86 template <typename> class PlusOrMinus,
89 struct corner_by_epsilon<Point, PlusOrMinus, D, D, false>
91 static inline void apply(Point const&) {}
96 template <typename Box>
97 inline void expand_by_epsilon(Box & box)
99 typedef detail::indexed_point_view<Box, min_corner> min_type;
100 min_type min_point(box);
101 expand::corner_by_epsilon<min_type, std::minus>::apply(min_point);
103 typedef detail::indexed_point_view<Box, max_corner> max_type;
104 max_type max_point(box);
105 expand::corner_by_epsilon<max_type, std::plus>::apply(max_point);
108 } // namespace detail
109 #endif // DOXYGEN_NO_DETAIL
111 }} // namespace boost::geometry
113 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_EXPAND_EXPAND_BY_EPSILON_HPP