]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
3 | // Copyright (c) 2014-2015, 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_SEGMENT_HPP | |
12 | #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_SEGMENT_HPP | |
13 | ||
14 | #include <boost/core/ignore_unused.hpp> | |
15 | ||
16 | #include <boost/geometry/core/point_type.hpp> | |
17 | #include <boost/geometry/core/tags.hpp> | |
18 | ||
19 | #include <boost/geometry/algorithms/assign.hpp> | |
20 | #include <boost/geometry/algorithms/equals.hpp> | |
21 | #include <boost/geometry/algorithms/validity_failure_type.hpp> | |
22 | #include <boost/geometry/algorithms/detail/is_valid/has_invalid_coordinate.hpp> | |
23 | #include <boost/geometry/algorithms/dispatch/is_valid.hpp> | |
24 | ||
25 | ||
26 | namespace boost { namespace geometry | |
27 | { | |
28 | ||
29 | ||
30 | ||
31 | #ifndef DOXYGEN_NO_DISPATCH | |
32 | namespace dispatch | |
33 | { | |
34 | ||
35 | ||
36 | // A segment is a curve. | |
37 | // A curve is simple if it does not pass through the same point twice, | |
38 | // with the possible exception of its two endpoints | |
39 | // A curve is 1-dimensional, hence we have to check is the two | |
40 | // endpoints of the segment coincide, since in this case it is | |
41 | // 0-dimensional. | |
42 | // | |
43 | // Reference: OGC 06-103r4 (6.1.6.1) | |
44 | template <typename Segment> | |
45 | struct is_valid<Segment, segment_tag> | |
46 | { | |
47 | template <typename VisitPolicy> | |
48 | static inline bool apply(Segment const& segment, VisitPolicy& visitor) | |
49 | { | |
50 | boost::ignore_unused(visitor); | |
51 | ||
52 | typename point_type<Segment>::type p[2]; | |
53 | detail::assign_point_from_index<0>(segment, p[0]); | |
54 | detail::assign_point_from_index<1>(segment, p[1]); | |
55 | ||
56 | if (detail::is_valid::has_invalid_coordinate | |
57 | < | |
58 | Segment | |
59 | >::apply(segment, visitor)) | |
60 | { | |
61 | return false; | |
62 | } | |
63 | else if (! geometry::equals(p[0], p[1])) | |
64 | { | |
65 | return visitor.template apply<no_failure>(); | |
66 | } | |
67 | else | |
68 | { | |
69 | return | |
70 | visitor.template apply<failure_wrong_topological_dimension>(); | |
71 | } | |
72 | } | |
73 | }; | |
74 | ||
75 | ||
76 | } // namespace dispatch | |
77 | #endif // DOXYGEN_NO_DISPATCH | |
78 | ||
79 | ||
80 | }} // namespace boost::geometry | |
81 | ||
82 | ||
83 | #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_SEGMENT_HPP |