]>
Commit | Line | Data |
---|---|---|
1 | // Boost.Geometry | |
2 | ||
3 | // Copyright (c) 2015 Oracle and/or its affiliates. | |
4 | ||
5 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle | |
6 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle | |
7 | ||
8 | // Use, modification and distribution is subject to the Boost Software License, | |
9 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
10 | // http://www.boost.org/LICENSE_1_0.txt) | |
11 | ||
12 | #ifndef BOOST_GEOMETRY_UTIL_HAS_NAN_COORDINATE_HPP | |
13 | #define BOOST_GEOMETRY_UTIL_HAS_NAN_COORDINATE_HPP | |
14 | ||
15 | #include <cstddef> | |
16 | ||
17 | #include <boost/type_traits/is_floating_point.hpp> | |
18 | ||
19 | #include <boost/geometry/core/access.hpp> | |
20 | #include <boost/geometry/core/coordinate_dimension.hpp> | |
21 | #include <boost/geometry/core/coordinate_type.hpp> | |
22 | ||
23 | #include <boost/math/special_functions/fpclassify.hpp> | |
24 | ||
25 | ||
26 | namespace boost { namespace geometry | |
27 | { | |
28 | ||
29 | #ifndef DOXYGEN_NO_DETAIL | |
30 | namespace detail | |
31 | { | |
32 | ||
33 | struct isnan | |
34 | { | |
35 | template <typename T> | |
36 | static inline bool apply(T const& t) | |
37 | { | |
38 | return boost::math::isnan(t); | |
39 | } | |
40 | }; | |
41 | ||
42 | template | |
43 | < | |
44 | typename Point, | |
45 | typename Predicate, | |
46 | bool Enable, | |
47 | std::size_t I = 0, | |
48 | std::size_t N = geometry::dimension<Point>::value | |
49 | > | |
50 | struct has_coordinate_with_property | |
51 | { | |
52 | static bool apply(Point const& point) | |
53 | { | |
54 | return Predicate::apply(geometry::get<I>(point)) | |
55 | || has_coordinate_with_property | |
56 | < | |
57 | Point, Predicate, Enable, I+1, N | |
58 | >::apply(point); | |
59 | } | |
60 | }; | |
61 | ||
62 | template <typename Point, typename Predicate, std::size_t I, std::size_t N> | |
63 | struct has_coordinate_with_property<Point, Predicate, false, I, N> | |
64 | { | |
65 | static inline bool apply(Point const&) | |
66 | { | |
67 | return false; | |
68 | } | |
69 | }; | |
70 | ||
71 | template <typename Point, typename Predicate, std::size_t N> | |
72 | struct has_coordinate_with_property<Point, Predicate, true, N, N> | |
73 | { | |
74 | static bool apply(Point const& ) | |
75 | { | |
76 | return false; | |
77 | } | |
78 | }; | |
79 | ||
80 | } // namespace detail | |
81 | #endif // DOXYGEN_NO_DETAIL | |
82 | ||
83 | template <typename Point> | |
84 | bool has_nan_coordinate(Point const& point) | |
85 | { | |
86 | return detail::has_coordinate_with_property | |
87 | < | |
88 | Point, | |
89 | detail::isnan, | |
90 | boost::is_floating_point | |
91 | < | |
92 | typename coordinate_type<Point>::type | |
93 | >::value | |
94 | >::apply(point); | |
95 | } | |
96 | ||
97 | }} // namespace boost::geometry | |
98 | ||
99 | #endif // BOOST_GEOMETRY_UTIL_HAS_NAN_COORDINATE_HPP |