[test] [length] Fixing issues from comments in length tests.

This commit is contained in:
Vissarion Fysikopoulos 2016-05-23 13:19:00 +03:00
parent 03555f438f
commit 7bdee87a22
6 changed files with 83 additions and 83 deletions

View File

@ -36,5 +36,3 @@ exe c08_custom_non_std_example : c08_custom_non_std_example.cpp ;
exe c09_custom_fusion_example : c09_custom_fusion_example.cpp ;
exe c10_custom_cs_example : c10_custom_cs_example.cpp ;
exe c11_custom_cs_transform_example : c11_custom_cs_transform_example.cpp ;

View File

@ -9,6 +9,7 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <algorithms/test_length.hpp>
#include <algorithms/length/linestring_cases.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
@ -18,60 +19,29 @@
#include <test_geometries/wrapped_boost_array.hpp>
template <typename P>
struct geo_strategies{
// Set radius type, but for integer coordinates we want to have floating point radius type
struct geo_strategies
{
// Set radius type, but for integer coordinates we want to have floating
// point radius type
typedef typename bg::promote_floating_point
<
typename bg::coordinate_type<P>::type
>::type rtype;
typedef bg::srs::spheroid<rtype> stype;
typedef bg::strategy::distance::andoyer<stype> andoyer_type;
BOOST_CONCEPT_ASSERT
(
(bg::concept::PointDistanceStrategy<andoyer_type, P, P>)
);
typedef bg::strategy::distance::thomas<stype> thomas_type;
BOOST_CONCEPT_ASSERT
(
(bg::concept::PointDistanceStrategy<thomas_type, P, P>)
);
typedef bg::strategy::distance::vincenty<stype> vincenty_type;
BOOST_CONCEPT_ASSERT
(
(bg::concept::PointDistanceStrategy<vincenty_type, P, P>)
);
//typedef typename bg::strategy::distance::services::default_strategy
//<
// bg::point_tag, bg::point_tag, P
//>::type default_strategy_type;
};
std::vector<std::string > Ls_data_gen()
{
std::string arr[] = {"LINESTRING(0 90,1 80,1 70)",
"LINESTRING(0 90,1 80,1 80,1 80,1 70,1 70)",
"LINESTRING(0 90,1 80,1 79,1 78,1 77,1 76,1 75,1 74,1 73,1 72,1 71,1 70)"};
std::vector<std::string> Ls_data (arr, arr + sizeof(arr) / sizeof(arr[0]));
return Ls_data;
}
template <typename P>
void test_default() //this should use andoyer strategy
{
std::vector<std::string > Ls_data = Ls_data_gen();
for(size_t i=0; i<2; ++i)
test_geometry<bg::model::linestring<P> >(Ls_data[i], 1116814.237 + 1116152.605);
for(std::size_t i = 0; i < 2; ++i)
{
test_geometry<bg::model::linestring<P> >(Ls_data_geo[i],
1116814.237 + 1116152.605);
}
// Geometries with length zero
test_geometry<P>("POINT(0 0)", 0);
test_geometry<bg::model::polygon<P> >("POLYGON((0 0,0 1,1 1,1 0,0 0))", 0);
@ -80,14 +50,16 @@ void test_default() //this should use andoyer strategy
template <typename P, typename N, typename Strategy>
void test_with_strategy(N exp_length, Strategy strategy)
{
std::vector<std::string > Ls_data = Ls_data_gen();
for(size_t i=0; i<2; ++i)
test_geometry<bg::model::linestring<P> >(Ls_data[i], exp_length, strategy);
for(std::size_t i = 0; i < 2; ++i)
{
test_geometry<bg::model::linestring<P> >(Ls_data_geo[i],
exp_length,
strategy);
}
// Geometries with length zero
test_geometry<P>("POINT(0 0)", 0, strategy);
test_geometry<bg::model::polygon<P> >("POLYGON((0 0,0 1,1 1,1 0,0 0))", 0, strategy);
test_geometry<bg::model::polygon<P> >("POLYGON((0 0,0 1,1 1,1 0,0 0))", 0,
strategy);
}
template <typename P>
@ -124,20 +96,25 @@ template <typename P>
void test_empty_input()
{
test_empty_input(bg::model::linestring<P>());
test_empty_input(bg::model::multi_linestring<P>());
}
int test_main(int, char* [])
{
// Works only for double(?!)
//test_all<bg::model::d2::point_xy<int, bg::cs::geographic<bg::degree> > >();
//test_all<bg::model::d2::point_xy<float, bg::cs::geographic<bg::degree> > >();
test_all<bg::model::d2::point_xy<double , bg::cs::geographic<bg::degree> > >();
//test_all<bg::model::d2::point_xy<int,
// bg::cs::geographic<bg::degree> > >();
//test_all<bg::model::d2::point_xy<float,
// bg::cs::geographic<bg::degree> > >();
test_all<bg::model::d2::point_xy<double,
bg::cs::geographic<bg::degree> > >();
#if defined(HAVE_TTMATH)
test_all<bg::model::d2::point_xy<ttmath_big> >();
#endif
//test_empty_input<bg::model::d2::point_xy<int> >();
//test_empty_input<bg::model::d2::point_xy<double,
// bg::cs::geographic<bg::degree> > >();
return 0;
}

View File

@ -11,7 +11,6 @@
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
template <typename P>
void test_all()
{
@ -19,6 +18,12 @@ void test_all()
("MULTILINESTRING((0 0,3 4,4 3))", 5 + sqrt(2.0));
}
template <typename P>
void test_empty_input()
{
test_empty_input(bg::model::multi_linestring<P>());
}
int test_main( int , char* [] )
{
test_all<bg::model::d2::point_xy<double> >();
@ -27,5 +32,7 @@ int test_main( int , char* [] )
test_all<bg::model::d2::point_xy<ttmath_big> >();
#endif
// test_empty_input<bg::model::d2::point_xy<int> >();
return 0;
}

View File

@ -9,6 +9,7 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <algorithms/test_length.hpp>
#include <algorithms/length/linestring_cases.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
@ -17,25 +18,15 @@
#include <test_geometries/all_custom_linestring.hpp>
#include <test_geometries/wrapped_boost_array.hpp>
std::vector<std::string > Ls_data_gen()
{
std::string arr[] = {"LINESTRING(0 0,180 0,180 180)",
"LINESTRING(0 0,180 0,180 0,180 0,180 180,180 180)",
"LINESTRING(0 0,180 0,180 10,180 20,180 30,180 40,180 50,180 60,180 70,180 80,180 90,180 100,\
180 110,180 120,180 130,180 140,180 150,180 160,180 170,180 180)"};
std::vector<std::string> Ls_data (arr, arr + sizeof(arr) / sizeof(arr[0]));
return Ls_data;
}
template <typename P>
void test_all_default() //test the default strategy
{
double const pi = boost::math::constants::pi<double>();
std::vector<std::string > Ls_data = Ls_data_gen();
for(size_t i=0; i<2; ++i)
test_geometry<bg::model::linestring<P> >(Ls_data[i], 2 * pi);
for(std::size_t i = 0; i < 2; ++i)
{
test_geometry<bg::model::linestring<P> >(Ls_data_sph[i], 2 * pi);
}
// Geometries with length zero
test_geometry<P>("POINT(0 0)", 0);
test_geometry<bg::model::polygon<P> >("POLYGON((0 0,0 1,1 1,1 0,0 0))", 0);
@ -46,34 +37,45 @@ void test_all_haversine(double const mean_radius)
{
double const pi = boost::math::constants::pi<double>();
bg::strategy::distance::haversine<float> haversine_strategy(mean_radius);
std::vector<std::string > Ls_data = Ls_data_gen();
for(size_t i=0; i<2; ++i)
test_geometry<bg::model::linestring<P> >(Ls_data[i], 2 * pi * mean_radius, haversine_strategy);
for(std::size_t i = 0; i < 2; ++i)
{
test_geometry<bg::model::linestring<P> >(Ls_data_sph[i],
2 * pi * mean_radius,
haversine_strategy);
}
// Geometries with length zero
test_geometry<P>("POINT(0 0)", 0, haversine_strategy);
test_geometry<bg::model::polygon<P> >("POLYGON((0 0,0 1,1 1,1 0,0 0))", 0, haversine_strategy);
//TODO why the following is not zero but 2.44929359829470641435e-16 ?
//test_geometry<std::pair<P, P> >("LINESTRING(0 0,360 0)", 0);
//TODO why the following is not zero but 4.8985871965894128287e-16 ?
//test_geometry<std::pair<P, P> >("LINESTRING(0 0,720 0)", 0);
test_geometry<bg::model::polygon<P> >("POLYGON((0 0,0 1,1 1,1 0,0 0))",
0, haversine_strategy);
}
template <typename P>
void test_empty_input()
{
test_empty_input(bg::model::linestring<P>());
test_empty_input(bg::model::multi_linestring<P>());
}
int test_main(int, char* [])
{
//Earth radius estimation (see https://en.wikipedia.org/wiki/Earth_radius)
//Earth radius estimation in Km
//(see https://en.wikipedia.org/wiki/Earth_radius)
double const mean_radius = 6371.0;
test_all_haversine<bg::model::d2::point_xy<int, bg::cs::spherical_equatorial<bg::degree> > >(mean_radius);
test_all_haversine<bg::model::d2::point_xy<float, bg::cs::spherical_equatorial<bg::degree> > >(mean_radius);
test_all_haversine<bg::model::d2::point_xy<double , bg::cs::spherical_equatorial<bg::degree> > >(mean_radius);
test_all_default<bg::model::d2::point_xy<int,
bg::cs::spherical_equatorial<bg::degree> > >();
test_all_default<bg::model::d2::point_xy<float,
bg::cs::spherical_equatorial<bg::degree> > >();
test_all_default<bg::model::d2::point_xy<double,
bg::cs::spherical_equatorial<bg::degree> > >();
test_all_haversine<bg::model::d2::point_xy<int,
bg::cs::spherical_equatorial<bg::degree> > >(mean_radius);
test_all_haversine<bg::model::d2::point_xy<float,
bg::cs::spherical_equatorial<bg::degree> > >(mean_radius);
test_all_haversine<bg::model::d2::point_xy<double,
bg::cs::spherical_equatorial<bg::degree> > >(mean_radius);
#if defined(HAVE_TTMATH)
test_all<bg::model::d2::point_xy<ttmath_big> >();

View File

@ -0,0 +1,17 @@
#ifndef LINESTRING_CASES_HPP
#define LINESTRING_CASES_HPP
#include <string>
static std::string Ls_data_geo[] = {"LINESTRING(0 90,1 80,1 70)",
"LINESTRING(0 90,1 80,1 80,1 80,1 70,1 70)",
"LINESTRING(0 90,1 80,1 79,1 78,1 77,1 76,1 75,1 74,\
1 73,1 72,1 71,1 70)"};
static std::string Ls_data_sph[] = {"LINESTRING(0 0,180 0,180 180)",
"LINESTRING(0 0,180 0,180 0,180 0,180 180,180 180)",
"LINESTRING(0 0,180 0,180 10,180 20,180 30,180 40,180 50,180 60,\
180 70,180 80,180 90,180 100,180 110,180 120,180 130,\
180 140,180 150,180 160,180 170,180 180)"};
#endif // LINESTRING_CASES_HPP

View File

@ -44,7 +44,7 @@ template <typename Geometry, typename Strategy>
void test_length(Geometry const& geometry, long double expected_length, Strategy strategy)
{
typename bg::default_length_result<Geometry>::type
length = bg::length(geometry,strategy);
length = bg::length(geometry, strategy);
#ifdef BOOST_GEOMETRY_TEST_DEBUG
std::ostringstream out;
@ -52,7 +52,7 @@ void test_length(Geometry const& geometry, long double expected_length, Strategy
<< std::endl
<< typeid(typename bg::default_length_result<Geometry>::type).name()
<< std::endl
<< "length : " << bg::length(geometry,strategy)
<< "length : " << bg::length(geometry, strategy)
<< std::endl;
std::cout << out.str();
#endif
@ -63,7 +63,6 @@ void test_length(Geometry const& geometry, long double expected_length, Strategy
template <typename Geometry>
void test_geometry(std::string const& wkt, double expected_length)
{
//typedef typename default_strategy<Geometry>::strategy_type strategy_type;
Geometry geometry;
bg::read_wkt(wkt, geometry);
test_length(geometry, expected_length);