|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r69087 - in sandbox-branches/geometry/index_080: boost/geometry/extensions/index/rtree tests
From: adam.wulkiewicz_at_[hidden]
Date: 2011-02-20 14:22:36
Author: awulkiew
Date: 2011-02-20 14:22:32 EST (Sun, 20 Feb 2011)
New Revision: 69087
URL: http://svn.boost.org/trac/boost/changeset/69087
Log:
tests redesigned
Added:
sandbox-branches/geometry/index_080/tests/main.cpp (contents, props changed)
sandbox-branches/geometry/index_080/tests/rtree_filters.hpp (contents, props changed)
sandbox-branches/geometry/index_080/tests/rtree_native.hpp (contents, props changed)
sandbox-branches/geometry/index_080/tests/translators.hpp (contents, props changed)
Text files modified:
sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree.hpp | 2 +-
sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree_node.hpp | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
Modified: sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree.hpp
==============================================================================
--- sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree.hpp (original)
+++ sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree.hpp 2011-02-20 14:22:32 EST (Sun, 20 Feb 2011)
@@ -315,7 +315,7 @@
inline std::deque<Value> find(Box const& box) const
{
std::deque<Value> result;
- m_root->find(box, result, false);
+ m_root->find(box, result, m_translator);
return result;
}
Modified: sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree_node.hpp
==============================================================================
--- sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree_node.hpp (original)
+++ sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree_node.hpp 2011-02-20 14:22:32 EST (Sun, 20 Feb 2011)
@@ -114,7 +114,8 @@
* If exact_match is true only return the elements having as
* key the box 'box'. Otherwise return everything inside 'box'.
*/
- virtual void find(Box const& box, std::deque<Value>& result, bool const exact_match, Translator const& tr)
+ // awulkiew - exact match case removed
+ virtual void find(Box const& box, std::deque<Value>& result, Translator const& tr)
{
for (typename node_map::const_iterator it = m_nodes.begin();
it != m_nodes.end(); ++it)
@@ -122,7 +123,7 @@
// awulkiew - is_overlapping changed to geometry::intersects
if (geometry::intersects(it->first, box))
{
- it->second->find(box, result, exact_match, tr);
+ it->second->find(box, result, tr);
}
}
}
Added: sandbox-branches/geometry/index_080/tests/main.cpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index_080/tests/main.cpp 2011-02-20 14:22:32 EST (Sun, 20 Feb 2011)
@@ -0,0 +1,13 @@
+
+#include <tests/translators.hpp>
+#include <tests/rtree_native.hpp>
+#include <tests/rtree_filters.hpp>
+
+int main()
+{
+ tests_translators_hpp();
+ tests_rtree_native_hpp();
+ tests_rtree_filters_hpp();
+
+ return 0;
+}
Added: sandbox-branches/geometry/index_080/tests/rtree_filters.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index_080/tests/rtree_filters.hpp 2011-02-20 14:22:32 EST (Sun, 20 Feb 2011)
@@ -0,0 +1,56 @@
+#ifndef TESTS_RTREE_FILTERS_HPP
+#define TESTS_RTREE_FILTERS_HPP
+
+#include <boost/geometry/geometry.hpp>
+#include <boost/geometry/extensions/index/rtree/rtree.hpp>
+
+#include <boost/geometry/extensions/index/rtree/filters.hpp>
+#include <boost/geometry/extensions/index/filters/nearest_filter.hpp>
+
+#include <iostream>
+
+#include <boost/range/algorithm.hpp>
+#include <boost/foreach.hpp>
+
+template <typename R>
+void tests_rtree_filters_hpp_print_range(R const& r)
+{
+ BOOST_FOREACH(typename boost::iterator_value<typename R::const_iterator>::type const& b, r)
+ {
+ float min_x = b.min_corner().template get<0>();
+ float min_y = b.min_corner().template get<1>();
+ float max_x = b.max_corner().template get<0>();
+ float max_y = b.max_corner().template get<1>();
+ std::cout << "(" << min_x << ", " << min_y << ")";
+ std::cout << 'x';
+ std::cout << "(" << max_x << ", " << max_y << ")";
+ std::cout << '\n';
+ }
+ std::cout << std::endl;
+}
+
+void tests_rtree_filters_hpp()
+{
+ std::cout << "tests\rtree_filters.hpp\n";
+
+ typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
+ typedef boost::geometry::model::box<P> B;
+
+ {
+ boost::geometry::index::rtree<B> t(3, 0);
+ t.insert(B(P(0, 0), P(1, 1)));
+ t.insert(B(P(2, 2), P(3, 3)));
+ t.insert(B(P(4, 4), P(5, 5)));
+ t.insert(B(P(6, 6), P(7, 7)));
+ t.print();
+
+ std::deque<B> res = t.find(B(P(2.5f, 2.5f), P(4.5f, 4.5f)));
+ tests_rtree_filters_hpp_print_range(res);
+
+ namespace f = boost::geometry::index::filters;
+ tests_rtree_filters_hpp_print_range(t | f::spatially_filtered(B(P(2.5f, 2.5f), P(4.5f, 4.5f))));
+ tests_rtree_filters_hpp_print_range(t | f::nearest_filtered(P(3.5f, 3.5f), 1.0f));
+ }
+}
+
+#endif // TESTS_RTREE_FILTERS_HPP
Added: sandbox-branches/geometry/index_080/tests/rtree_native.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index_080/tests/rtree_native.hpp 2011-02-20 14:22:32 EST (Sun, 20 Feb 2011)
@@ -0,0 +1,211 @@
+#ifndef TESTS_RTREE_NATIVE_HPP
+#define TESTS_RTREE_NATIVE_HPP
+
+#include <boost/geometry/geometry.hpp>
+
+#include <boost/geometry/extensions/index/rtree/rtree.hpp>
+#include <boost/geometry/extensions/index/translator/index.hpp>
+
+#include <iostream>
+
+#include <boost/range/algorithm.hpp>
+#include <boost/foreach.hpp>
+
+#include <map>
+
+void tests_rtree_native_hpp()
+{
+ std::cout << "tests\rtree_native.hpp\n";
+
+ // Box
+ {
+ typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
+ typedef boost::geometry::model::box<P> B;
+
+ boost::geometry::index::rtree<B> t(3, 0);
+ t.insert(B(P(0, 0), P(1, 1)));
+ t.insert(B(P(2, 2), P(3, 3)));
+ t.insert(B(P(4, 4), P(5, 5)));
+ t.insert(B(P(6, 6), P(7, 7)));
+ t.print();
+
+ // error
+ t.remove_in(B(P(-1, -1), P(2, 2)));
+ // ok
+ t.remove_in(B(P(0, 0), P(1, 1)));
+ t.print();
+
+ t.remove(B(P(6, 6), P(7, 7)));
+ t.print();
+ }
+
+ std::cout << "-------------------------------------------------\n";
+ std::cout << "-------------------------------------------------\n";
+
+ // Point
+ {
+ typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
+ typedef boost::geometry::model::box<P> B;
+
+ boost::geometry::index::rtree<P> t(3, 0);
+ t.insert(P(0, 0));
+ t.insert(P(2, 2));
+ t.insert(P(4, 4));
+ t.insert(P(6, 6));
+ t.print();
+
+ // error
+ t.remove_in(B(P(-1, -1), P(1, 1)));
+ // ok
+ t.remove_in(B(P(0, 0), P(0, 0)));
+ t.print();
+
+ t.remove(P(6, 6));
+ t.print();
+ }
+
+ std::cout << "-------------------------------------------------\n";
+ std::cout << "-------------------------------------------------\n";
+
+ // std::pair<Box, int>
+ {
+ typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
+ typedef boost::geometry::model::box<P> B;
+ typedef std::pair<B, int> V;
+
+ boost::geometry::index::rtree<V> t(3, 0);
+ t.insert(V(B(P(0, 0), P(1, 1)), 0));
+ t.insert(V(B(P(2, 2), P(3, 3)), 1));
+ t.insert(V(B(P(4, 4), P(5, 5)), 2));
+ t.insert(V(B(P(6, 6), P(7, 7)), 3));
+ t.print();
+
+ // error
+ t.remove_in(B(P(0, 0), P(2, 1)));
+ // ok
+ t.remove_in(B(P(0, 0), P(1, 1)));
+ t.print();
+
+ t.remove(V(B(P(6, 6), P(7, 7)), 3));
+ t.print();
+ }
+
+ std::cout << "-------------------------------------------------\n";
+ std::cout << "-------------------------------------------------\n";
+
+ // boost::shared_ptr< std::pair<Box, int> >
+ {
+ typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
+ typedef boost::geometry::model::box<P> B;
+
+ typedef boost::shared_ptr< std::pair<B, int> > V;
+
+ V v1( new std::pair<B, int>(B(P(0, 0), P(1, 1)), 0) );
+ V v2( new std::pair<B, int>(B(P(2, 2), P(3, 3)), 1) );
+ V v3( new std::pair<B, int>(B(P(4, 4), P(5, 5)), 2) );
+ V v4( new std::pair<B, int>(B(P(6, 6), P(7, 7)), 3) );
+
+ boost::geometry::index::rtree<V> t(3, 0);
+ t.insert(v1);
+ t.insert(v2);
+ t.insert(v3);
+ t.insert(v4);
+ t.print();
+
+ // error
+ t.remove_in(B(P(0, 0), P(2, 1)));
+ // ok
+ t.remove_in(B(P(0, 0), P(1, 1)));
+ t.print();
+
+ t.remove(v4);
+ t.print();
+ }
+
+ std::cout << "-------------------------------------------------\n";
+ std::cout << "-------------------------------------------------\n";
+
+ // std::map<int, Box>::iterator
+ {
+ typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
+ typedef boost::geometry::model::box<P> B;
+
+ typedef std::map<int, B>::iterator V;
+
+ std::map<int, B> m;
+ m.insert(std::pair<int, B>(0, B(P(0, 0), P(1, 1))));
+ m.insert(std::pair<int, B>(1, B(P(2, 2), P(3, 3))));
+ m.insert(std::pair<int, B>(2, B(P(4, 4), P(5, 5))));
+ m.insert(std::pair<int, B>(3, B(P(6, 6), P(7, 7))));
+
+ boost::geometry::index::rtree<V> t(3, 0);
+ V vit = m.begin();
+ t.insert(vit++);
+ t.insert(vit++);
+ t.insert(vit++);
+ t.insert(vit);
+ t.print();
+
+ // error
+ t.remove_in(B(P(0, 0), P(2, 1)));
+ // ok
+ t.remove_in(B(P(0, 0), P(1, 1)));
+ t.print();
+
+ t.remove(m.find(3));
+ t.print();
+ }
+
+ std::cout << "-------------------------------------------------\n";
+ std::cout << "-------------------------------------------------\n";
+
+ // size_t
+ {
+ typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
+ typedef boost::geometry::model::box<P> B;
+
+ typedef size_t V;
+ typedef boost::geometry::index::translator::index<std::vector<B> > T;
+
+ std::vector<B> v;
+ v.push_back(B(P(0, 0), P(1, 1)));
+ v.push_back(B(P(2, 2), P(3, 3)));
+ v.push_back(B(P(4, 4), P(5, 5)));
+ v.push_back(B(P(6, 6), P(7, 7)));
+
+ boost::geometry::index::rtree<V, T> t(3, 0, T(v));
+
+ t.insert(0);
+ t.insert(1);
+ t.insert(2);
+ t.insert(3);
+ t.print();
+
+ // error
+ t.remove_in(B(P(0, 0), P(2, 1)));
+ // ok
+ t.remove_in(B(P(0, 0), P(1, 1)));
+ t.print();
+
+ t.remove(3);
+ t.print();
+ }
+
+ {
+ typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
+ typedef boost::geometry::model::box<P> B;
+
+ boost::geometry::index::rtree<B>::rtree_leaf l;
+ boost::geometry::index::rtree<B>::rtree_node n;
+
+ std::cout << sizeof(boost::shared_ptr<int>) << '\n';
+ std::cout << sizeof(std::vector<int>) << '\n';
+ std::cout << sizeof(n) << '\n';
+ std::cout << sizeof(l) << '\n';
+ }
+
+ // ERROR!
+ // remove_in expects previously inserted box - it should remove all objects inside some bigger box
+}
+
+#endif // TESTS_RTREE_NATIVE_HPP
Added: sandbox-branches/geometry/index_080/tests/translators.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index_080/tests/translators.hpp 2011-02-20 14:22:32 EST (Sun, 20 Feb 2011)
@@ -0,0 +1,72 @@
+#ifndef TESTS_TRANSLATORS_HPP
+#define TESTS_TRANSLATORS_HPP
+
+#include <boost/geometry/geometry.hpp>
+#include <boost/geometry/extensions/index/rtree/rtree.hpp>
+
+#include <boost/geometry/extensions/index/translator/def.hpp>
+#include <boost/geometry/extensions/index/translator/index.hpp>
+
+#include <vector>
+#include <map>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/scoped_ptr.hpp>
+
+void tests_translators_hpp()
+{
+ std::cout << "tests\translators.hpp\n";
+
+ typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
+ typedef boost::geometry::model::box<P> B;
+ typedef boost::geometry::index::rtree<B> I;
+
+ using namespace boost::geometry;
+
+ index::translator::def<P> p;
+ index::translator::def<P*> pp;
+ index::translator::def<std::pair<int, P>*> pip;
+ index::translator::def< boost::shared_ptr<P> > sp;
+ index::translator::def< std::vector<P>::iterator > ip;
+ index::translator::def< std::map<int, P>::iterator > mip;
+ index::translator::def< std::pair<P, size_t> > ppi;
+ index::translator::def< boost::shared_ptr< std::pair<int, P> > > spip;
+ index::translator::def< boost::shared_ptr< std::pair<P, int> > > sppi;
+ index::translator::def< boost::scoped_ptr< std::pair<P, int> > > scppi;
+ index::translator::def< boost::scoped_ptr< std::pair<int, P> > > scpip;
+
+ P tmp_p;
+ boost::shared_ptr<P> tmp_sp(new P());
+ std::vector<P> tmp_v(1);
+ std::map<int, P> tmp_m;
+ tmp_m.insert(std::pair<int, P>(0, P()));
+ std::pair<int, P> tmp_pip;
+ boost::shared_ptr< std::pair<int, P> > tmp_spip(new std::pair<int, P>(0, P()));
+ boost::shared_ptr< std::pair<P, int> > tmp_sppi(new std::pair<P, int>(P(), 0));
+ boost::scoped_ptr< std::pair<int, P> > tmp_scpip(new std::pair<int, P>(0, P()));
+ boost::scoped_ptr< std::pair<P, int> > tmp_scppi(new std::pair<P, int>(P(), 0));
+
+ tmp_p = p(P());
+ tmp_p = pp(&tmp_p);
+ tmp_p = pip(&tmp_pip);
+ tmp_p = sp(tmp_sp);
+ tmp_p = ip(tmp_v.begin());
+ tmp_p = mip(tmp_m.begin());
+ tmp_p = ppi(std::pair<P, size_t>(P(), 0));
+ tmp_p = spip(tmp_spip);
+ tmp_p = sppi(tmp_sppi);
+ tmp_p = scpip(tmp_scpip);
+ tmp_p = scppi(tmp_scppi);
+
+ //index::translator::def<int> d; // error
+ //index::translator::def< model::segment<P> > d; // error
+
+ index::translator::def< std::pair<model::polygon<P>, B> > d;
+ index::translator::def< std::pair<B, model::polygon<P> > > dd;
+
+ B tmp_b;
+ tmp_b = d( std::pair<model::polygon<P>, B>() );
+ tmp_b = dd( std::pair<B, model::polygon<P> >() );
+}
+
+#endif // TESTS_TRANSLATORS_HPP
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk