1 | // Boost.Geometry |
2 | |
3 | // Copyright (c) 2017 Barend Gehrels, Amsterdam, the Netherlands. |
4 | |
5 | // This file was modified by Oracle on 2021. |
6 | // Modifications copyright (c) 2021, Oracle and/or its affiliates. |
7 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle |
8 | |
9 | // Use, modification and distribution is subject to the Boost Software License, |
10 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
11 | // http://www.boost.org/LICENSE_1_0.txt) |
12 | |
13 | #ifndef BOOST_GEOMETRY_TEST_CHECK_VALIDITY_HPP |
14 | #define BOOST_GEOMETRY_TEST_CHECK_VALIDITY_HPP |
15 | |
16 | #include <boost/geometry/algorithms/is_valid.hpp> |
17 | |
18 | template<typename Geometry> |
19 | inline bool input_is_valid(std::string const& case_id, std::string const& subcase, |
20 | Geometry const& geometry) |
21 | { |
22 | std::string message; |
23 | bool const result = bg::is_valid(geometry, message); |
24 | if (! result) |
25 | { |
26 | std::cout << "WARNING: " << case_id << " Input [" << subcase |
27 | << "] is not considered as valid (" |
28 | << message << ") this can cause that output is invalid: " |
29 | << case_id << std::endl; |
30 | } |
31 | return result; |
32 | } |
33 | |
34 | |
35 | template<typename Geometry, typename G1, typename G2> |
36 | inline bool is_output_valid(Geometry const& geometry, |
37 | std::string const& case_id, |
38 | G1 const& g1, G2 const& g2, |
39 | bool ignore_validity_on_invalid_input, |
40 | std::string& message) |
41 | { |
42 | bool result = bg::is_valid(geometry, message); |
43 | if (! result && ignore_validity_on_invalid_input) |
44 | { |
45 | if (! input_is_valid(case_id, "a" , g1) |
46 | || ! input_is_valid(case_id, "b" , g2)) |
47 | { |
48 | // Because input is invalid, output validity is ignored |
49 | result = true; |
50 | } |
51 | } |
52 | return result; |
53 | } |
54 | |
55 | template |
56 | < |
57 | typename Geometry, |
58 | typename Tag = typename bg::tag<Geometry>::type |
59 | > |
60 | struct check_validity |
61 | { |
62 | template <typename G1, typename G2> |
63 | static inline |
64 | bool apply(Geometry const& geometry, |
65 | std::string const& case_id, |
66 | G1 const& g1, G2 const& g2, |
67 | std::string& message, |
68 | bool ignore_validity_on_invalid_input = true) |
69 | { |
70 | return is_output_valid(geometry, case_id, g1, g2, |
71 | ignore_validity_on_invalid_input, message); |
72 | } |
73 | }; |
74 | |
75 | // Specialization for vector of <geometry> (e.g. rings) |
76 | template <typename Geometry> |
77 | struct check_validity<Geometry, void> |
78 | { |
79 | template <typename G1, typename G2> |
80 | static inline |
81 | bool apply(Geometry const& geometry, |
82 | std::string const& case_id, |
83 | G1 const& g1, G2 const& g2, |
84 | std::string& message, |
85 | bool ignore_validity_on_invalid_input = true) |
86 | { |
87 | typedef typename boost::range_value<Geometry>::type single_type; |
88 | for (single_type const& element : geometry) |
89 | { |
90 | if (! is_output_valid(element, case_id, g1, g2, |
91 | ignore_validity_on_invalid_input, message)) |
92 | { |
93 | return false; |
94 | } |
95 | } |
96 | return true; |
97 | } |
98 | }; |
99 | |
100 | |
101 | #endif // BOOST_GEOMETRY_TEST_CHECK_VALIDITY_HPP |
102 | |