[test][is_simple] Add test for geographic CS.

This commit is contained in:
Adam Wulkiewicz 2017-07-27 03:40:21 +02:00
parent e7463b35f0
commit ea8c93478f
4 changed files with 182 additions and 95 deletions

View File

@ -33,6 +33,7 @@ test-suite boost-geometry-algorithms
[ run is_convex.cpp : : : : algorithms_is_convex ]
[ run is_empty.cpp : : : : algorithms_is_empty ]
[ run is_simple.cpp : : : : algorithms_is_simple ]
[ run is_simple_geo.cpp : : : : algorithms_is_simple_geo ]
[ run is_valid.cpp : : : : algorithms_is_valid ]
[ run is_valid_failure.cpp : : : : algorithms_is_valid_failure ]
[ run make.cpp : : : : algorithms_make ]

View File

@ -13,36 +13,7 @@
#define BOOST_TEST_MODULE test_is_simple
#endif
#include <iostream>
#include <string>
#include <boost/assert.hpp>
#include <boost/variant/variant.hpp>
#include <boost/test/included/unit_test.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/segment.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/multi_point.hpp>
#include <boost/geometry/geometries/multi_linestring.hpp>
#include <boost/geometry/geometries/multi_polygon.hpp>
#include <boost/geometry/strategies/strategies.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/geometry/algorithms/is_valid.hpp>
#include <boost/geometry/algorithms/is_simple.hpp>
#include <from_wkt.hpp>
#ifdef BOOST_GEOMETRY_TEST_DEBUG
#include "pretty_print_geometry.hpp"
#endif
#include "test_is_simple.hpp"
namespace bg = ::boost::geometry;
@ -61,71 +32,6 @@ typedef bg::model::multi_polygon<open_ccw_polygon_type> multi_polygon_type;
typedef bg::model::box<point_type> box_type;
//----------------------------------------------------------------------------
template <typename CSTag, typename Geometry>
void test_simple(Geometry const& geometry, bool expected_result,
bool check_validity = true)
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
std::cout << "=======" << std::endl;
#endif
bool simple = bg::is_simple(geometry);
BOOST_ASSERT( ! check_validity || bg::is_valid(geometry) );
BOOST_CHECK_MESSAGE( simple == expected_result,
"Expected: " << expected_result
<< " detected: " << simple
<< " wkt: " << bg::wkt(geometry) );
typedef typename bg::strategy::intersection::services::default_strategy
<
CSTag
>::type strategy_type;
bool simple_s = bg::is_simple(geometry, strategy_type());
BOOST_CHECK_EQUAL(simple, simple_s);
#ifdef BOOST_GEOMETRY_TEST_DEBUG
std::cout << "Geometry: ";
pretty_print_geometry<Geometry>::apply(std::cout, geometry);
std::cout << std::endl;
std::cout << std::boolalpha;
std::cout << "is simple: " << simple << std::endl;
std::cout << "expected result: " << expected_result << std::endl;
std::cout << "=======" << std::endl;
std::cout << std::endl << std::endl;
std::cout << std::noboolalpha;
#endif
}
template <typename Geometry>
void test_simple(Geometry const& geometry,
bool expected_result,
bool check_validity = true)
{
typedef typename bg::cs_tag<Geometry>::type cs_tag;
test_simple<cs_tag>(geometry, expected_result, check_validity);
}
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
void test_simple(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& variant_geometry,
bool expected_result,
bool check_validity = true)
{
typedef typename bg::cs_tag<T0>::type cs_tag;
test_simple<cs_tag>(variant_geometry, expected_result, check_validity);
}
//----------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE( test_is_simple_point )
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG

View File

@ -0,0 +1,59 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2014-2017, Oracle and/or its affiliates.
// 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
#ifndef BOOST_TEST_MODULE
#define BOOST_TEST_MODULE test_is_simple_geo
#endif
#include "test_is_simple.hpp"
typedef bg::model::point<double, 2, bg::cs::geographic<bg::degree> > point_type;
typedef bg::model::segment<point_type> segment_type;
typedef bg::model::linestring<point_type> linestring_type;
typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
// ccw open and closed polygons
typedef bg::model::polygon<point_type,false,false> open_ccw_polygon_type;
typedef bg::model::polygon<point_type,false,true> closed_ccw_polygon_type;
// multi-geometries
typedef bg::model::multi_point<point_type> multi_point_type;
typedef bg::model::multi_polygon<open_ccw_polygon_type> multi_polygon_type;
// box
typedef bg::model::box<point_type> box_type;
BOOST_AUTO_TEST_CASE( test_is_simple_geo_linestring )
{
typedef linestring_type G;
bg::strategy::intersection::geographic_segments<> s;
test_simple_s(from_wkt<G>("LINESTRING(0 0, -90 0, 90 0)"), s, true);
test_simple_s(from_wkt<G>("LINESTRING(0 90, -90 0, 90 0)"), s, false);
test_simple_s(from_wkt<G>("LINESTRING(0 90, -90 50, 90 0)"), s, false);
test_simple_s(from_wkt<G>("LINESTRING(0 90, -90 -50, 90 0)"), s, true);
test_simple_s(from_wkt<G>("LINESTRING(35 0, 110 36, 159 0, 82 30)"), s, false);
test_simple_s(from_wkt<G>("LINESTRING(135 0, -150 36, -101 0, -178 30)"), s, false);
test_simple_s(from_wkt<G>("LINESTRING(45 0, 120 36, 169 0, 92 30)"), s, false);
test_simple_s(from_wkt<G>("LINESTRING(179 0, -179 1, -179 0, 179 1)"), s, false);
}
BOOST_AUTO_TEST_CASE( test_is_simple_geo_multilinestring )
{
typedef multi_linestring_type G;
bg::strategy::intersection::geographic_segments<> s;
test_simple_s(from_wkt<G>("MULTILINESTRING((35 0, 110 36),(159 0, 82 30))"), s, false);
test_simple_s(from_wkt<G>("MULTILINESTRING((135 0, -150 36),(-101 0, -178 30))"), s, false);
test_simple_s(from_wkt<G>("MULTILINESTRING((45 0, 120 36),(169 0, 92 30))"), s, false);
test_simple_s(from_wkt<G>("MULTILINESTRING((179 0, -179 1),(-179 0, 179 1))"), s, false);
}

View File

@ -0,0 +1,121 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2014-2017, 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
#include <iostream>
#include <string>
#include <boost/assert.hpp>
#include <boost/variant/variant.hpp>
#include <boost/test/included/unit_test.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/segment.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/multi_point.hpp>
#include <boost/geometry/geometries/multi_linestring.hpp>
#include <boost/geometry/geometries/multi_polygon.hpp>
#include <boost/geometry/strategies/strategies.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/geometry/algorithms/is_valid.hpp>
#include <boost/geometry/algorithms/is_simple.hpp>
#include <from_wkt.hpp>
#ifdef BOOST_GEOMETRY_TEST_DEBUG
#include "pretty_print_geometry.hpp"
#endif
namespace bg = ::boost::geometry;
template <typename Geometry, typename Strategy>
void test_simple_s(Geometry const& geometry,
Strategy const& strategy,
bool expected_result,
bool check_validity = true)
{
bool simple = bg::is_simple(geometry, strategy);
bool valid = ! check_validity || bg::is_valid(geometry, strategy);
BOOST_CHECK_MESSAGE( valid == true,
"Expected valid geometry, "
<< " wkt: " << bg::wkt(geometry) );
BOOST_CHECK_MESSAGE( simple == expected_result,
"Expected: " << expected_result
<< " detected: " << simple
<< " wkt: " << bg::wkt(geometry) );
}
template <typename CSTag, typename Geometry>
void test_simple(Geometry const& geometry, bool expected_result,
bool check_validity = true)
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
std::cout << "=======" << std::endl;
#endif
bool simple = bg::is_simple(geometry);
bool valid = ! check_validity || bg::is_valid(geometry);
BOOST_CHECK_MESSAGE( valid == true,
"Expected valid geometry, "
<< " wkt: " << bg::wkt(geometry) );
BOOST_CHECK_MESSAGE( simple == expected_result,
"Expected: " << expected_result
<< " detected: " << simple
<< " wkt: " << bg::wkt(geometry) );
typedef typename bg::strategy::intersection::services::default_strategy
<
CSTag
>::type strategy_type;
test_simple_s(geometry, strategy_type(), expected_result, check_validity);
#ifdef BOOST_GEOMETRY_TEST_DEBUG
std::cout << "Geometry: ";
pretty_print_geometry<Geometry>::apply(std::cout, geometry);
std::cout << std::endl;
std::cout << std::boolalpha;
std::cout << "is simple: " << simple << std::endl;
std::cout << "expected result: " << expected_result << std::endl;
std::cout << "=======" << std::endl;
std::cout << std::endl << std::endl;
std::cout << std::noboolalpha;
#endif
}
template <typename Geometry>
void test_simple(Geometry const& geometry,
bool expected_result,
bool check_validity = true)
{
typedef typename bg::cs_tag<Geometry>::type cs_tag;
test_simple<cs_tag>(geometry, expected_result, check_validity);
}
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
void test_simple(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& variant_geometry,
bool expected_result,
bool check_validity = true)
{
typedef typename bg::cs_tag<T0>::type cs_tag;
test_simple<cs_tag>(variant_geometry, expected_result, check_validity);
}