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
14namespace boost { namespace geometry { namespace index { namespace detail {
15
16template <typename Indexable>
17struct default_content_result
18{
19 typedef typename select_most_precise<
20 typename coordinate_type<Indexable>::type,
21 long double
22 >::type type;
23};
24
25namespace dispatch {
26
27template <typename Box,
28 std::size_t CurrentDimension = dimension<Box>::value>
29struct 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
40template <typename Box>
41struct 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
49template <typename Indexable, typename Tag>
50struct content
51{
52 BOOST_MPL_ASSERT_MSG(false, NOT_IMPLEMENTED_FOR_THIS_INDEXABLE_AND_TAG, (Indexable, Tag));
53};
54
55template <typename Indexable>
56struct content<Indexable, point_tag>
57{
58 static typename detail::default_content_result<Indexable>::type apply(Indexable const&)
59 {
60 return 0;
61 }
62};
63
64template <typename Indexable>
65struct 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
75template <typename Indexable>
76typename 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