File indexing completed on 2025-01-18 09:35:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_HAS_INVALID_COORDINATE_HPP
0013 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_HAS_INVALID_COORDINATE_HPP
0014
0015 #include <cstddef>
0016 #include <type_traits>
0017
0018 #include <boost/geometry/algorithms/validity_failure_type.hpp>
0019
0020 #include <boost/geometry/core/coordinate_type.hpp>
0021 #include <boost/geometry/core/point_type.hpp>
0022
0023 #include <boost/geometry/iterators/point_iterator.hpp>
0024
0025 #include <boost/geometry/views/detail/indexed_point_view.hpp>
0026
0027 #include <boost/geometry/util/has_non_finite_coordinate.hpp>
0028
0029 namespace boost { namespace geometry
0030 {
0031
0032 #ifndef DOXYGEN_NO_DETAIL
0033 namespace detail { namespace is_valid
0034 {
0035
0036 struct always_valid
0037 {
0038 template <typename Geometry, typename VisitPolicy>
0039 static inline bool apply(Geometry const&, VisitPolicy& visitor)
0040 {
0041 return ! visitor.template apply<no_failure>();
0042 }
0043 };
0044
0045 struct point_has_invalid_coordinate
0046 {
0047 template <typename Point, typename VisitPolicy>
0048 static inline bool apply(Point const& point, VisitPolicy& visitor)
0049 {
0050 boost::ignore_unused(visitor);
0051
0052 return
0053 geometry::has_non_finite_coordinate(point)
0054 ?
0055 (! visitor.template apply<failure_invalid_coordinate>())
0056 :
0057 (! visitor.template apply<no_failure>());
0058 }
0059
0060 template <typename Point>
0061 static inline bool apply(Point const& point)
0062 {
0063 return geometry::has_non_finite_coordinate(point);
0064 }
0065 };
0066
0067 struct indexed_has_invalid_coordinate
0068 {
0069 template <typename Geometry, typename VisitPolicy>
0070 static inline bool apply(Geometry const& geometry, VisitPolicy& visitor)
0071 {
0072 geometry::detail::indexed_point_view<Geometry const, 0> p0(geometry);
0073 geometry::detail::indexed_point_view<Geometry const, 1> p1(geometry);
0074
0075 return point_has_invalid_coordinate::apply(p0, visitor)
0076 || point_has_invalid_coordinate::apply(p1, visitor);
0077 }
0078 };
0079
0080
0081 struct range_has_invalid_coordinate
0082 {
0083 template <typename Geometry, typename VisitPolicy>
0084 static inline bool apply(Geometry const& geometry, VisitPolicy& visitor)
0085 {
0086 boost::ignore_unused(visitor);
0087
0088 auto const points_end = geometry::points_end(geometry);
0089 bool const has_valid_coordinates = std::none_of
0090 (
0091 geometry::points_begin(geometry), points_end,
0092 []( auto const& point ){
0093 return point_has_invalid_coordinate::apply(point);
0094 }
0095 );
0096
0097 return has_valid_coordinates
0098 ?
0099 (! visitor.template apply<no_failure>())
0100 :
0101 (! visitor.template apply<failure_invalid_coordinate>());
0102 }
0103 };
0104
0105
0106 template
0107 <
0108 typename Geometry,
0109 typename Tag = typename tag<Geometry>::type,
0110 bool HasFloatingPointCoordinates = std::is_floating_point
0111 <
0112 typename coordinate_type<Geometry>::type
0113 >::value
0114 >
0115 struct has_invalid_coordinate
0116 : range_has_invalid_coordinate
0117 {};
0118
0119 template <typename Geometry, typename Tag>
0120 struct has_invalid_coordinate<Geometry, Tag, false>
0121 : always_valid
0122 {};
0123
0124 template <typename Point>
0125 struct has_invalid_coordinate<Point, point_tag, true>
0126 : point_has_invalid_coordinate
0127 {};
0128
0129 template <typename Segment>
0130 struct has_invalid_coordinate<Segment, segment_tag, true>
0131 : indexed_has_invalid_coordinate
0132 {};
0133
0134 template <typename Box>
0135 struct has_invalid_coordinate<Box, box_tag, true>
0136 : indexed_has_invalid_coordinate
0137 {};
0138
0139
0140 }}
0141 #endif
0142
0143 }}
0144
0145 #endif