From 31c5e016e74067331a6353195a65cfaf2e1bfedc Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Mon, 25 Jun 2012 19:00:24 +0000 Subject: [PATCH] added tests of some index's algorithms + index::margin() optimization. [SVN r79090] --- .../extensions/index/algorithms/margin.hpp | 6 +- test/Jamfile.v2 | 27 +++ test/algorithms/Jamfile.v2 | 17 ++ test/algorithms/content.cpp | 77 +++++++++ test/algorithms/is_valid.cpp | 102 +++++++++++ test/algorithms/margin.cpp | 72 ++++++++ test/algorithms/test_content.hpp | 50 ++++++ test/algorithms/test_margin.hpp | 49 ++++++ test/geometry_index_test_common.hpp | 25 +++ test/geometry_test_common.hpp | 162 ++++++++++++++++++ 10 files changed, 584 insertions(+), 3 deletions(-) create mode 100644 test/Jamfile.v2 create mode 100644 test/algorithms/Jamfile.v2 create mode 100644 test/algorithms/content.cpp create mode 100644 test/algorithms/is_valid.cpp create mode 100644 test/algorithms/margin.cpp create mode 100644 test/algorithms/test_content.hpp create mode 100644 test/algorithms/test_margin.hpp create mode 100644 test/geometry_index_test_common.hpp create mode 100644 test/geometry_test_common.hpp diff --git a/include/boost/geometry/extensions/index/algorithms/margin.hpp b/include/boost/geometry/extensions/index/algorithms/margin.hpp index ea235e9c9..a86d15811 100644 --- a/include/boost/geometry/extensions/index/algorithms/margin.hpp +++ b/include/boost/geometry/extensions/index/algorithms/margin.hpp @@ -76,7 +76,7 @@ struct margin_for_each_dimension static inline typename default_margin_result::type apply(Box const& b) { return margin_for_each_dimension::apply(b) + - 2 * margin_for_each_edge::value>::apply(b); + margin_for_each_edge::value>::apply(b); } }; @@ -85,7 +85,7 @@ struct margin_for_each_dimension { static inline typename default_margin_result::type apply(Box const& b) { - return 2 * margin_for_each_edge::value>::apply(b); + return margin_for_each_edge::value>::apply(b); } }; @@ -94,7 +94,7 @@ struct margin_for_each_dimension template typename default_margin_result::type margin(Box const& b) { - return detail::margin_for_each_dimension::value>::apply(b); + return 2 * detail::margin_for_each_dimension::value>::apply(b); } }}} // namespace boost::geometry::index diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 new file mode 100644 index 000000000..6760caf7d --- /dev/null +++ b/test/Jamfile.v2 @@ -0,0 +1,27 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +# +# 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) + +import testing ; + +project boost-geometry-index-test + : + requirements + . + .. + ../.. + ../../.. + #../../../boost/geometry/extensions/contrib/ttmath + msvc:on + ; + +build-project algorithms ; +#build-project rtree ; +#build-project filters ; +#build-project translator ; diff --git a/test/algorithms/Jamfile.v2 b/test/algorithms/Jamfile.v2 new file mode 100644 index 000000000..6da7d6901 --- /dev/null +++ b/test/algorithms/Jamfile.v2 @@ -0,0 +1,17 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +# +# 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-index-algorithms + : + [ run content.cpp ] + [ run is_valid.cpp ] + [ run margin.cpp ] + ; + diff --git a/test/algorithms/content.cpp b/test/algorithms/content.cpp new file mode 100644 index 000000000..b6d01d8cf --- /dev/null +++ b/test/algorithms/content.cpp @@ -0,0 +1,77 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// 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 + +//#define GEOMETRY_TEST_DEBUG + +void test_large_integers() +{ + typedef bg::model::point int_point_type; + typedef bg::model::point double_point_type; + + bg::model::box int_box; + bg::model::box double_box; + + std::string const box_li = "POLYGON((1536119 192000, 1872000 528000))"; + bg::read_wkt(box_li, int_box); + bg::read_wkt(box_li, double_box); + + double int_value = bgi::content(int_box); + double double_value = bgi::content(double_box); + + BOOST_CHECK_CLOSE(int_value, double_value, 0.0001); +} + +int test_main(int, char* []) +{ + typedef bg::model::point P2ic; + typedef bg::model::point P2fc; + typedef bg::model::point P2dc; + + typedef bg::model::point P3ic; + typedef bg::model::point P3fc; + typedef bg::model::point P3dc; + + test_content(P2ic(0, 0), 0); + test_content(P2fc(0, 0), 0); + test_content(P2dc(0, 0), 0); + test_content(P3ic(0, 0, 0), 0); + test_content(P3fc(0, 0, 0), 0); + test_content(P3dc(0, 0, 0), 0); + + test_geometry >("POLYGON((0 1,2 4))", 6.0); + test_geometry >("POLYGON((0 1,2 4))", 6.0); + test_geometry >("POLYGON((0 1,2 4))", 6.0); + test_geometry >("POLYGON((0 1 2,2 4 6))", 24.0); + test_geometry >("POLYGON((0 1 2,2 4 6))", 24.0); + test_geometry >("POLYGON((0 1 2,2 4 6))", 24.0); + +#ifdef HAVE_TTMATH + typedef bg::model::point P2ttmc; + typedef bg::model::point P3ttmc; + + test_geometry >("POLYGON((0 1,2 4))", 6.0); + test_geometry >("POLYGON((0 1 2,2 4 6))", 24.0); +#endif + + test_large_integers(); + + return 0; +} diff --git a/test/algorithms/is_valid.cpp b/test/algorithms/is_valid.cpp new file mode 100644 index 000000000..4b339c527 --- /dev/null +++ b/test/algorithms/is_valid.cpp @@ -0,0 +1,102 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// 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 + +//#define GEOMETRY_TEST_DEBUG + +template +void test(Geometry const& geometry, bool expected_value) +{ + BOOST_CHECK(bgi::is_valid(geometry) == expected_value); +} + +template +void test_box(std::string const& wkt, bool expected_value) +{ + Box box; + bg::read_wkt(wkt, box); + test(box, expected_value); + typename bg::point_type::type temp_pt; + temp_pt = box.min_corner(); + box.min_corner() = box.max_corner(); + box.max_corner() = temp_pt; + test(box, !expected_value); +} + +void test_large_integers() +{ + typedef bg::model::point int_point_type; + typedef bg::model::point double_point_type; + + bg::model::box int_box; + bg::model::box double_box; + + std::string const box_li = "POLYGON((1536119 192000, 1872000 528000))"; + bg::read_wkt(box_li, int_box); + bg::read_wkt(box_li, double_box); + + BOOST_CHECK(bgi::is_valid(int_box) == bgi::is_valid(double_box)); + + std::string const box_li2 = "POLYGON((1872000 528000, 1536119 192000))"; + bg::read_wkt(box_li2, int_box); + bg::read_wkt(box_li2, double_box); + + BOOST_CHECK(bgi::is_valid(int_box) == bgi::is_valid(double_box)); +} + +int test_main(int, char* []) +{ + typedef bg::model::point P2ic; + typedef bg::model::point P2fc; + typedef bg::model::point P2dc; + + typedef bg::model::point P3ic; + typedef bg::model::point P3fc; + typedef bg::model::point P3dc; + + test(P2ic(0, 0), true); + test(P2fc(0, 0), true); + test(P2dc(0, 0), true); + test(P3ic(0, 0, 0), true); + test(P3fc(0, 0, 0), true); + test(P3dc(0, 0, 0), true); + + test_box >("POLYGON((0 1,2 4))", true); + test_box >("POLYGON((0 1,2 4))", true); + test_box >("POLYGON((0 1,2 4))", true); + test_box >("POLYGON((0 1 2,2 4 6))", true); + test_box >("POLYGON((0 1 2,2 4 6))", true); + test_box >("POLYGON((0 1 2,2 4 6))", true); + +#ifdef HAVE_TTMATH + typedef bg::model::point P2ttmc; + typedef bg::model::point P3ttmc; + + test_geometry >("POLYGON((0 1,2 4))", true); + test_geometry >("POLYGON((0 1 2,2 4 6))", true); +#endif + + test_large_integers(); + + return 0; +} diff --git a/test/algorithms/margin.cpp b/test/algorithms/margin.cpp new file mode 100644 index 000000000..6a825b458 --- /dev/null +++ b/test/algorithms/margin.cpp @@ -0,0 +1,72 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// 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 + +//#define GEOMETRY_TEST_DEBUG + +void test_large_integers() +{ + typedef bg::model::point int_point_type; + typedef bg::model::point double_point_type; + + bg::model::box int_box; + bg::model::box double_box; + + std::string const box_li = "POLYGON((1536119 192000, 1872000 528000))"; + bg::read_wkt(box_li, int_box); + bg::read_wkt(box_li, double_box); + + double int_value = bgi::margin(int_box); + double double_value = bgi::margin(double_box); + + BOOST_CHECK_CLOSE(int_value, double_value, 0.0001); +} + +int test_main(int, char* []) +{ + typedef bg::model::point P2ic; + typedef bg::model::point P2fc; + typedef bg::model::point P2dc; + + typedef bg::model::point P3ic; + typedef bg::model::point P3fc; + typedef bg::model::point P3dc; + + test_geometry >("POLYGON((0 1,2 4))", 10.0); + test_geometry >("POLYGON((0 1,2 4))", 10.0); + test_geometry >("POLYGON((0 1,2 4))", 10.0); + test_geometry >("POLYGON((0 1 2,2 4 6))", 52); + test_geometry >("POLYGON((0 1 2,2 4 6))", 52.0); + test_geometry >("POLYGON((0 1 2,2 4 6))", 52.0); + +#ifdef HAVE_TTMATH + typedef bg::model::point P2ttmc; + typedef bg::model::point P3ttmc; + + test_geometry >("POLYGON((0 1,2 4))", 10.0); + test_geometry >("POLYGON((0 1 2,2 4 6))", 52.0); +#endif + + test_large_integers(); + + // test_empty_input >(); + + return 0; +} diff --git a/test/algorithms/test_content.hpp b/test/algorithms/test_content.hpp new file mode 100644 index 000000000..42143d575 --- /dev/null +++ b/test/algorithms/test_content.hpp @@ -0,0 +1,50 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2011-2012 Adam Wulkiewicz, Lodz, Poland. + +// 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) + +#ifndef BOOST_GEOMETRY_EXTENSIONS_INDEX_TEST_CONTENT_HPP +#define BOOST_GEOMETRY_EXTENSIONS_INDEX_TEST_CONTENT_HPP + +#include + +#include + +//#include + + +template +void test_content(Geometry const& geometry, + typename bgi::default_content_result::type expected_value) +{ + typename bgi::default_content_result::type value = bgi::content(geometry); + +#ifdef GEOMETRY_TEST_DEBUG + std::ostringstream out; + out << typeid(typename bg::coordinate_type::type).name() + << " " + << typeid(typename bgi::default_content_result::type).name() + << " " + << "content : " << value + << std::endl; + std::cout << out.str(); +#endif + + BOOST_CHECK_CLOSE(value, expected_value, 0.0001); +} + +template +void test_geometry(std::string const& wkt, + typename bgi::default_content_result::type expected_value) +{ + Geometry geometry; + bg::read_wkt(wkt, geometry); + test_content(geometry, expected_value); +} + +#endif diff --git a/test/algorithms/test_margin.hpp b/test/algorithms/test_margin.hpp new file mode 100644 index 000000000..318478221 --- /dev/null +++ b/test/algorithms/test_margin.hpp @@ -0,0 +1,49 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2011-2012 Adam Wulkiewicz, Lodz, Poland. + +// 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) + +#ifndef BOOST_GEOMETRY_EXTENSIONS_INDEX_TEST_MARGIN_HPP +#define BOOST_GEOMETRY_EXTENSIONS_INDEX_TEST_MARGIN_HPP + +#include + +#include + +//#include + +template +void test_margin(Geometry const& geometry, + typename bgi::default_margin_result::type expected_value) +{ + typename bgi::default_margin_result::type value = bgi::margin(geometry); + +#ifdef GEOMETRY_TEST_DEBUG + std::ostringstream out; + out << typeid(typename bg::coordinate_type::type).name() + << " " + << typeid(typename bgi::default_margin_result::type).name() + << " " + << "content : " << value + << std::endl; + std::cout << out.str(); +#endif + + BOOST_CHECK_CLOSE(value, expected_value, 0.0001); +} + +template +void test_geometry(std::string const& wkt, + typename bgi::default_margin_result::type expected_value) +{ + Geometry geometry; + bg::read_wkt(wkt, geometry); + test_margin(geometry, expected_value); +} + +#endif diff --git a/test/geometry_index_test_common.hpp b/test/geometry_index_test_common.hpp new file mode 100644 index 000000000..3ca1da626 --- /dev/null +++ b/test/geometry_index_test_common.hpp @@ -0,0 +1,25 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// 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) + + +#ifndef GEOMETRY_TEST_GEOMETRY_INDEX_TEST_COMMON_HPP +#define GEOMETRY_TEST_GEOMETRY_INDEX_TEST_COMMON_HPP + +#include +#include + +#include + +namespace bgi = boost::geometry::index; + +#endif // GEOMETRY_TEST_GEOMETRY_INDEX_TEST_COMMON_HPP diff --git a/test/geometry_test_common.hpp b/test/geometry_test_common.hpp new file mode 100644 index 000000000..4777a0ab7 --- /dev/null +++ b/test/geometry_test_common.hpp @@ -0,0 +1,162 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// 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) + + +#ifndef GEOMETRY_TEST_GEOMETRY_TEST_COMMON_HPP +#define GEOMETRY_TEST_GEOMETRY_TEST_COMMON_HPP + +#if defined(_MSC_VER) +// We deliberately mix float/double's so turn off warnings +#pragma warning( disable : 4244 ) +// For (new since Boost 1.40) warning in Boost.Test on putenv/posix +#pragma warning( disable : 4996 ) + +//#pragma warning( disable : 4305 ) +#endif // defined(_MSC_VER) + +#include + + +#if defined(BOOST_INTEL_CXX_VERSION) +#define BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE +#endif + + +#include + + +// Include some always-included-for-testing files +#if ! defined(BOOST_GEOMETRY_NO_BOOST_TEST) + +// Until Boost fixes it, silence warning issued by clang: +// warning: unused variable 'check_is_close' [-Wunused-variable] +#ifdef __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunused-variable" +#endif + +# include +# include +//# include +# include + +#ifdef __clang__ +# pragma clang diagnostic pop +#endif + +#endif + + +#if defined(HAVE_TTMATH) +# include +#endif + +#if defined(HAVE_CLN) || defined(HAVE_GMP) +# include +#endif + + +#if defined(HAVE_GMP) +# include +#endif +#if defined(HAVE_CLN) +# include +#endif + + +template +struct string_from_type {}; + +template <> struct string_from_type +{ static std::string name() { return "v"; } }; + +template <> struct string_from_type +{ static std::string name() { return "f"; } }; + +template <> struct string_from_type +{ static std::string name() { return "d"; } }; + +template <> struct string_from_type +{ static std::string name() { return "e"; } }; + +#if defined(HAVE_TTMATH) + template <> struct string_from_type + { static std::string name() { return "t"; } }; +#endif + +#if defined(BOOST_RATIONAL_HPP) +template struct string_from_type > +{ static std::string name() { return "r"; } }; +#endif + + +#if defined(HAVE_GMP) + template <> struct string_from_type + { static std::string name() { return "g"; } }; +#endif + +#if defined(HAVE_CLN) + template <> struct string_from_type + { static std::string name() { return "c"; } }; +#endif + + +template +inline T1 if_typed_tt(T1 value_tt, T2 value) +{ +#if defined(HAVE_TTMATH) + return boost::is_same::type::value ? value_tt : value; +#else + return value; +#endif +} + +template +inline T if_typed(T value_typed, T value) +{ + return boost::is_same::value ? value_typed : value; +} + + + + +struct geographic_policy +{ + template + static inline CoordinateType apply(CoordinateType const& value) + { + return value; + } +}; + +struct mathematical_policy +{ + template + static inline CoordinateType apply(CoordinateType const& value) + { + return 90 - value; + } + +}; + + + + +// For all tests: +// - do NOT use "using namespace boost::geometry" to make clear what is Boost.Geometry +// - use bg:: as short alias +#include +namespace bg = boost::geometry; + + +#endif // GEOMETRY_TEST_GEOMETRY_TEST_COMMON_HPP