From c00ddbd2a83ce6d1e49cc12e93d33d64691d3549 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Tue, 26 Jun 2012 11:49:56 +0000 Subject: [PATCH] some tests and optimizations. [SVN r79107] --- .../extensions/index/algorithms/content.hpp | 3 +- .../index/algorithms/intersection_content.hpp | 8 +- .../index/algorithms/minmaxdist.hpp | 15 ++- test/algorithms/Jamfile.v2 | 5 +- test/algorithms/intersection_content.cpp | 78 +++++++++++++ test/algorithms/is_valid.cpp | 15 ++- test/algorithms/minmaxdist.cpp | 106 ++++++++++++++++++ test/algorithms/test_intersection_content.hpp | 52 +++++++++ test/algorithms/test_union_content.hpp | 48 ++++++++ test/algorithms/union_content.cpp | 75 +++++++++++++ 10 files changed, 393 insertions(+), 12 deletions(-) create mode 100644 test/algorithms/intersection_content.cpp create mode 100644 test/algorithms/minmaxdist.cpp create mode 100644 test/algorithms/test_intersection_content.hpp create mode 100644 test/algorithms/test_union_content.hpp create mode 100644 test/algorithms/union_content.cpp diff --git a/include/boost/geometry/extensions/index/algorithms/content.hpp b/include/boost/geometry/extensions/index/algorithms/content.hpp index 0dfa24d66..52aa49710 100644 --- a/include/boost/geometry/extensions/index/algorithms/content.hpp +++ b/include/boost/geometry/extensions/index/algorithms/content.hpp @@ -2,7 +2,8 @@ // // Boost.SpatialIndex - n-dimensional box's content (2d-area/3d-volume/...) // -// Copyright 2011 Adam Wulkiewicz. +// 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) diff --git a/include/boost/geometry/extensions/index/algorithms/intersection_content.hpp b/include/boost/geometry/extensions/index/algorithms/intersection_content.hpp index ae8286f2c..3cc969195 100644 --- a/include/boost/geometry/extensions/index/algorithms/intersection_content.hpp +++ b/include/boost/geometry/extensions/index/algorithms/intersection_content.hpp @@ -2,7 +2,8 @@ // // Boost.SpatialIndex - boxes union/intersection area/volume // -// Copyright 2011 Adam Wulkiewicz. +// 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) @@ -21,14 +22,13 @@ namespace boost { namespace geometry { namespace index { template inline typename default_content_result::type intersection_content(Box const& box1, Box const& box2) { - typename default_content_result::type result = 0; if ( geometry::intersects(box1, box2) ) { Box box_intersection; geometry::intersection(box1, box2, box_intersection); - result = index::content(box_intersection); + return index::content(box_intersection); } - return result; + return 0; } }}} // namespace boost::geometry::index diff --git a/include/boost/geometry/extensions/index/algorithms/minmaxdist.hpp b/include/boost/geometry/extensions/index/algorithms/minmaxdist.hpp index d7ed6d0f0..71e7dd8ca 100644 --- a/include/boost/geometry/extensions/index/algorithms/minmaxdist.hpp +++ b/include/boost/geometry/extensions/index/algorithms/minmaxdist.hpp @@ -2,7 +2,8 @@ // // Boost.Index - minmaxdist used in R-tree k nearest neighbors query // -// Copyright 2011 Adam Wulkiewicz. +// 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) @@ -10,12 +11,13 @@ #ifndef BOOST_GEOMETRY_EXTENSIONS_INDEX_ALGORITHMS_MINMAXDIST_HPP #define BOOST_GEOMETRY_EXTENSIONS_INDEX_ALGORITHMS_MINMAXDIST_HPP +#include +#include + #include #include #include -#include - namespace boost { namespace geometry { namespace index { namespace detail { @@ -49,7 +51,7 @@ struct smallest_for_indexable_dimension inline static result_type apply(Point const& pt, Indexable const& i) { - result_type maxd = maxdist(pt, i); + result_type maxd = geometry::comparable_distance(pt, i); return smallest_for_indexable< Point, @@ -102,6 +104,9 @@ struct minmaxdist_impl } // namespace detail +/** + * This is comparable distace. + */ template typename geometry::default_distance_result::type minmaxdist(Point const& pt, Indexable const& i) diff --git a/test/algorithms/Jamfile.v2 b/test/algorithms/Jamfile.v2 index 6da7d6901..619f13dd3 100644 --- a/test/algorithms/Jamfile.v2 +++ b/test/algorithms/Jamfile.v2 @@ -11,7 +11,10 @@ test-suite boost-geometry-index-algorithms : [ run content.cpp ] + [ run intersection_content.cpp ] # this tests overlap() too [ run is_valid.cpp ] - [ run margin.cpp ] + [ run margin.cpp ] + #[ run minmaxdist.cpp ] + [ run union_content.cpp ] ; diff --git a/test/algorithms/intersection_content.cpp b/test/algorithms/intersection_content.cpp new file mode 100644 index 000000000..70819d20c --- /dev/null +++ b/test/algorithms/intersection_content.cpp @@ -0,0 +1,78 @@ +// 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_box1, int_box2; + bg::model::box double_box1, double_box2; + + std::string const box_li1 = "POLYGON((1536119 192000, 1872000 528000))"; + std::string const box_li2 = "POLYGON((1701234 368250, 2673400 777400))"; + bg::read_wkt(box_li1, int_box1); + bg::read_wkt(box_li1, double_box1); + bg::read_wkt(box_li2, int_box2); + bg::read_wkt(box_li2, double_box2); + + double int_value = bgi::intersection_content(int_box1, int_box2); + double double_value = bgi::intersection_content(double_box1, double_box2); + + BOOST_CHECK_CLOSE(int_value, double_value, 0.0001); + + // temp + BOOST_CHECK_CLOSE(bgi::overlap(int_box1, int_box2), bgi::overlap(double_box1, double_box2), 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))", "POLYGON((1 2,3 5))", 2.0); + test_geometry >("POLYGON((0 1,2 4))", "POLYGON((1 2,3 5))", 2.0); + test_geometry >("POLYGON((0 1,2 4))", "POLYGON((1 2,3 5))", 2.0); + test_geometry >("POLYGON((0 1 2,2 4 6))", "POLYGON((1 2 3,3 5 7))", 6.0); + test_geometry >("POLYGON((0 1 2,2 4 6))", "POLYGON((1 2 3,3 5 7))", 6.0); + test_geometry >("POLYGON((0 1 2,2 4 6))", "POLYGON((1 2 3,3 5 7))", 6.0); + + test_geometry >("POLYGON((0 1,2 4))", "POLYGON((2 1,3 4))", 0.0); + test_geometry >("POLYGON((0 1,2 4))", "POLYGON((2 4,3 5))", 0.0); + +#ifdef HAVE_TTMATH + typedef bg::model::point P2ttmc; + typedef bg::model::point P3ttmc; + + test_geometry >("POLYGON((0 1,2 4))", "POLYGON((1 2,3 5))", 2.0); + test_geometry >("POLYGON((0 1 2,2 4 6))", "POLYGON((1 2 3,3 5 7))", 6.0); +#endif + + test_large_integers(); + + return 0; +} diff --git a/test/algorithms/is_valid.cpp b/test/algorithms/is_valid.cpp index 4b339c527..b7f4983c1 100644 --- a/test/algorithms/is_valid.cpp +++ b/test/algorithms/is_valid.cpp @@ -27,7 +27,20 @@ template void test(Geometry const& geometry, bool expected_value) { - BOOST_CHECK(bgi::is_valid(geometry) == expected_value); + bool value = bgi::is_valid(geometry); + +#ifdef GEOMETRY_TEST_DEBUG + std::ostringstream out; + out << typeid(typename bg::coordinate_type::type).name() + << " " + << typeid(bool).name() + << " " + << "is_valid : " << value + << std::endl; + std::cout << out.str(); +#endif + + BOOST_CHECK(value == expected_value); } template diff --git a/test/algorithms/minmaxdist.cpp b/test/algorithms/minmaxdist.cpp new file mode 100644 index 000000000..b0a84915b --- /dev/null +++ b/test/algorithms/minmaxdist.cpp @@ -0,0 +1,106 @@ +// 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(Point const& pt, Indexable const& indexable, + typename bg::default_distance_result::type expected_value) +{ + typename bg::default_distance_result::type value = bgi::minmaxdist(pt, indexable); + +#ifdef GEOMETRY_TEST_DEBUG + std::ostringstream out; + out << typeid(typename bg::coordinate_type::type).name() + << " " + << typeid(typename bg::coordinate_type::type).name() + << " " + << typeid(bg::default_distance_result::type).name() + << " " + << "minmaxdist : " << value + << std::endl; + std::cout << out.str(); +#endif + + BOOST_CHECK_CLOSE(value, expected_value, 0.0001); +} + +template +void test_indexable(Point const& pt, std::string const& wkt, + typename bg::default_distance_result::type expected_value) +{ + Indexable indexable; + bg::read_wkt(wkt, indexable); + test(pt, indexable, expected_value); +} + +void test_large_integers() +{ + typedef bg::model::point int_point_type; + typedef bg::model::point double_point_type; + + int_point_type int_pt(0, 0); + double_point_type double_pt(0, 0); + + 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::minmaxdist(int_pt, int_box) == bgi::minmaxdist(double_pt, 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_indexable >(P2ic(1, 2), "POLYGON((0 1,2 4))", 5.0); + test_indexable >(P2fc(1, 2), "POLYGON((0 1,2 4))", 5.0); + test_indexable >(P2dc(1, 2), "POLYGON((0 1,2 4))", 5.0); + test_indexable >(P3ic(1, 2, 3), "POLYGON((0 1 2,2 4 6))", 14.0); + test_indexable >(P3fc(1, 2, 3), "POLYGON((0 1 2,2 4 6))", 14.0); + test_indexable >(P3dc(1, 2, 3), "POLYGON((0 1 2,2 4 6))", 14.0); + + test_indexable >(P2ic(1, 2), "POLYGON((1 2,3 5))", 4.0); + +#ifdef HAVE_TTMATH + typedef bg::model::point P2ttmc; + typedef bg::model::point P3ttmc; + + test_indexable >(P2ttmc(1, 2), "POLYGON((0 1,2 4))", 5.0); + test_indexable >(P3ttmc(1, 2, 3), "POLYGON((0 1 2,2 4 6))", 14.0); +#endif + + test_large_integers(); + + return 0; +} diff --git a/test/algorithms/test_intersection_content.hpp b/test/algorithms/test_intersection_content.hpp new file mode 100644 index 000000000..415acfa61 --- /dev/null +++ b/test/algorithms/test_intersection_content.hpp @@ -0,0 +1,52 @@ +// 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_INTERSECTION_CONTENT_HPP +#define BOOST_GEOMETRY_EXTENSIONS_INDEX_TEST_INTERSECTION_CONTENT_HPP + +#include + +#include +#include + +template +void test_intersection_content(Geometry const& geometry1, Geometry const& geometry2, + typename bgi::default_content_result::type expected_value) +{ + typename bgi::default_content_result::type value = bgi::intersection_content(geometry1, geometry2); + +#ifdef GEOMETRY_TEST_DEBUG + std::ostringstream out; + out << typeid(typename bg::coordinate_type::type).name() + << " " + << typeid(typename bgi::default_content_result::type).name() + << " " + << "intersection_content : " << value + << std::endl; + std::cout << out.str(); +#endif + + BOOST_CHECK_CLOSE(value, expected_value, 0.0001); + + // temp + BOOST_CHECK_CLOSE(bgi::overlap(geometry1, geometry2), expected_value, 0.0001); +} + +template +void test_geometry(std::string const& wkt1, std::string const& wkt2, + typename bgi::default_content_result::type expected_value) +{ + Geometry geometry1, geometry2; + bg::read_wkt(wkt1, geometry1); + bg::read_wkt(wkt2, geometry2); + test_intersection_content(geometry1, geometry2, expected_value); +} + +#endif diff --git a/test/algorithms/test_union_content.hpp b/test/algorithms/test_union_content.hpp new file mode 100644 index 000000000..dfbf2432e --- /dev/null +++ b/test/algorithms/test_union_content.hpp @@ -0,0 +1,48 @@ +// 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_UNION_CONTENT_HPP +#define BOOST_GEOMETRY_EXTENSIONS_INDEX_TEST_UNION_CONTENT_HPP + +#include + +#include + +template +void test_union_content(Geometry const& geometry1, Geometry const& geometry2, + typename bgi::default_content_result::type expected_value) +{ + typename bgi::default_content_result::type value = bgi::union_content(geometry1, geometry2); + +#ifdef GEOMETRY_TEST_DEBUG + std::ostringstream out; + out << typeid(typename bg::coordinate_type::type).name() + << " " + << typeid(typename bgi::default_content_result::type).name() + << " " + << "union_content : " << value + << std::endl; + std::cout << out.str(); +#endif + + BOOST_CHECK_CLOSE(value, expected_value, 0.0001); +} + +template +void test_geometry(std::string const& wkt1, std::string const& wkt2, + typename bgi::default_content_result::type expected_value) +{ + Geometry geometry1, geometry2; + bg::read_wkt(wkt1, geometry1); + bg::read_wkt(wkt2, geometry2); + test_union_content(geometry1, geometry2, expected_value); +} + +#endif diff --git a/test/algorithms/union_content.cpp b/test/algorithms/union_content.cpp new file mode 100644 index 000000000..4a8c92e93 --- /dev/null +++ b/test/algorithms/union_content.cpp @@ -0,0 +1,75 @@ +// 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_box1, int_box2; + bg::model::box double_box1, double_box2; + + std::string const box_li1 = "POLYGON((1536119 192000, 1872000 528000))"; + std::string const box_li2 = "POLYGON((1701234 368250, 2673400 777400))"; + bg::read_wkt(box_li1, int_box1); + bg::read_wkt(box_li1, double_box1); + bg::read_wkt(box_li2, int_box2); + bg::read_wkt(box_li2, double_box2); + + double int_value = bgi::union_content(int_box1, int_box2); + double double_value = bgi::union_content(double_box1, double_box2); + + 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))", "POLYGON((1 2,3 5))", 12.0); + test_geometry >("POLYGON((0 1,2 4))", "POLYGON((1 2,3 5))", 12.0); + test_geometry >("POLYGON((0 1,2 4))", "POLYGON((1 2,3 5))", 12.0); + test_geometry >("POLYGON((0 1 2,2 4 6))", "POLYGON((1 2 3,3 5 7))", 60.0); + test_geometry >("POLYGON((0 1 2,2 4 6))", "POLYGON((1 2 3,3 5 7))", 60.0); + test_geometry >("POLYGON((0 1 2,2 4 6))", "POLYGON((1 2 3,3 5 7))", 60.0); + + test_geometry >("POLYGON((0 1,2 4))", "POLYGON((2 1,3 4))", 9.0); + test_geometry >("POLYGON((0 1,2 4))", "POLYGON((2 4,3 5))", 12.0); + +#ifdef HAVE_TTMATH + typedef bg::model::point P2ttmc; + typedef bg::model::point P3ttmc; + + test_geometry >("POLYGON((0 1,2 4))", "POLYGON((1 2,3 5))", 12.0); + test_geometry >("POLYGON((0 1 2,2 4 6))", "POLYGON((1 2 3,3 5 7))", 60.0); +#endif + + test_large_integers(); + + return 0; +}