|
| 1 | +// Boost.Geometry (aka GGL, Generic Geometry Library) |
| 2 | +// Unit Test |
| 3 | + |
| 4 | +// Copyright (c) 2020 Tinko Bartels, Berlin, Germany. |
| 5 | + |
| 6 | +// Contributed and/or modified by Tinko Bartels, |
| 7 | +// as part of Google Summer of Code 2020 program. |
| 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 | +#include <array> |
| 14 | + |
| 15 | +#include <geometry_test_common.hpp> |
| 16 | + |
| 17 | +#include <boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/approximate.hpp> |
| 18 | +#include <boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/expression_tree.hpp> |
| 19 | + |
| 20 | +namespace p = boost::geometry::detail::generic_robust_predicates; |
| 21 | + |
| 22 | +template <typename CalculationType> |
| 23 | +void test_all() |
| 24 | +{ |
| 25 | + using ct = CalculationType; |
| 26 | + ct r1 = p::approximate_value<p::sum<p::_1, p::_2>, ct>( |
| 27 | + std::array<ct, 2>{1.0, 2.0}); |
| 28 | + BOOST_CHECK_EQUAL(3.0, r1); |
| 29 | + ct r2 = p::approximate_value<p::max<p::abs<p::_1>, p::abs<p::_2>>, ct>( |
| 30 | + std::array<ct, 2>{-10.0, 2.0}); |
| 31 | + BOOST_CHECK_EQUAL(10.0, r2); |
| 32 | + |
| 33 | + using expression = p::product |
| 34 | + < |
| 35 | + p::difference<p::_1, p::_2>, |
| 36 | + p::difference<p::_3, p::_4> |
| 37 | + >; |
| 38 | + using evals = p::post_order<expression>; |
| 39 | + std::array<ct, boost::mp11::mp_size<evals>::value> r; |
| 40 | + std::array<ct, 4> input {5.0, 3.0, 2.0, 8.0}; |
| 41 | + p::approximate_interim<evals, evals, ct>(r, input); |
| 42 | + ct r3 = p::get_approx<evals, typename expression::left, ct>(r, input); |
| 43 | + BOOST_CHECK_EQUAL(2.0, r3); |
| 44 | + ct r4 = p::get_approx<evals, typename expression::right, ct>(r, input); |
| 45 | + BOOST_CHECK_EQUAL(-6.0, r4); |
| 46 | + ct r5 = p::get_approx<evals, expression, ct>(r, input); |
| 47 | + BOOST_CHECK_EQUAL(-12.0, r5); |
| 48 | +} |
| 49 | + |
| 50 | + |
| 51 | +int test_main(int, char* []) |
| 52 | +{ |
| 53 | + test_all<double>(); |
| 54 | + return 0; |
| 55 | +} |
0 commit comments