[test][simplify] Add tests for different input and output geometries.

This commit is contained in:
Adam Wulkiewicz 2022-06-25 00:38:47 +02:00
parent 6a6dba760a
commit a9364a1a88

View File

@ -17,11 +17,12 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <iterator>
#include <vector>
#include <algorithms/test_simplify.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/register/ring.hpp>
#include <test_geometries/wrapped_boost_array.hpp>
#include <test_common/test_point.hpp>
@ -308,6 +309,44 @@ void test_spherical()
}
template <typename P>
struct ring : std::vector<P>
{
ring(std::initializer_list<P> l)
: std::vector<P>(l)
{}
};
BOOST_GEOMETRY_REGISTER_RING_TEMPLATED(ring)
void test_different_types()
{
using point_t = bg::model::d2::point_xy<double>;
using ring_t = ::ring<point_t>;
using bg_ring_t = bg::model::ring<point_t>;
ring_t ring{{0, 0}, {10, 1}, {20, 2}, {30, 0}, {0, 0}};
bg_ring_t result;
bg::simplify(ring, result, 0.1);
BOOST_CHECK(boost::size(result) == 4);
BOOST_CHECK_CLOSE(bg::area(result), 30.0, 0.00001);
using var_t = boost::variant<point_t, ring_t>;
using bg_var_t = boost::variant<point_t, bg_ring_t>;
var_t var = ring;
bg_var_t result_var;
bg::simplify(var, result_var, 0.1);
BOOST_CHECK(bg::num_points(result_var) == 4);
BOOST_CHECK_CLOSE(bg::area(result_var), 30.0, 0.00001);
using gc_t = bg::model::geometry_collection<var_t>;
using bg_gc_t = bg::model::geometry_collection<bg_var_t>;
gc_t gc = {var};
bg_gc_t result_gc;
bg::simplify(gc, result_gc, 0.1);
BOOST_CHECK(bg::num_points(result_gc) == 4);
BOOST_CHECK_CLOSE(bg::area(result_gc), 30.0, 0.00001);
}
int test_main(int, char* [])
{
// Integer compiles, but simplify-process fails (due to distances)
@ -319,14 +358,15 @@ int test_main(int, char* [])
test_all<bg::model::d2::point_xy<float> >();
#endif
test_3d<bg::model::point<double, 3, bg::cs::cartesian> >();
test_spherical<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
test_zigzag<bg::model::d2::point_xy<double> >();
#endif
test_different_types();
return 0;
}