Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67474 - in sandbox/geometry/libs/geometry/test/algorithms: . overlay/robustness
From: barend.gehrels_at_[hidden]
Date: 2010-12-28 11:40:20


Author: barendgehrels
Date: 2010-12-28 11:40:15 EST (Tue, 28 Dec 2010)
New Revision: 67474
URL: http://svn.boost.org/trac/boost/changeset/67474

Log:
Added test for box/box -> box intersection
Text files modified:
   sandbox/geometry/libs/geometry/test/algorithms/intersection.cpp | 27 +++++++++++++++++++++++++--
   sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/test_overlay_p_q.hpp | 11 +++++++++++
   sandbox/geometry/libs/geometry/test/algorithms/test_intersection.hpp | 7 ++++++-
   3 files changed, 42 insertions(+), 3 deletions(-)

Modified: sandbox/geometry/libs/geometry/test/algorithms/intersection.cpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/algorithms/intersection.cpp (original)
+++ sandbox/geometry/libs/geometry/test/algorithms/intersection.cpp 2010-12-28 11:40:15 EST (Tue, 28 Dec 2010)
@@ -188,6 +188,24 @@
             "POLYGON((2 2, 1 4, 2 4, 3 3, 2 2))", 1, 4, 0.75);
 }
 
+template <typename Box>
+void test_boxes(std::string const& wkt1, std::string const& wkt2, double expected_area, bool expected_result)
+{
+ Box box1, box2;
+ bg::read_wkt(wkt1, box1);
+ bg::read_wkt(wkt2, box2);
+
+ Box box_out;
+ bool detected = bg::intersection(box1, box2, box_out);
+ double area = bg::area(box_out);
+
+ BOOST_CHECK_EQUAL(detected, expected_result);
+ if (detected && expected_result)
+ {
+ BOOST_CHECK_CLOSE(area, expected_area, 0.01);
+ }
+}
+
 
 template <typename P>
 void test_all()
@@ -224,7 +242,7 @@
         1, 7, 5.47363293);
 #endif
 
- // Basic check: box/linestring, is clipping OK? should compile in any order
+ // Basic check: box/linestring, is clipping OK? should compile in any order
     test_one<linestring, linestring, box>("llb", "LINESTRING(0 0,10 10)", clip, 1, 2, sqrt(2.0 * 6.0 * 6.0));
     test_one<linestring, box, linestring>("lbl", clip, "LINESTRING(0 0,10 10)", 1, 2, sqrt(2.0 * 6.0 * 6.0));
 
@@ -248,7 +266,7 @@
     // Outputting two lines (because of 3-4-5 constructions (0.3,0.4,0.5)
     // which occur 4 times, the length is expected to be 2.0)
     test_one<linestring, linestring, box>("llb_2", "LINESTRING(1.7 1.6,2.3 2.4,2.9 1.6,3.5 2.4,4.1 1.6)", clip, 2, 6, 4 * 0.5);
-
+
 
 
 
@@ -260,6 +278,10 @@
     // polygons outputing points
     //test_one<P, polygon, polygon>("ppp1", simplex_normal[0], simplex_normal[1], 1, 7, 5.47363293);
 
+ test_boxes<box>("box(2 2,8 8)", "box(4 4,10 10)", 16, true);
+ test_boxes<box>("box(2 2,8 7)", "box(4 4,10 10)", 12, true);
+ test_boxes<box>("box(2 2,8 7)", "box(14 4,20 10)", 0, false);
+ test_boxes<box>("box(2 2,4 4)", "box(4 4,8 8)", 0, true);
 
 
     /*
@@ -319,3 +341,4 @@
     //test_pointer_version();
     return 0;
 }
+

Modified: sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/test_overlay_p_q.hpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/test_overlay_p_q.hpp (original)
+++ sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/test_overlay_p_q.hpp 2010-12-28 11:40:15 EST (Tue, 28 Dec 2010)
@@ -94,6 +94,14 @@
 
     }
 
+ // For POSTGIS output
+ /***
+ std::cout
+ << "union select " << area_i << " as bg,ST_area(ST_Intersection(ST_GeomFromText('" << bg::wkt(p) << "'), ST_GeomFromText('" << bg::wkt(q) << "'))) as pg" << std::endl
+ << "union select " << area_u << " as bg,ST_area(ST_Union(ST_GeomFromText('" << bg::wkt(p) << "'), ST_GeomFromText('" << bg::wkt(q) << "'))) as pg" << std::endl
+ << std::endl;
+ ***/
+
 
     if(svg)
     {
@@ -110,6 +118,9 @@
         mapper.add(p);
         mapper.add(q);
 
+ //mapper.add(point_type(0,0));
+ //mapper.add(point_type(3,3));
+
         // Input shapes in green/blue
         mapper.map(p, "fill-opacity:0.5;fill:rgb(153,204,0);"
                 "stroke:rgb(153,204,0);stroke-width:3");

Modified: sandbox/geometry/libs/geometry/test/algorithms/test_intersection.hpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/algorithms/test_intersection.hpp (original)
+++ sandbox/geometry/libs/geometry/test/algorithms/test_intersection.hpp 2010-12-28 11:40:15 EST (Tue, 28 Dec 2010)
@@ -46,7 +46,6 @@
 
     //std::cout << caseid << std::endl;
 
- std::vector<OutputType> clip;
 
     typedef typename bg::coordinate_type<G1>::type coordinate_type;
     typedef typename bg::point_type<G1>::type point_type;
@@ -60,6 +59,12 @@
             CalculationType
> strategy;
 
+ // Check both normal behaviour, and _inserter behaviour
+ {
+ std::vector<OutputType> out;
+ bg::intersection(g1, g2, out);
+ }
+ std::vector<OutputType> clip;
     bg::intersection_inserter<OutputType>(g1, g2, std::back_inserter(clip), strategy());
 
 


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