mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-11 13:34:10 +00:00
[test][get_turns] Add spherical A/A test.
Replace explicitly specified Version of operations testing (linear v.s. areal) with overloaded function automatically picking the correct check.
This commit is contained in:
parent
5c53a86d86
commit
538a735718
@ -19,6 +19,7 @@ test-suite boost-geometry-algorithms-overlay
|
||||
[ run get_turn_info.cpp : : : : algorithms_get_turn_info ]
|
||||
[ run get_turns.cpp : : : : algorithms_get_turns ]
|
||||
[ run get_turns_areal_areal.cpp : : : : algorithms_get_turns_areal_areal ]
|
||||
[ run get_turns_areal_areal_sph.cpp : : : : algorithms_get_turns_areal_areal_sph ]
|
||||
[ run get_turns_linear_areal.cpp : : : : algorithms_get_turns_linear_areal ]
|
||||
[ run get_turns_linear_areal_sph.cpp : : : : algorithms_get_turns_linear_areal_sph ]
|
||||
[ run get_turns_linear_linear.cpp : : : : algorithms_get_turns_linear_linear ]
|
||||
|
@ -35,13 +35,13 @@ void test_all()
|
||||
// cw(duplicated point)
|
||||
test_geometry<poly, poly>("POLYGON((-8042 -1485,-8042 250,-8042 250,15943 254,15943 -1485,-8042 -1485))",
|
||||
"POLYGON((-7901 -1485,-7901 529,-7901 529, 15802 544, 15802 -1485, -7901 -1485))",
|
||||
expected_pusher<0>()("iiu")("iui")("mcc")("cui"));
|
||||
expected("iiu")("iui")("mcc")("cui"));
|
||||
//to_svg<poly, poly>("POLYGON((-8042 -1485,-8042 250,15943 254,15943 -1485,-8042 -1485))",
|
||||
// "POLYGON((-7901 -1485,-7901 529,15802 544, 15802 -1485, -7901 -1485))",
|
||||
// "poly_poly_1.svg");
|
||||
test_geometry<poly, poly>("POLYGON((-7901 -1485,-7901 529,-7901 529, 15802 544, 15802 -1485, -7901 -1485))",
|
||||
"POLYGON((-8042 -1485,-8042 250,-8042 250,15943 254,15943 -1485,-8042 -1485))",
|
||||
expected_pusher<0>()("iui")("iiu")("mcc")("ciu"));
|
||||
expected("iui")("iiu")("mcc")("ciu"));
|
||||
}
|
||||
}
|
||||
|
||||
|
53
test/algorithms/overlay/get_turns_areal_areal_sph.cpp
Normal file
53
test/algorithms/overlay/get_turns_areal_areal_sph.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
// Boost.Geometry
|
||||
// Unit Test
|
||||
|
||||
// Copyright (c) 2016, 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)
|
||||
|
||||
|
||||
#include "test_get_turns.hpp"
|
||||
#include <boost/geometry/geometries/geometries.hpp>
|
||||
|
||||
#include <algorithms/overlay/overlay_cases.hpp>
|
||||
|
||||
|
||||
template <typename T>
|
||||
void test_all()
|
||||
{
|
||||
typedef bg::model::point<T, 2, bg::cs::spherical_equatorial<bg::degree> > pt;
|
||||
//typedef bg::model::ring<pt> ring;
|
||||
typedef bg::model::polygon<pt> poly;
|
||||
//typedef bg::model::multi_polygon<poly> mpoly;
|
||||
|
||||
test_geometry<poly, poly>(case_1[0], case_1[1],
|
||||
expected("iiu")("iui")("iiu")("iui")("iiu")("iui"));
|
||||
|
||||
test_geometry<poly, poly>(case_2[0], case_2[1],
|
||||
expected("iui")("iiu")("iui")("iiu")("iui")("iiu")("iui")("iiu"));
|
||||
|
||||
#ifdef BOOST_GEOMETRY_ENABLE_FAILING
|
||||
test_geometry<poly, poly>(case_3_sph[0], case_3_sph[1],
|
||||
expected("miu")("miu")("miu")("miu"));
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
int test_main(int, char* [])
|
||||
{
|
||||
test_all<float>();
|
||||
test_all<double>();
|
||||
|
||||
//#if ! defined(_MSC_VER)
|
||||
// test_all<long double>();
|
||||
//#endif
|
||||
|
||||
//#if defined(HAVE_TTMATH)
|
||||
// test_all<ttmath_big>();
|
||||
//#endif
|
||||
return 0;
|
||||
}
|
@ -3,10 +3,11 @@
|
||||
//
|
||||
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
|
||||
// This file was modified by Oracle on 2015.
|
||||
// Modifications copyright (c) 2015, Oracle and/or its affiliates.
|
||||
// This file was modified by Oracle on 2015, 2016.
|
||||
// Modifications copyright (c) 2015-2016, 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
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software License,
|
||||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -41,6 +42,10 @@ static std::string case_3[2] = {
|
||||
"POLYGON((1 2,2 4,4 3,3 1,1 2))",
|
||||
"POLYGON((1 1,1 4,4 4,4 1,1 1))" };
|
||||
|
||||
static std::string case_3_sph[2] = {
|
||||
"POLYGON((1 2,2 4.0012148518458881,4 3,3 1.0002046405995848,1 2))",
|
||||
"POLYGON((1 1,1 4,4 4,4 1,1 1))" };
|
||||
|
||||
|
||||
static std::string case_4[2] = {
|
||||
"POLYGON((0 2,2 5,5 3,3 0,0 2))",
|
||||
|
@ -4,8 +4,8 @@
|
||||
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
|
||||
|
||||
// This file was modified by Oracle on 2014.
|
||||
// Modifications copyright (c) 2014 Oracle and/or its affiliates.
|
||||
// This file was modified by Oracle on 2014, 2016.
|
||||
// Modifications copyright (c) 2014-2016 Oracle and/or its affiliates.
|
||||
|
||||
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
||||
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
||||
@ -33,12 +33,13 @@
|
||||
#include <boost/geometry/io/wkt/read.hpp>
|
||||
#include <boost/geometry/io/wkt/write.hpp>
|
||||
|
||||
template <int Version = 0>
|
||||
struct expected_pusher
|
||||
{
|
||||
static const int version = Version;
|
||||
void push_back(std::string const& ex)
|
||||
{
|
||||
vec.push_back(ex);
|
||||
}
|
||||
|
||||
void push_back(std::string const& ex) { vec.push_back(ex); }
|
||||
expected_pusher & operator()(std::string const& ex)
|
||||
{
|
||||
push_back(ex);
|
||||
@ -56,13 +57,12 @@ struct expected_pusher
|
||||
std::vector<std::string> vec;
|
||||
};
|
||||
|
||||
expected_pusher<1> expected(std::string const& ex)
|
||||
inline expected_pusher expected(std::string const& ex)
|
||||
{
|
||||
expected_pusher<1> res;
|
||||
expected_pusher res;
|
||||
return res(ex);
|
||||
}
|
||||
|
||||
template <int Version>
|
||||
struct equal_turn
|
||||
{
|
||||
equal_turn(std::string const& s) : turn_ptr(&s) {}
|
||||
@ -70,43 +70,45 @@ struct equal_turn
|
||||
template <typename T>
|
||||
bool operator()(T const& t) const
|
||||
{
|
||||
BOOST_ASSERT(turn_ptr && turn_ptr->size() == 3);
|
||||
return bg::method_char(t.method) == (*turn_ptr)[0]
|
||||
&& bg::operation_char(t.operations[0].operation) == (*turn_ptr)[1]
|
||||
&& bg::operation_char(t.operations[1].operation) == (*turn_ptr)[2];
|
||||
std::string const& s = (*turn_ptr);
|
||||
std::string::size_type const count = s.size();
|
||||
|
||||
return (count > 0
|
||||
? bg::method_char(t.method) == s[0]
|
||||
: true)
|
||||
&& (count > 1
|
||||
? bg::operation_char(t.operations[0].operation) == s[1]
|
||||
: true)
|
||||
&& (count > 2
|
||||
? bg::operation_char(t.operations[1].operation) == s[2]
|
||||
: true)
|
||||
&& equal_operations_ex(t.operations[0], t.operations[1], s);
|
||||
}
|
||||
|
||||
const std::string * turn_ptr;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct equal_turn<1>
|
||||
{
|
||||
equal_turn(std::string const& s) : turn_ptr(&s) {}
|
||||
|
||||
template <typename T>
|
||||
bool operator()(T const& t) const
|
||||
template <typename P, typename R>
|
||||
static bool equal_operations_ex(bg::detail::overlay::turn_operation<P, R> const& op0,
|
||||
bg::detail::overlay::turn_operation<P, R> const& op1,
|
||||
std::string const& s)
|
||||
{
|
||||
std::string::size_type count = turn_ptr->size();
|
||||
//BOOST_ASSERT(turn_ptr && count >= 1);
|
||||
return ( count > 0
|
||||
? bg::method_char(t.method) == (*turn_ptr)[0]
|
||||
: true )
|
||||
&& ( count > 1
|
||||
? bg::operation_char(t.operations[0].operation) == (*turn_ptr)[1]
|
||||
: true )
|
||||
&& ( count > 2
|
||||
? bg::operation_char(t.operations[1].operation) == (*turn_ptr)[2]
|
||||
: true )
|
||||
&& ( count > 3
|
||||
? is_colinear_char(t.operations[0].is_collinear) == (*turn_ptr)[3]
|
||||
: true )
|
||||
&& ( count > 4
|
||||
? is_colinear_char(t.operations[1].is_collinear) == (*turn_ptr)[4]
|
||||
: true );
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline char is_colinear_char(bool is_collinear)
|
||||
template <typename P, typename R>
|
||||
static bool equal_operations_ex(bg::detail::overlay::turn_operation_linear<P, R> const& op0,
|
||||
bg::detail::overlay::turn_operation_linear<P, R> const& op1,
|
||||
std::string const& s)
|
||||
{
|
||||
std::string::size_type const count = s.size();
|
||||
|
||||
return (count > 3
|
||||
? is_colinear_char(op0.is_collinear) == s[3]
|
||||
: true)
|
||||
&& (count > 4
|
||||
? is_colinear_char(op1.is_collinear) == s[4]
|
||||
: true);
|
||||
}
|
||||
|
||||
static char is_colinear_char(bool is_collinear)
|
||||
{
|
||||
return is_collinear ? '=' : '+';
|
||||
}
|
||||
@ -115,12 +117,11 @@ struct equal_turn<1>
|
||||
};
|
||||
|
||||
template <typename Geometry1, typename Geometry2, typename Expected>
|
||||
void check_geometry_range(
|
||||
Geometry1 const& g1,
|
||||
Geometry2 const& g2,
|
||||
std::string const& wkt1,
|
||||
std::string const& wkt2,
|
||||
Expected const& expected)
|
||||
void check_geometry_range(Geometry1 const& g1,
|
||||
Geometry2 const& g2,
|
||||
std::string const& wkt1,
|
||||
std::string const& wkt2,
|
||||
Expected const& expected)
|
||||
{
|
||||
typedef bg::detail::no_rescale_policy robust_policy_type;
|
||||
typedef typename bg::point_type<Geometry2>::type point_type;
|
||||
@ -168,7 +169,7 @@ void check_geometry_range(
|
||||
sit != boost::end(expected) ; ++sit)
|
||||
{
|
||||
typename std::vector<turn_info>::iterator
|
||||
it = std::find_if(turns.begin(), turns.end(), equal_turn<Expected::version>(*sit));
|
||||
it = std::find_if(turns.begin(), turns.end(), equal_turn(*sit));
|
||||
|
||||
if ( it != turns.end() )
|
||||
turns.erase(it);
|
||||
@ -245,9 +246,9 @@ void test_geometry(std::string const& wkt1, std::string const& wkt2,
|
||||
test_geometry_range<G1, G2>(wkt1, wkt2, expected(ex0)(ex1)(ex2));
|
||||
}
|
||||
|
||||
template <typename G1, typename G2, int Version>
|
||||
template <typename G1, typename G2>
|
||||
void test_geometry(std::string const& wkt1, std::string const& wkt2,
|
||||
expected_pusher<Version> const& expected)
|
||||
expected_pusher const& expected)
|
||||
{
|
||||
test_geometry_range<G1, G2>(wkt1, wkt2, expected);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user