File: check_validity.hpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (101 lines) | stat: -rw-r--r-- 3,216 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Boost.Geometry

// Copyright (c) 2017 Barend Gehrels, Amsterdam, the Netherlands.

// This file was modified by Oracle on 2021.
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_GEOMETRY_TEST_CHECK_VALIDITY_HPP
#define BOOST_GEOMETRY_TEST_CHECK_VALIDITY_HPP

#include <boost/geometry/algorithms/is_valid.hpp>

template<typename Geometry>
inline bool is_input_valid(std::string const& case_id, std::string const& subcase,
                         Geometry const& geometry)
{
    std::string message;
    bool const result = bg::is_valid(geometry, message);
    if (! result)
    {
        std::cout << "WARNING: " << case_id << " Input [" << subcase
                  << "] is not considered as valid ("
                  << message << ") this can cause that output is invalid: "
                  << case_id << std::endl;
    }
    return result;
}


template<typename Geometry, typename G1, typename G2>
inline bool is_output_valid(Geometry const& geometry,
                            std::string const& case_id,
                            G1 const& g1, G2 const& g2,
                            bool ignore_validity_on_invalid_input,
                            std::string& message)
{
    bool result = bg::is_valid(geometry, message);
    if (! result && ignore_validity_on_invalid_input)
    {
        if (! is_input_valid(case_id, "a", g1)
            || ! is_input_valid(case_id, "b", g2))
        {
            // Because input is invalid, output validity is ignored
            result = true;
        }
    }
    return result;
}

template
<
    typename Geometry,
    typename Tag = typename bg::tag<Geometry>::type
>
struct check_validity
{
    template <typename G1, typename G2>
    static inline
    bool apply(Geometry const& geometry,
               std::string const& case_id,
               G1 const& g1, G2 const& g2,
               std::string& message,
               bool ignore_validity_on_invalid_input = true)
    {
        return is_output_valid(geometry, case_id, g1, g2,
                               ignore_validity_on_invalid_input, message);
    }
};

// Specialization for vector of <geometry> (e.g. rings)
template <typename Geometry>
struct check_validity<Geometry, void>
{
    template <typename G1, typename G2>
    static inline
    bool apply(Geometry const& geometry,
               std::string const& case_id,
               G1 const& g1, G2 const& g2,
               std::string& message,
               bool ignore_validity_on_invalid_input = true)
    {
        typedef typename boost::range_value<Geometry>::type single_type;
        for (single_type const& element : geometry)
        {
            if (! is_output_valid(element, case_id, g1, g2,
                                  ignore_validity_on_invalid_input, message))
            {
                return false;
            }
        }
        return true;
    }
};


#endif // BOOST_GEOMETRY_TEST_CHECK_VALIDITY_HPP