Imported Upstream version 1.64.0
[platform/upstream/boost.git] / boost / geometry / algorithms / detail / is_valid / pointlike.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2014-2017, Oracle and/or its affiliates.
4
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
10
11 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_POINTLIKE_HPP
12 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_POINTLIKE_HPP
13
14 #include <boost/core/ignore_unused.hpp>
15 #include <boost/range.hpp>
16
17 #include <boost/geometry/core/tags.hpp>
18
19 #include <boost/geometry/algorithms/validity_failure_type.hpp>
20 #include <boost/geometry/algorithms/detail/is_valid/has_invalid_coordinate.hpp>
21 #include <boost/geometry/algorithms/dispatch/is_valid.hpp>
22
23 #include <boost/geometry/util/condition.hpp>
24
25
26 namespace boost { namespace geometry
27 {
28
29
30
31 #ifndef DOXYGEN_NO_DISPATCH
32 namespace dispatch
33 {
34
35 // A point is always simple
36 template <typename Point>
37 struct is_valid<Point, point_tag>
38 {
39     template <typename VisitPolicy, typename Strategy>
40     static inline bool apply(Point const& point, VisitPolicy& visitor, Strategy const&)
41     {
42         boost::ignore_unused(visitor);
43         return ! detail::is_valid::has_invalid_coordinate
44             <
45                 Point
46             >::apply(point, visitor);
47     }
48 };
49
50
51
52 // A MultiPoint is simple if no two Points in the MultiPoint are equal
53 // (have identical coordinate values in X and Y)
54 //
55 // Reference: OGC 06-103r4 (6.1.5)
56 template <typename MultiPoint, bool AllowEmptyMultiGeometries>
57 struct is_valid<MultiPoint, multi_point_tag, AllowEmptyMultiGeometries>
58 {
59     template <typename VisitPolicy, typename Strategy>
60     static inline bool apply(MultiPoint const& multipoint,
61                              VisitPolicy& visitor,
62                              Strategy const&)
63     {
64         boost::ignore_unused(multipoint, visitor);
65
66         if (BOOST_GEOMETRY_CONDITION(
67                 AllowEmptyMultiGeometries || !boost::empty(multipoint)))
68         {
69             // we allow empty multi-geometries, so an empty multipoint
70             // is considered valid
71             return ! detail::is_valid::has_invalid_coordinate
72                 <
73                     MultiPoint
74                 >::apply(multipoint, visitor);
75         }
76         else
77         {
78             // we do not allow an empty multipoint
79             return visitor.template apply<failure_few_points>();
80         }
81     }
82 };
83
84
85 } // namespace dispatch
86 #endif // DOXYGEN_NO_DISPATCH
87
88
89 }} // namespace boost::geometry
90
91
92 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_POINTLIKE_HPP