[test][formulas] Add test case (issue 612).

This commit is contained in:
Adam Wulkiewicz 2019-09-20 00:57:21 +02:00
parent 06a5435917
commit a03155b46d
2 changed files with 51 additions and 28 deletions

View File

@ -1,7 +1,7 @@
// Boost.Geometry
// Unit Test
// Copyright (c) 2016-2018 Oracle and/or its affiliates.
// Copyright (c) 2016-2019 Oracle and/or its affiliates.
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
@ -171,6 +171,20 @@ void test_all(expected_results const& results)
#endif
}
void test_bugs()
{
// https://github.com/boostorg/geometry/issues/612
{
double lon, lat;
bg::formula::sjoberg_intersection<double, bg::formula::andoyer_inverse, 1>
::apply(-0.0872665, -0.0872665, -0.0872665, 0.0872665,
0.0, 1.57e-07, -0.392699, 1.57e-07,
lon, lat, bg::srs::spheroid<double>());
check_one("issue 612", lon, -0.087266500535674751);
check_one("issue 612", lat, 1.5892499139622920e-07);
}
}
int test_main(int, char*[])
{
for (size_t i = 0; i < expected_size; ++i)
@ -178,5 +192,7 @@ int test_main(int, char*[])
test_all(expected[i]);
}
test_bugs();
return 0;
}

View File

@ -1,7 +1,7 @@
// Boost.Geometry
// Unit Test
// Copyright (c) 2016-2017 Oracle and/or its affiliates.
// Copyright (c) 2016-2019 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
@ -29,6 +29,38 @@ void normalize_deg(double & deg)
::boost::test_tools::check_is_close_t(), M, CHECK, CHECK_MSG, (L)(R)(::boost::math::fpc::percent_tolerance(T)) )
void check_one(std::string const& name, double result, double expected)
{
std::string id = name.empty() ? "" : (name + " : ");
double eps = std::numeric_limits<double>::epsilon();
double abs_result = bg::math::abs(result);
double abs_expected = bg::math::abs(expected);
double res_max = (std::max)(abs_result, abs_expected);
double res_min = (std::min)(abs_result, abs_expected);
if (res_min <= eps) // including 0
{
bool is_close = abs_result <= 30 * eps && abs_expected <= 30 * eps;
BOOST_CHECK_MESSAGE((is_close),
id << std::setprecision(20) << "result {" << result << "} different than expected {" << expected << "}.");
}
else if (res_max > 100 * eps)
{
BOOST_GEOMETRY_CHECK_CLOSE(result, expected, 0.1,
id << std::setprecision(20) << "result {" << result << "} different than expected {" << expected << "}.");
}
else if (res_max > 10 * eps)
{
BOOST_GEOMETRY_CHECK_CLOSE(result, expected, 10,
id << std::setprecision(20) << "result {" << result << "} different than expected {" << expected << "}.");
}
else if (res_max > eps)
{
BOOST_GEOMETRY_CHECK_CLOSE(result, expected, 1000,
id << std::setprecision(20) << "result {" << result << "} different than expected {" << expected << "}.");
}
}
void check_one(std::string const& name,
double result, double expected, double reference, double reference_error,
bool normalize = false, bool check_reference_only = false)
@ -44,32 +76,7 @@ void check_one(std::string const& name,
if (! check_reference_only)
{
double eps = std::numeric_limits<double>::epsilon();
double abs_result = bg::math::abs(result);
double abs_expected = bg::math::abs(expected);
double res_max = (std::max)(abs_result, abs_expected);
double res_min = (std::min)(abs_result, abs_expected);
if (res_min <= eps) // including 0
{
bool is_close = abs_result <= 30 * eps && abs_expected <= 30 * eps;
BOOST_CHECK_MESSAGE((is_close),
id << std::setprecision(20) << "result {" << result << "} different than expected {" << expected << "}.");
}
else if (res_max > 100 * eps)
{
BOOST_GEOMETRY_CHECK_CLOSE(result, expected, 0.1,
id << std::setprecision(20) << "result {" << result << "} different than expected {" << expected << "}.");
}
else if (res_max > 10 * eps)
{
BOOST_GEOMETRY_CHECK_CLOSE(result, expected, 10,
id << std::setprecision(20) << "result {" << result << "} different than expected {" << expected << "}.");
}
else if (res_max > eps)
{
BOOST_GEOMETRY_CHECK_CLOSE(result, expected, 1000,
id << std::setprecision(20) << "result {" << result << "} different than expected {" << expected << "}.");
}
check_one(name, result, expected);
}
// NOTE: in some cases it probably will be necessary to normalize