[test] Add DG/GC tests for various algorithms.

This commit is contained in:
Adam Wulkiewicz 2021-10-03 18:06:56 +02:00
parent 47119631f0
commit 90bbacf5e0
8 changed files with 170 additions and 15 deletions

View File

@ -1,7 +1,7 @@
// Boost.Geometry
// Unit Test
// Copyright (c) 2017-2018, Oracle and/or its affiliates.
// Copyright (c) 2017-2021, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
@ -9,6 +9,8 @@
// http://www.boost.org/users/license.html
#include <boost/variant/variant.hpp>
#include <geometry_test_common.hpp>
#include <boost/geometry/geometries/geometries.hpp>
@ -159,6 +161,17 @@ inline void test_geometry(std::string const& wkt, Check const& check)
bg::densify(g, o, max_distance);
check_result(g, o, max_distance, def_s, check);
using variant_t = boost::variant<G, typename bg::point_type<G>::type>;
variant_t v = g, vo;
bg::densify(v, vo, max_distance);
check(v, vo, def_s);
bg::model::geometry_collection<variant_t> gc{v}, gco;
bg::densify(gc, gco, max_distance);
check(gc, gco, def_s);
}
{

View File

@ -21,6 +21,7 @@
#include <boost/geometry/algorithms/envelope.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/geometry_collection.hpp>
#include <boost/geometry/strategies/strategies.hpp>
#include <boost/geometry/io/wkt/read.hpp>
@ -97,6 +98,10 @@ void test_envelope(std::string const& wkt,
check_result<box_type, bg::dimension<Geometry>::type::value>
::apply(b, x1, y1, z1, x2, y2, z2);
bg::model::geometry_collection<boost::variant<Geometry>> gc{v};
bg::envelope(gc, b);
check_result<box_type, bg::dimension<Geometry>::type::value>
::apply(b, x1, y1, z1, x2, y2, z2);
}

View File

@ -1,7 +1,7 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2014-2018, Oracle and/or its affiliates.
// Copyright (c) 2014-2021, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
@ -27,6 +27,8 @@
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/geometry/algorithms/reverse.hpp>
#include <boost/geometry/geometries/geometry_collection.hpp>
BOOST_AUTO_TEST_CASE( test_is_valid_point )
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
@ -1414,3 +1416,40 @@ BOOST_AUTO_TEST_CASE( test_is_valid_variant )
vg = invalid_polygon;
test::apply("v04", vg, false);
}
BOOST_AUTO_TEST_CASE( test_is_valid_geometry_collection )
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
std::cout << std::endl << std::endl;
std::cout << "************************************" << std::endl;
std::cout << " is_valid: geometry collection" << std::endl;
std::cout << "************************************" << std::endl;
#endif
using polygon_type = bg::model::polygon<point_type>; // cw, closed
using variant_type = boost::variant
<
linestring_type, multi_linestring_type, polygon_type
>;
using gc_type = bg::model::geometry_collection<variant_type>;
typedef test_valid_variant<gc_type> test;
gc_type gc;
linestring_type valid_linestring =
from_wkt<linestring_type>("LINESTRING(0 0,1 0)");
multi_linestring_type invalid_multi_linestring =
from_wkt<multi_linestring_type>("MULTILINESTRING((0 0,1 0),(0 0))");
polygon_type valid_polygon =
from_wkt<polygon_type>("POLYGON((0 0,1 1,1 0,0 0))");
polygon_type invalid_polygon =
from_wkt<polygon_type>("POLYGON((0 0,2 2,2 0,1 0))");
gc = {valid_linestring, valid_polygon};
test::apply("gc01", gc, true);
gc = {invalid_multi_linestring, valid_polygon};
test::apply("gc02", gc, false);
gc = {valid_linestring, invalid_polygon};
test::apply("gc03", gc, false);
}

View File

@ -6,6 +6,10 @@
// Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
// Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
// 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)
@ -67,6 +71,12 @@ int test_main(int, char* [])
typedef bg::model::polygon<point, true, false> open_polygon;
typedef bg::model::multi_polygon<open_polygon> open_multi_polygon;
using variant = boost::variant<linestring, polygon>;
using open_variant = boost::variant<linestring, open_polygon>;
using geometry_collection = bg::model::geometry_collection<variant>;
using open_geometry_collection = bg::model::geometry_collection<open_variant>;
test_num_points<point>("POINT(0 0)", 1u);
test_num_points<linestring>("LINESTRING(0 0,1 1)", 2u);
test_num_points<segment>("LINESTRING(0 0,1 1)", 2u);
@ -89,6 +99,12 @@ int test_main(int, char* [])
test_num_points<open_multi_polygon>("MULTIPOLYGON(((0 0,0 10,10 10,10 0)),((0 10,1 10,1 9)))", 7u, 9u);
test_num_points<open_multi_polygon>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 10,1 10,1 9,0 10)))", 7u, 9u);
test_num_points<variant>("POLYGON((0 0,1 1,0 1,0 0))", 4u);
test_num_points<open_variant>("POLYGON((0 0,1 1,0 1))", 3u, 4u);
test_num_points<geometry_collection>("GEOMETRYCOLLECTION(POLYGON((0 0,1 1,0 1,0 0)),LINESTRING(0 0,1 1))", 6u);
test_num_points<open_geometry_collection>("GEOMETRYCOLLECTION(POLYGON((0 0,1 1,0 1)),LINESTRING(0 0,1 1))", 5u, 6u);
return 0;
}

View File

@ -1,9 +1,10 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2014, Oracle and/or its affiliates.
// Copyright (c) 2014-2021, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
@ -289,3 +290,16 @@ BOOST_AUTO_TEST_CASE( test_variant )
variant_geometry = p_closed;
tester::apply(variant_geometry, 4);
}
BOOST_AUTO_TEST_CASE( test_geometry_collection )
{
using variant = boost::variant<linestring, polygon_cw_closed>;
using geometry_collection = bg::model::geometry_collection<variant>;
using tester = test_num_segments<geometry_collection>;
geometry_collection gc;
bg::read_wkt("GEOMETRYCOLLECTION(LINESTRING(0 0,1 1,2 2),POLYGON((0 0,0 1,1 1,1 0,0 0)))", gc);
tester::apply(gc, 6);
}

View File

@ -5,6 +5,10 @@
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
// 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
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
@ -222,6 +226,18 @@ void test_all()
"POINT(0 0)",
"POINT(0 0)", 1.0);
test_geometry<bg::model::segment<P> >(
"SEGMENT(0 0, 1 1)",
"SEGMENT(0 0, 1 1)", 1.0);
test_geometry<bg::model::box<P> >(
"BOX(0 0, 1 1)",
"BOX(0 0, 1 1)", 1.0);
test_geometry<bg::model::multi_point<P> >(
"MULTIPOINT(0 0, 1 1, 2 2)",
"MULTIPOINT(0 0, 1 1, 2 2)", 1.0);
// RING: check compilation and behaviour
test_geometry<bg::model::ring<P> >(

View File

@ -2,6 +2,11 @@
// Unit Test
// Copyright (c) 2007-2012 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)
@ -15,6 +20,7 @@
#include <geometry_test_common.hpp>
#include <boost/geometry/algorithms/perimeter.hpp>
#include <boost/geometry/geometries/geometry_collection.hpp>
#include <boost/geometry/strategies/strategies.hpp>
#include <boost/geometry/io/wkt/read.hpp>
@ -37,6 +43,16 @@ void test_perimeter(Geometry const& geometry, long double expected_perimeter)
#endif
BOOST_CHECK_CLOSE(perimeter, expected_perimeter, 0.0001);
boost::variant<Geometry> v(geometry);
perimeter = bg::perimeter(v);
BOOST_CHECK_CLOSE(perimeter, expected_perimeter, 0.0001);
bg::model::geometry_collection<boost::variant<Geometry>> gc{v};
perimeter = bg::perimeter(gc);
BOOST_CHECK_CLOSE(perimeter, expected_perimeter, 0.0001);
}
@ -58,6 +74,16 @@ void test_perimeter(Geometry const& geometry, long double expected_perimeter, St
#endif
BOOST_CHECK_CLOSE(perimeter, expected_perimeter, 0.0001);
boost::variant<Geometry> v(geometry);
perimeter = bg::perimeter(v, strategy);
BOOST_CHECK_CLOSE(perimeter, expected_perimeter, 0.0001);
bg::model::geometry_collection<boost::variant<Geometry>> gc{v};
perimeter = bg::perimeter(gc, strategy);
BOOST_CHECK_CLOSE(perimeter, expected_perimeter, 0.0001);
}
template <typename Geometry>
@ -65,12 +91,7 @@ void test_geometry(std::string const& wkt, double expected_perimeter)
{
Geometry geometry;
bg::read_wkt(wkt, geometry);
boost::variant<Geometry> v(geometry);
test_perimeter(geometry, expected_perimeter);
#if !defined(BOOST_GEOMETRY_TEST_DEBUG)
test_perimeter(v, expected_perimeter);
#endif
}
template <typename Geometry, typename Strategy>

View File

@ -2,6 +2,11 @@
// Unit Test
// Copyright (c) 2007-2012 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)
@ -18,11 +23,24 @@
#include <boost/geometry/algorithms/equals.hpp>
#include <boost/geometry/algorithms/simplify.hpp>
#include <boost/geometry/algorithms/distance.hpp>
#include <boost/geometry/geometries/geometry_collection.hpp>
#include <boost/geometry/strategies/strategies.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>
#include <boost/variant/variant.hpp>
template <typename Geometry, typename Tag = typename bg::tag<Geometry>::type>
struct boost_variant_type
{
using type = boost::variant<Geometry, typename bg::point_type<Geometry>::type>;
};
template <typename Geometry>
struct boost_variant_type<Geometry, bg::point_tag>
{
using type = boost::variant<Geometry>;
};
template
<
typename GeometryForTag,
@ -158,8 +176,9 @@ void test_geometry(std::string const& wkt,
bg::read_wkt(wkt, geometry);
bg::read_wkt(expected_wkt, expected);
boost::variant<Geometry> v(geometry);
using variant_t = typename boost_variant_type<Geometry>::type;
variant_t v(geometry);
// Define default strategy for testing
typedef bg::strategy::simplify::douglas_peucker
<
@ -167,15 +186,27 @@ void test_geometry(std::string const& wkt,
bg::strategy::distance::projected_point<double>
> dp;
BOOST_CONCEPT_ASSERT((bg::concepts::SimplifyStrategy<dp, point_type>));
check_geometry(geometry, expected, distance);
check_geometry(v, expected, distance);
BOOST_CONCEPT_ASSERT( (bg::concepts::SimplifyStrategy<dp, point_type>) );
check_geometry(geometry, expected, distance, dp());
check_geometry(v, expected, distance, dp());
// For now check GC here because it's not supported by equals()
{
using gc_t = bg::model::geometry_collection<variant_t>;
gc_t gc{v};
gc_t gc_simplified;
bg::simplify(gc, gc_simplified, distance);
bg::detail::visit_breadth_first([&](auto const& g)
{
test_equality<Geometry>::apply(g, expected);
return false;
}, gc_simplified);
}
// Check inserter (if applicable)
test_inserter
<
@ -217,7 +248,7 @@ void test_geometry(std::string const& wkt,
bg::correct_closure(geometry);
bg::correct_closure(expected);
boost::variant<Geometry> v(geometry);
typename boost_variant_type<Geometry>::type v(geometry);
BOOST_CONCEPT_ASSERT( (bg::concepts::SimplifyStrategy<Strategy,
typename bg::point_type<Geometry>::type>) );