Boost logo

Boost-Commit :

From: mariano.consoni_at_[hidden]
Date: 2008-06-05 09:55:25


Author: mconsoni
Date: 2008-06-05 09:55:24 EDT (Thu, 05 Jun 2008)
New Revision: 46167
URL: http://svn.boost.org/trac/boost/changeset/46167

Log:
- Integrated with the Geometry Library Proposal.

Text files modified:
   sandbox/SOC/2008/spacial_indexing/libs/spatial_index/test/random_test.cpp | 117 ++++++++++++++++++++-------------------
   1 files changed, 59 insertions(+), 58 deletions(-)

Modified: sandbox/SOC/2008/spacial_indexing/libs/spatial_index/test/random_test.cpp
==============================================================================
--- sandbox/SOC/2008/spacial_indexing/libs/spatial_index/test/random_test.cpp (original)
+++ sandbox/SOC/2008/spacial_indexing/libs/spatial_index/test/random_test.cpp 2008-06-05 09:55:24 EDT (Thu, 05 Jun 2008)
@@ -15,6 +15,9 @@
 
 #include <sys/time.h>
 
+#define MAX_X 2000.0
+#define MAX_Y 2000.0
+
 
 double drandom(unsigned int upper_bound)
 {
@@ -35,63 +38,61 @@
 
 int test_main(int, char* [])
 {
- // data and indexed points
- std::vector<unsigned int> ids;
- std::vector<std::pair<double, double> > points;
-
- // plane
- const double max_x = 2000.0;
- const double max_y = 2000.0;
-
- // number of points
- const unsigned int points_count = 500;
-
- // number of points to find on the search phase
- const unsigned int find_count = 50;
-
- boost::shared_ptr< boost::spatial_index::spatial_index< std::pair<double, double> , std::vector<unsigned int>::iterator > >
- q(new boost::spatial_index::quadtree< std::pair<double, double> ,
- std::vector<unsigned int>::iterator >(0.0, 0.0, max_x, max_y));
-
- // generate random data
- for(unsigned int i = 0; i < points_count; i++) {
- double x = drandom((int) max_x);
- double y = drandom((int) max_y);
-
- ids.push_back(i);
- points.push_back(std::make_pair(x, y));
-
-// std::cerr << "insert " << i << " -> (" << x << ", " << y << ")" << std::endl;
- }
-
- // insert data
- std::cerr << " --> bulk insert" << std::endl;
- std::vector<unsigned int>::iterator b, e;
- b = ids.begin();
- e = ids.end();
- q->bulk_insert(b,e, points);
-
- // search
- std::vector<std::pair<double,double> > search_positions;
- std::vector<unsigned int> search_data;
-
- // compute random positions to do the searches, store the data
- for(unsigned int j=0; j < find_count; j++) {
- unsigned int pos = (int) drandom(points_count);
- search_positions.push_back(points[pos]);
- search_data.push_back(pos);
- }
-
- // search data and compare
- for(unsigned int j=0; j < find_count; j++) {
- std::vector<unsigned int>::iterator it = q->find(search_positions[j]);
- std::cout << search_data[j]
- << " - found in (" << search_positions[j].first << "," << search_positions[j].second
- << ") --> " << *it << std::endl;
-
- // check if the retrieved data is equal to the stored data
- BOOST_CHECK_EQUAL(*it, search_data[j]);
- }
+ // data and indexed points
+ std::vector<unsigned int> ids;
+ std::vector<geometry::point_xy<double> > points;
+
+ // plane
+ geometry::box<geometry::point_xy<double> > plane(geometry::point_xy<double>(0.0, 0.0), geometry::point_xy<double>(MAX_X, MAX_Y));
+
+ // number of points
+ const unsigned int points_count = 500;
+
+ // number of points to find on the search phase
+ const unsigned int find_count = 50;
+
+ boost::shared_ptr< boost::spatial_index::spatial_index< geometry::point_xy<double> , std::vector<unsigned int>::iterator > >
+ q(new boost::spatial_index::quadtree< geometry::point_xy<double>, std::vector<unsigned int>::iterator >(plane));
+
+ // generate random data
+ for(unsigned int i = 0; i < points_count; i++) {
+ double x = drandom((int) MAX_X);
+ double y = drandom((int) MAX_Y);
+
+ ids.push_back(i);
+ points.push_back(geometry::point_xy<double>(x, y));
+
+ // std::cerr << "insert " << i << " -> (" << x << ", " << y << ")" << std::endl;
+ }
+
+ // insert data
+ std::cerr << " --> bulk insert" << std::endl;
+ std::vector<unsigned int>::iterator b, e;
+ b = ids.begin();
+ e = ids.end();
+ q->bulk_insert(b,e, points);
+
+ // search
+ std::vector<geometry::point_xy<double> > search_positions;
+ std::vector<unsigned int> search_data;
+
+ // compute random positions to do the searches, store the data
+ for(unsigned int j=0; j < find_count; j++) {
+ unsigned int pos = (int) drandom(points_count);
+ search_positions.push_back(points[pos]);
+ search_data.push_back(pos);
+ }
+
+ // search data and compare
+ for(unsigned int j=0; j < find_count; j++) {
+ std::vector<unsigned int>::iterator it = q->find(search_positions[j]);
+ std::cout << search_data[j]
+ << " - found in (" << geometry::get<0>(search_positions[j]) << "," << geometry::get<1>(search_positions[j])
+ << ") --> " << *it << std::endl;
+
+ // check if the retrieved data is equal to the stored data
+ BOOST_CHECK_EQUAL(*it, search_data[j]);
+ }
 
- return 0;
+ return 0;
 }


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