From 7423d61a8dae70da8653709ca4af8540c3d621f4 Mon Sep 17 00:00:00 2001 From: Vissarion Fysikopoulos Date: Thu, 19 May 2016 18:56:18 +0300 Subject: [PATCH] [test] [length] Tests for length algorithm. --- example/Jamfile.v2 | 2 + test/algorithms/Jamfile.v2 | 5 +- test/algorithms/buffer/Jamfile.v2 | 1 + test/algorithms/{ => buffer}/buffer.cpp | 12 +- test/algorithms/length/Jamfile.v2 | 17 +++ test/algorithms/{ => length}/length.cpp | 0 test/algorithms/length/length_geo.cpp | 144 ++++++++++++++++++ test/algorithms/{ => length}/length_multi.cpp | 0 test/algorithms/length/length_sph.cpp | 85 +++++++++++ test/algorithms/test_length.hpp | 36 ++++- 10 files changed, 295 insertions(+), 7 deletions(-) rename test/algorithms/{ => buffer}/buffer.cpp (81%) create mode 100644 test/algorithms/length/Jamfile.v2 rename test/algorithms/{ => length}/length.cpp (100%) create mode 100644 test/algorithms/length/length_geo.cpp rename test/algorithms/{ => length}/length_multi.cpp (100%) create mode 100644 test/algorithms/length/length_sph.cpp diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index 17fae5000..785ea911c 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -36,3 +36,5 @@ 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 ; + + diff --git a/test/algorithms/Jamfile.v2 b/test/algorithms/Jamfile.v2 index 03777cef3..2f65a3655 100644 --- a/test/algorithms/Jamfile.v2 +++ b/test/algorithms/Jamfile.v2 @@ -7,6 +7,7 @@ # This file was modified by Oracle on 2014, 2015, 2016. # Modifications copyright (c) 2014-2016, Oracle and/or its affiliates. # +# Contributed and/or modified by Vissarion Fisikopoulos, on behalf of Oracle # Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle # Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle # @@ -20,7 +21,6 @@ test-suite boost-geometry-algorithms [ run area.cpp : : : : algorithms_area ] [ run area_multi.cpp : : : : algorithms_area_multi ] [ run assign.cpp : : : : algorithms_assign ] - [ run buffer.cpp : : : : algorithms_buffer ] [ run centroid.cpp : : : : algorithms_centroid ] [ run centroid_multi.cpp : : : : algorithms_centroid_multi ] [ run comparable_distance.cpp : : : : algorithms_comparable_distance ] @@ -37,8 +37,6 @@ test-suite boost-geometry-algorithms [ run is_simple.cpp : : : : algorithms_is_simple ] [ run is_valid.cpp : : : : algorithms_is_valid ] [ run is_valid_failure.cpp : : : : algorithms_is_valid_failure ] - [ run length.cpp : : : : algorithms_length ] - [ run length_multi.cpp : : : : algorithms_length_multi ] [ run make.cpp : : : : algorithms_make ] [ run maximum_gap.cpp : : : : algorithms_maximum_gap ] [ run num_geometries.cpp : : : : algorithms_num_geometries ] @@ -66,6 +64,7 @@ build-project buffer ; build-project detail ; build-project distance ; build-project envelope_expand ; +build-project length ; build-project overlay ; build-project relational_operations ; build-project set_operations ; diff --git a/test/algorithms/buffer/Jamfile.v2 b/test/algorithms/buffer/Jamfile.v2 index 567bf41b0..521e5b4a1 100644 --- a/test/algorithms/buffer/Jamfile.v2 +++ b/test/algorithms/buffer/Jamfile.v2 @@ -14,6 +14,7 @@ project boost-geometry-algorithms-buffer test-suite boost-geometry-algorithms-buffer : + [ run buffer.cpp : : : : algorithms_buffer ] [ run buffer_with_strategies.cpp : : : BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_with_strategies ] [ run buffer_point.cpp : : : BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_point ] [ run buffer_linestring.cpp : : : BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE : algorithms_buffer_linestring ] diff --git a/test/algorithms/buffer.cpp b/test/algorithms/buffer/buffer.cpp similarity index 81% rename from test/algorithms/buffer.cpp rename to test/algorithms/buffer/buffer.cpp index fc591e630..a854faeae 100644 --- a/test/algorithms/buffer.cpp +++ b/test/algorithms/buffer/buffer.cpp @@ -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 2016. +// Modifications copyright (c) 2016, 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. @@ -18,6 +22,7 @@ #include #include +#include #include #include @@ -41,12 +46,13 @@ void test_all() box_type b2; bg::buffer(b1, b2, coordinate_type(2)); + box_type expected(P(-2, -2), P(4, 4)); + BOOST_CHECK(bg::equals(b2, expected)); + boost::variant v(b1); bg::buffer(v, b2, coordinate_type(2)); - // TODO: Check if buffer is correct - // using bg::equals to compare boxes - // (TODO: implement that) + BOOST_CHECK(bg::equals(b2, expected)); } int test_main(int, char* []) diff --git a/test/algorithms/length/Jamfile.v2 b/test/algorithms/length/Jamfile.v2 new file mode 100644 index 000000000..ff4ce2f92 --- /dev/null +++ b/test/algorithms/length/Jamfile.v2 @@ -0,0 +1,17 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2016 Oracle and/or its affiliates. +# +# Contributed and/or modified by Vissarion Fisikopoulos, 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) + +test-suite boost-geometry-algorithms-length + : + [ run length.cpp : : : : length ] + [ run length_multi.cpp : : : : length_multi ] + [ run length_sph.cpp : : : : length_sph ] + [ run length_geo.cpp : : : : length_geo ] + ; diff --git a/test/algorithms/length.cpp b/test/algorithms/length/length.cpp similarity index 100% rename from test/algorithms/length.cpp rename to test/algorithms/length/length.cpp diff --git a/test/algorithms/length/length_geo.cpp b/test/algorithms/length/length_geo.cpp new file mode 100644 index 000000000..d4291aa33 --- /dev/null +++ b/test/algorithms/length/length_geo.cpp @@ -0,0 +1,144 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2016 Oracle and/or its affiliates. +// Contributed and/or modified by Vissarion Fisikopoulos, 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 + +#include +#include +#include + +#include +#include + +template +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

::type + >::type rtype; + + typedef bg::srs::spheroid stype; + + typedef bg::strategy::distance::andoyer andoyer_type; + + BOOST_CONCEPT_ASSERT + ( + (bg::concept::PointDistanceStrategy) + ); + + typedef bg::strategy::distance::thomas thomas_type; + + BOOST_CONCEPT_ASSERT + ( + (bg::concept::PointDistanceStrategy) + ); + + typedef bg::strategy::distance::vincenty vincenty_type; + + BOOST_CONCEPT_ASSERT + ( + (bg::concept::PointDistanceStrategy) + ); + + //typedef typename bg::strategy::distance::services::default_strategy + //< + // bg::point_tag, bg::point_tag, P + //>::type default_strategy_type; + +}; + +std::vector 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 Ls_data (arr, arr + sizeof(arr) / sizeof(arr[0])); + return Ls_data; +} + +template +void test_default() //this should use andoyer strategy +{ + std::vector Ls_data = Ls_data_gen(); + + for(size_t i=0; i<2; ++i) + test_geometry >(Ls_data[i], 1116814.237 + 1116152.605); + + // Geometries with length zero + test_geometry

("POINT(0 0)", 0); + test_geometry >("POLYGON((0 0,0 1,1 1,1 0,0 0))", 0); +} + +template +void test_with_strategy(N exp_length, Strategy strategy) +{ + std::vector Ls_data = Ls_data_gen(); + + for(size_t i=0; i<2; ++i) + test_geometry >(Ls_data[i], exp_length, strategy); + + // Geometries with length zero + test_geometry

("POINT(0 0)", 0, strategy); + test_geometry >("POLYGON((0 0,0 1,1 1,1 0,0 0))", 0, strategy); +} + +template +void test_andoyer() +{ + typename geo_strategies

::andoyer_type andoyer; + test_with_strategy

(1116814.237 + 1116152.605, andoyer); +} + +template +void test_thomas() +{ + typename geo_strategies

::thomas_type thomas; + test_with_strategy

(1116825.795 + 1116158.7417, thomas); +} + +template +void test_vincenty() +{ + typename geo_strategies

::vincenty_type vincenty; + test_with_strategy

(1116828.8624 + 1116161.625, vincenty); +} + +template +void test_all() +{ + test_default

(); + test_andoyer

(); + test_thomas

(); + test_vincenty

(); +} + +template +void test_empty_input() +{ + test_empty_input(bg::model::linestring

()); +} + +int test_main(int, char* []) +{ + // Works only for double(?!) + //test_all > >(); + //test_all > >(); + test_all > >(); + +#if defined(HAVE_TTMATH) + test_all >(); +#endif + + //test_empty_input >(); + + return 0; +} + diff --git a/test/algorithms/length_multi.cpp b/test/algorithms/length/length_multi.cpp similarity index 100% rename from test/algorithms/length_multi.cpp rename to test/algorithms/length/length_multi.cpp diff --git a/test/algorithms/length/length_sph.cpp b/test/algorithms/length/length_sph.cpp new file mode 100644 index 000000000..f1240c560 --- /dev/null +++ b/test/algorithms/length/length_sph.cpp @@ -0,0 +1,85 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2016 Oracle and/or its affiliates. +// Contributed and/or modified by Vissarion Fisikopoulos, 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 + +#include +#include +#include + +#include +#include + +std::vector 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 Ls_data (arr, arr + sizeof(arr) / sizeof(arr[0])); + return Ls_data; +} + +template +void test_all_default() //test the default strategy +{ + double const pi = boost::math::constants::pi(); + std::vector Ls_data = Ls_data_gen(); + + for(size_t i=0; i<2; ++i) + test_geometry >(Ls_data[i], 2 * pi); + + // Geometries with length zero + test_geometry

("POINT(0 0)", 0); + test_geometry >("POLYGON((0 0,0 1,1 1,1 0,0 0))", 0); +} + +template +void test_all_haversine(double const mean_radius) +{ + double const pi = boost::math::constants::pi(); + bg::strategy::distance::haversine haversine_strategy(mean_radius); + std::vector Ls_data = Ls_data_gen(); + + for(size_t i=0; i<2; ++i) + test_geometry >(Ls_data[i], 2 * pi * mean_radius, haversine_strategy); + + // Geometries with length zero + test_geometry

("POINT(0 0)", 0, haversine_strategy); + test_geometry >("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 >("LINESTRING(0 0,360 0)", 0); + //TODO why the following is not zero but 4.8985871965894128287e-16 ? + //test_geometry >("LINESTRING(0 0,720 0)", 0); +} + +template +void test_empty_input() +{ + test_empty_input(bg::model::linestring

()); +} + +int test_main(int, char* []) +{ + //Earth radius estimation (see https://en.wikipedia.org/wiki/Earth_radius) + double const mean_radius = 6371.0; + + test_all_haversine > >(mean_radius); + test_all_haversine > >(mean_radius); + test_all_haversine > >(mean_radius); + +#if defined(HAVE_TTMATH) + test_all >(); +#endif + + //test_empty_input >(); + + return 0; +} diff --git a/test/algorithms/test_length.hpp b/test/algorithms/test_length.hpp index 107bdae21..cdd8a0f4f 100644 --- a/test/algorithms/test_length.hpp +++ b/test/algorithms/test_length.hpp @@ -2,6 +2,10 @@ // Unit Test // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// Copyright (c) 2016 Oracle and/or its affiliates. +// Contributed and/or modified by Vissarion Fisikopoulos, 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) @@ -16,7 +20,6 @@ #include #include - template void test_length(Geometry const& geometry, long double expected_length) { @@ -37,10 +40,30 @@ void test_length(Geometry const& geometry, long double expected_length) BOOST_CHECK_CLOSE(length, expected_length, 0.0001); } +template +void test_length(Geometry const& geometry, long double expected_length, Strategy strategy) +{ + typename bg::default_length_result::type + length = bg::length(geometry,strategy); + +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::ostringstream out; + out << typeid(typename bg::coordinate_type::type).name() + << std::endl + << typeid(typename bg::default_length_result::type).name() + << std::endl + << "length : " << bg::length(geometry,strategy) + << std::endl; + std::cout << out.str(); +#endif + + BOOST_CHECK_CLOSE(length, expected_length, 0.0001); +} template void test_geometry(std::string const& wkt, double expected_length) { + //typedef typename default_strategy::strategy_type strategy_type; Geometry geometry; bg::read_wkt(wkt, geometry); test_length(geometry, expected_length); @@ -49,6 +72,17 @@ void test_geometry(std::string const& wkt, double expected_length) #endif } +template +void test_geometry(std::string const& wkt, double expected_length, Strategy strategy) +{ + Geometry geometry; + bg::read_wkt(wkt, geometry); + test_length(geometry, expected_length, strategy); +#if !defined(BOOST_GEOMETRY_TEST_DEBUG) + test_length(boost::variant(geometry), expected_length, strategy); +#endif +} + template void test_empty_input(Geometry const& geometry) {