1 | // Boost.Geometry Index |
2 | // |
3 | // n-dimensional content (hypervolume) - 2d area, 3d volume, ... |
4 | // |
5 | // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland. |
6 | // |
7 | // Use, modification and distribution is subject to the Boost Software License, |
8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
9 | // http://www.boost.org/LICENSE_1_0.txt) |
10 | |
11 | #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP |
12 | #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP |
13 | |
14 | namespace boost { namespace geometry { namespace index { namespace detail { |
15 | |
16 | template <typename Indexable> |
17 | struct default_content_result |
18 | { |
19 | typedef typename select_most_precise< |
20 | typename coordinate_type<Indexable>::type, |
21 | long double |
22 | >::type type; |
23 | }; |
24 | |
25 | namespace dispatch { |
26 | |
27 | template <typename Box, |
28 | std::size_t CurrentDimension = dimension<Box>::value> |
29 | struct content_box |
30 | { |
31 | BOOST_STATIC_ASSERT(0 < CurrentDimension); |
32 | |
33 | static inline typename detail::default_content_result<Box>::type apply(Box const& b) |
34 | { |
35 | return content_box<Box, CurrentDimension - 1>::apply(b) * |
36 | ( get<max_corner, CurrentDimension - 1>(b) - get<min_corner, CurrentDimension - 1>(b) ); |
37 | } |
38 | }; |
39 | |
40 | template <typename Box> |
41 | struct content_box<Box, 1> |
42 | { |
43 | static inline typename detail::default_content_result<Box>::type apply(Box const& b) |
44 | { |
45 | return get<max_corner, 0>(b) - get<min_corner, 0>(b); |
46 | } |
47 | }; |
48 | |
49 | template <typename Indexable, typename Tag> |
50 | struct content |
51 | { |
52 | BOOST_MPL_ASSERT_MSG(false, NOT_IMPLEMENTED_FOR_THIS_INDEXABLE_AND_TAG, (Indexable, Tag)); |
53 | }; |
54 | |
55 | template <typename Indexable> |
56 | struct content<Indexable, point_tag> |
57 | { |
58 | static typename detail::default_content_result<Indexable>::type apply(Indexable const&) |
59 | { |
60 | return 0; |
61 | } |
62 | }; |
63 | |
64 | template <typename Indexable> |
65 | struct content<Indexable, box_tag> |
66 | { |
67 | static typename default_content_result<Indexable>::type apply(Indexable const& b) |
68 | { |
69 | return dispatch::content_box<Indexable>::apply(b); |
70 | } |
71 | }; |
72 | |
73 | } // namespace dispatch |
74 | |
75 | template <typename Indexable> |
76 | typename default_content_result<Indexable>::type content(Indexable const& b) |
77 | { |
78 | return dispatch::content |
79 | < |
80 | Indexable, |
81 | typename tag<Indexable>::type |
82 | >::apply(b); |
83 | } |
84 | |
85 | }}}} // namespace boost::geometry::index::detail |
86 | |
87 | #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP |
88 | |