3 // Copyright (c) 2015-2019, 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_integral.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
41 struct corner_by_epsilon
43 static inline void apply(Point & point)
45 typedef typename coordinate_type<Point>::type coord_type;
46 coord_type const coord = get<I>(point);
47 coord_type const seps = math::scaled_epsilon(coord);
49 set<I>(point, PlusOrMinus<coord_type>()(coord, seps));
51 corner_by_epsilon<Point, PlusOrMinus, I+1>::apply(point);
54 static inline void apply(Point & point,
55 typename coordinate_type<Point>::type const& eps)
57 typedef typename coordinate_type<Point>::type coord_type;
58 coord_type const coord = get<I>(point);
59 coord_type const seps = math::scaled_epsilon(coord, eps);
61 set<I>(point, PlusOrMinus<coord_type>()(coord, seps));
63 corner_by_epsilon<Point, PlusOrMinus, I + 1>::apply(point);
70 template <typename> class PlusOrMinus,
73 struct corner_by_epsilon<Point, PlusOrMinus, D, D>
75 static inline void apply(Point const&) {}
76 static inline void apply(Point const&, typename coordinate_type<Point>::type const&) {}
82 bool Enable = ! boost::is_integral<typename coordinate_type<Box>::type>::value
84 struct expand_by_epsilon
86 static inline void apply(Box & box)
88 typedef detail::indexed_point_view<Box, min_corner> min_type;
89 min_type min_point(box);
90 corner_by_epsilon<min_type, std::minus>::apply(min_point);
92 typedef detail::indexed_point_view<Box, max_corner> max_type;
93 max_type max_point(box);
94 corner_by_epsilon<max_type, std::plus>::apply(max_point);
97 static inline void apply(Box & box,
98 typename coordinate_type<Box>::type const& eps)
100 typedef detail::indexed_point_view<Box, min_corner> min_type;
101 min_type min_point(box);
102 corner_by_epsilon<min_type, std::minus>::apply(min_point, eps);
104 typedef detail::indexed_point_view<Box, max_corner> max_type;
105 max_type max_point(box);
106 corner_by_epsilon<max_type, std::plus>::apply(max_point, eps);
110 template <typename Box>
111 struct expand_by_epsilon<Box, false>
113 static inline void apply(Box &) {}
114 static inline void apply(Box &, typename coordinate_type<Box>::type const&) {}
117 } // namespace expand
119 template <typename Box>
120 inline void expand_by_epsilon(Box & box)
122 expand::expand_by_epsilon<Box>::apply(box);
125 template <typename Box>
126 inline void expand_by_epsilon(Box & box,
127 typename coordinate_type<Box>::type const& eps)
129 expand::expand_by_epsilon<Box>::apply(box, eps);
132 } // namespace detail
133 #endif // DOXYGEN_NO_DETAIL
135 }} // namespace boost::geometry
137 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_EXPAND_EXPAND_BY_EPSILON_HPP