Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71308 - in trunk/libs/geometry/test/algorithms: . detail
From: barend.gehrels_at_[hidden]
Date: 2011-04-16 07:29:28


Author: barendgehrels
Date: 2011-04-16 07:29:26 EDT (Sat, 16 Apr 2011)
New Revision: 71308
URL: http://svn.boost.org/trac/boost/changeset/71308

Log:
Added omitted _rev
Text files modified:
   trunk/libs/geometry/test/algorithms/assign.cpp | 6
   trunk/libs/geometry/test/algorithms/detail/partition.cpp | 258 +++++++++++++++++++++++++++++++++++++++
   2 files changed, 258 insertions(+), 6 deletions(-)

Modified: trunk/libs/geometry/test/algorithms/assign.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/assign.cpp (original)
+++ trunk/libs/geometry/test/algorithms/assign.cpp 2011-04-16 07:29:26 EDT (Sat, 16 Apr 2011)
@@ -143,7 +143,7 @@
     bg::assign_values(p, 1, 2);
 
     box_type b;
- bg::assign(b, p);
+ bg::assign_rev(b, p);
 
     BOOST_CHECK_CLOSE((bg::get<0, 0>(b)), 1.0, 0.001);
     BOOST_CHECK_CLOSE((bg::get<0, 1>(b)), 2.0, 0.001);
@@ -157,7 +157,7 @@
     bg::set<bg::max_corner, 1>(b, 4);
         
     ring_type ring;
- bg::assign(ring, b);
+ bg::assign_rev(ring, b);
 
     //std::cout << bg::wkt(b) << std::endl;
     //std::cout << bg::wkt(ring) << std::endl;
@@ -183,7 +183,7 @@
 
     polygon_type polygon;
 
- bg::assign(polygon, ring);
+ bg::assign_rev(polygon, ring);
     BOOST_CHECK_EQUAL(bg::num_points(polygon), 5u);
 
     bg::assign_rev(ring, polygon);

Modified: trunk/libs/geometry/test/algorithms/detail/partition.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/detail/partition.cpp (original)
+++ trunk/libs/geometry/test/algorithms/detail/partition.cpp 2011-04-16 07:29:26 EDT (Sat, 16 Apr 2011)
@@ -9,18 +9,24 @@
 
 #include <algorithms/test_overlay.hpp>
 
-#include <boost/range/algorithm/copy.hpp>
 
 #include <boost/geometry/geometry.hpp>
 #include <boost/geometry/multi/geometries/multi_point.hpp>
 #include <boost/geometry/geometries/register/point.hpp>
 
-#include <boost/geometry/algorithms/detail/overlay/select_rings.hpp>
-#include <boost/geometry/algorithms/detail/overlay/assign_parents.hpp>
 #include <boost/geometry/algorithms/detail/partition.hpp>
 
 #include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
 
+#if defined(TEST_WITH_SVG)
+# include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+#endif
+
+#include <boost/random/linear_congruential.hpp>
+#include <boost/random/uniform_int.hpp>
+#include <boost/random/uniform_real.hpp>
+#include <boost/random/variate_generator.hpp>
+
 
 template <typename Box>
 struct box_item
@@ -214,6 +220,237 @@
 
 }
 
+//------------------- higher volumes
+
+template <typename SvgMapper>
+struct svg_visitor
+{
+ SvgMapper& m_mapper;
+
+ svg_visitor(SvgMapper& mapper)
+ : m_mapper(mapper)
+ {}
+
+ template <typename Box>
+ inline void apply(Box const& box, int level)
+ {
+ /*
+ std::string color("rgb(64,64,64)");
+ switch(level)
+ {
+ case 0 : color = "rgb(255,0,0)"; break;
+ case 1 : color = "rgb(0,255,0)"; break;
+ case 2 : color = "rgb(0,0,255)"; break;
+ case 3 : color = "rgb(255,255,0)"; break;
+ case 4 : color = "rgb(255,0,255)"; break;
+ case 5 : color = "rgb(0,255,255)"; break;
+ case 6 : color = "rgb(255,128,0)"; break;
+ case 7 : color = "rgb(0,128,255)"; break;
+ }
+ std::ostringstream style;
+ style << "fill:none;stroke-width:" << (5.0 - level / 2.0) << ";stroke:" << color << ";";
+ m_mapper.map(box, style.str());
+ */
+ m_mapper.map(box, "fill:none;stroke-width:2;stroke:rgb(0,0,0);");
+
+ }
+};
+
+
+
+
+template <typename Collection>
+void fill_points(Collection& collection, int seed, int size, int count)
+{
+ typedef boost::minstd_rand base_generator_type;
+
+ base_generator_type generator(seed);
+
+ boost::uniform_int<> random_coordinate(0, size - 1);
+ boost::variate_generator<base_generator_type&, boost::uniform_int<> >
+ coordinate_generator(generator, random_coordinate);
+
+ std::set<std::pair<int, int> > included;
+
+ int n = 0;
+ for (int i = 0; n < count && i < count*count; i++)
+ {
+ int x = coordinate_generator();
+ int y = coordinate_generator();
+ std::pair<int, int> pair = std::make_pair(x, y);
+ if (included.find(pair) == included.end())
+ {
+ included.insert(pair);
+ typename boost::range_value<Collection>::type item;
+ item.x = x;
+ item.y = y;
+ collection.push_back(item);
+ n++;
+ }
+ }
+}
+
+void test_many_points(int seed, int size, int count)
+{
+ bg::model::multi_point<point_item> mp1, mp2;
+
+ fill_points(mp1, seed, size, count);
+ fill_points(mp2, seed * 2, size, count);
+
+ // Test equality in quadratic loop
+ int expected_count = 0;
+ BOOST_FOREACH(point_item const& item1, mp1)
+ {
+ BOOST_FOREACH(point_item const& item2, mp2)
+ {
+ if (bg::equals(item1, item2))
+ {
+ expected_count++;
+ }
+ }
+ }
+
+#if defined(TEST_WITH_SVG)
+ std::ostringstream filename;
+ filename << "partition" << seed << ".svg";
+ std::ofstream svg(filename.str().c_str());
+
+ bg::svg_mapper<point_item> mapper(svg, 800, 800);
+
+ {
+ point_item p;
+ p.x = -1; p.y = -1; mapper.add(p);
+ p.x = size + 1; p.y = size + 1; mapper.add(p);
+ }
+
+ typedef svg_visitor<bg::svg_mapper<point_item> > box_visitor_type;
+ box_visitor_type box_visitor(mapper);
+#else
+ typedef visit_no_policy box_visitor_type;
+ visit_no_policy box_visitor;
+#endif
+
+ point_visitor visitor;
+ bg::partition
+ <
+ bg::model::box<point_item>, get_point, ovelaps_point,
+ box_visitor_type
+ >::apply(mp1, mp2, visitor, 2, box_visitor);
+
+ BOOST_CHECK_EQUAL(visitor.count, expected_count);
+
+#if defined(TEST_WITH_SVG)
+ BOOST_FOREACH(point_item const& item, mp1)
+ {
+ mapper.map(item, "fill:rgb(255,128,0);stroke:rgb(0,0,100);stroke-width:1", 8);
+ }
+ BOOST_FOREACH(point_item const& item, mp2)
+ {
+ mapper.map(item, "fill:rgb(0,128,255);stroke:rgb(0,0,100);stroke-width:1", 4);
+ }
+#endif
+}
+
+template <typename Collection>
+void fill_boxes(Collection& collection, int seed, int size, int count)
+{
+ typedef boost::minstd_rand base_generator_type;
+
+ base_generator_type generator(seed);
+
+ boost::uniform_int<> random_coordinate(0, size * 10 - 1);
+ boost::variate_generator<base_generator_type&, boost::uniform_int<> >
+ coordinate_generator(generator, random_coordinate);
+
+ int n = 0;
+ for (int i = 0; n < count && i < count*count; i++)
+ {
+ int w = coordinate_generator() % 30;
+ int h = coordinate_generator() % 30;
+ if (w > 0 && h > 0)
+ {
+ int x = coordinate_generator();
+ int y = coordinate_generator();
+ if (x + w < size * 10 && y + h < size * 10)
+ {
+ typename boost::range_value<Collection>::type item(n+1);
+ bg::assign_values(item.box, x / 10.0, y / 10.0, (x + w) / 10.0, (y + h) / 10.0);
+ collection.push_back(item);
+ n++;
+ }
+ }
+ }
+}
+
+
+
+void test_many_boxes(int seed, int size, int count)
+{
+ typedef bg::model::box<point_item> box_type;
+ std::vector<box_item<box_type> > boxes;
+
+ fill_boxes(boxes, seed, size, count);
+
+ // Test equality in quadratic loop
+ int expected_count = 0;
+ double expected_area = 0.0;
+ BOOST_FOREACH(box_item<box_type> const& item1, boxes)
+ {
+ BOOST_FOREACH(box_item<box_type> const& item2, boxes)
+ {
+ if (item1.id < item2.id)
+ {
+ if (bg::intersects(item1.box, item2.box))
+ {
+ box_type b;
+ bg::intersection(item1.box, item2.box, b);
+ expected_area += bg::area(b);
+ expected_count++;
+ }
+ }
+ }
+ }
+
+
+#if defined(TEST_WITH_SVG)
+ std::ostringstream filename;
+ filename << "partition_box_" << seed << ".svg";
+ std::ofstream svg(filename.str().c_str());
+
+ bg::svg_mapper<point_item> mapper(svg, 800, 800);
+
+ {
+ point_item p;
+ p.x = -1; p.y = -1; mapper.add(p);
+ p.x = size + 1; p.y = size + 1; mapper.add(p);
+ }
+
+ BOOST_FOREACH(box_item<box_type> const& item, boxes)
+ {
+ mapper.map(item.box, "opacity:0.6;fill:rgb(50,50,210);stroke:rgb(0,0,0);stroke-width:1");
+ }
+
+ typedef svg_visitor<bg::svg_mapper<point_item> > partition_visitor_type;
+ partition_visitor_type partition_visitor(mapper);
+#else
+ typedef visit_no_policy box_visitor_type;
+ visit_no_policy partition_visitor;
+#endif
+
+
+ box_visitor<box_type> visitor;
+ bg::partition
+ <
+ box_type, get_box, ovelaps_box,
+ partition_visitor_type
+ >::apply(boxes, visitor, 2, partition_visitor);
+
+ BOOST_CHECK_EQUAL(visitor.count, expected_count);
+ BOOST_CHECK_CLOSE(visitor.area, expected_area, 0.001);
+
+}
+
+
 
 
 
@@ -221,5 +458,20 @@
 {
     test_all<bg::model::d2::point_xy<double> >();
 
+ test_many_points(12345, 20, 40);
+ test_many_points(54321, 20, 60);
+ test_many_points(67890, 20, 80);
+ test_many_points(98765, 20, 100);
+ for (int i = 1; i < 10; i++)
+ {
+ test_many_points(i, 30, i * 20);
+ }
+
+ test_many_boxes(12345, 20, 40);
+ for (int i = 1; i < 10; i++)
+ {
+ test_many_boxes(i, 20, i * 10);
+ }
+
     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