]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/formulas/test_formula.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / geometry / test / formulas / test_formula.hpp
1 // Boost.Geometry
2 // Unit Test
3
4 // Copyright (c) 2016-2017 Oracle and/or its affiliates.
5
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7
8 // Use, modification and distribution is subject to the Boost Software License,
9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
11
12 #ifndef BOOST_GEOMETRY_TEST_FORMULA_HPP
13 #define BOOST_GEOMETRY_TEST_FORMULA_HPP
14
15 #include <geometry_test_common.hpp>
16
17 #include <boost/geometry/util/math.hpp>
18
19 void normalize_deg(double & deg)
20 {
21 while (deg > 180.0)
22 deg -= 360.0;
23 while (deg <= -180.0)
24 deg += 360.0;
25 }
26
27
28 #define BOOST_GEOMETRY_CHECK_CLOSE( L, R, T, M ) BOOST_TEST_TOOL_IMPL( 0, \
29 ::boost::test_tools::check_is_close_t(), M, CHECK, CHECK_MSG, (L)(R)(::boost::math::fpc::percent_tolerance(T)) )
30
31
32 void check_one(std::string const& name,
33 double result, double expected, double reference, double reference_error,
34 bool normalize = false, bool check_reference_only = false)
35 {
36 std::string id = name.empty() ? "" : (name + " : ");
37
38 if (normalize)
39 {
40 normalize_deg(result);
41 normalize_deg(expected);
42 normalize_deg(reference);
43 }
44
45 if (! check_reference_only)
46 {
47 double eps = std::numeric_limits<double>::epsilon();
48 double abs_result = bg::math::abs(result);
49 double abs_expected = bg::math::abs(expected);
50 double res_max = (std::max)(abs_result, abs_expected);
51 double res_min = (std::min)(abs_result, abs_expected);
52 if (res_min <= eps) // including 0
53 {
54 bool is_close = abs_result <= 30 * eps && abs_expected <= 30 * eps;
55 BOOST_CHECK_MESSAGE((is_close),
56 id << std::setprecision(20) << "result {" << result << "} different than expected {" << expected << "}.");
57 }
58 else if (res_max > 100 * eps)
59 {
60 BOOST_GEOMETRY_CHECK_CLOSE(result, expected, 0.1,
61 id << std::setprecision(20) << "result {" << result << "} different than expected {" << expected << "}.");
62 }
63 else if (res_max > 10 * eps)
64 {
65 BOOST_GEOMETRY_CHECK_CLOSE(result, expected, 10,
66 id << std::setprecision(20) << "result {" << result << "} different than expected {" << expected << "}.");
67 }
68 else if (res_max > eps)
69 {
70 BOOST_GEOMETRY_CHECK_CLOSE(result, expected, 1000,
71 id << std::setprecision(20) << "result {" << result << "} different than expected {" << expected << "}.");
72 }
73 }
74
75 // NOTE: in some cases it probably will be necessary to normalize
76 // the differences between the result and expected result
77 double ref_diff = bg::math::abs(result - reference);
78 double ref_max = (std::max)(bg::math::abs(result), bg::math::abs(reference));
79 bool is_ref_close = ref_diff <= reference_error || ref_diff <= reference_error * ref_max;
80 BOOST_CHECK_MESSAGE((is_ref_close),
81 id << std::setprecision(20) << "result {" << result << "} and reference {" << reference << "} not close enough.");
82 }
83
84 void check_one(double result, double expected, double reference, double reference_error,
85 bool normalize = false, bool check_reference_only = false)
86 {
87 check_one("", result, expected, reference, reference_error, normalize, check_reference_only);
88 }
89
90 #endif // BOOST_GEOMETRY_TEST_FORMULA_HPP