Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75556 - trunk/libs/geometry/test/algorithms
From: barend.gehrels_at_[hidden]
Date: 2011-11-19 11:39:57


Author: barendgehrels
Date: 2011-11-19 11:39:56 EST (Sat, 19 Nov 2011)
New Revision: 75556
URL: http://svn.boost.org/trac/boost/changeset/75556

Log:
Linestring/polygon overlay, unit tests for second phase
Text files modified:
   trunk/libs/geometry/test/algorithms/intersection.cpp | 38 ++++++++++++++++++++------
   trunk/libs/geometry/test/algorithms/test_intersection.hpp | 56 ++++++++++++++++++++++++++++++++-------
   2 files changed, 75 insertions(+), 19 deletions(-)

Modified: trunk/libs/geometry/test/algorithms/intersection.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/intersection.cpp (original)
+++ trunk/libs/geometry/test/algorithms/intersection.cpp 2011-11-19 11:39:56 EST (Sat, 19 Nov 2011)
@@ -15,7 +15,10 @@
 #include <iostream>
 #include <string>
 
+//#define BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER
+//#define BOOST_GEOMETRY_DEBUG_INTERSECTION
 //#define BOOST_GEOMETRY_DEBUG_TRAVERSE
+//#define BOOST_GEOMETRY_DEBUG_FOLLOW
 //#define BOOST_GEOMETRY_DEBUG_ASSEMBLE
 //#define BOOST_GEOMETRY_DEBUG_IDENTIFIER
 
@@ -287,17 +290,33 @@
 void test_polygon_linestring()
 {
     std::string const poly_simplex = "POLYGON((1 1,1 3,3 3,3 1,1 1))";
- test_one<LineString, Polygon, LineString>("simplex", poly_simplex, "LINESTRING(0 2,4 2)", 1, 2, 2.0);
- test_one<LineString, Polygon, LineString>("case2", poly_simplex, "LINESTRING(0 1,4 3)", 1, 2, sqrt(5.0));
- test_one<LineString, Polygon, LineString>("case3", "POLYGON((2 0,2 5,5 5,5 0,2 0))", "LINESTRING(0 1,1 2,3 2,4 3,6 3,7 4)", 1, 4, 2 + sqrt(2.0));
- test_one<LineString, Polygon, LineString>("case4", "POLYGON((0 0,0 4,2 4,2 0,0 0))", "LINESTRING(1 1,3 2,1 3)", 2, 4, sqrt(5.0));
+ std::string const poly_9 = "POLYGON((1 1,1 4,4 4,4 1,1 1))";
+
+ test_one_lp<LineString, Polygon, LineString>("simplex", poly_simplex, "LINESTRING(0 2,4 2)", 1, 2, 2.0);
+ test_one_lp<LineString, Polygon, LineString>("case2", poly_simplex, "LINESTRING(0 1,4 3)", 1, 2, sqrt(5.0));
+ test_one_lp<LineString, Polygon, LineString>("case3", "POLYGON((2 0,2 5,5 5,5 0,2 0))", "LINESTRING(0 1,1 2,3 2,4 3,6 3,7 4)", 1, 4, 2 + sqrt(2.0));
+ test_one_lp<LineString, Polygon, LineString>("case4", "POLYGON((0 0,0 4,2 4,2 0,0 0))", "LINESTRING(1 1,3 2,1 3)", 2, 4, sqrt(5.0));
 
- test_one<LineString, Polygon, LineString>("case5", poly_simplex, "LINESTRING(0 1,3 4)", 1, 2, sqrt(2.0));
- test_one<LineString, Polygon, LineString>("case6", "POLYGON((2 0,2 4,3 4,3 1,4 1,4 3,5 3,5 1,6 1,6 3,7 3,7 1,8 1,8 3,9 3,9 0,2 0))", "LINESTRING(1 1,10 3)", 4, 8,
+ test_one_lp<LineString, Polygon, LineString>("case5", poly_simplex, "LINESTRING(0 1,3 4)", 1, 2, sqrt(2.0));
+ test_one_lp<LineString, Polygon, LineString>("case6", "POLYGON((2 0,2 4,3 4,3 1,4 1,4 3,5 3,5 1,6 1,6 3,7 3,7 1,8 1,8 3,9 3,9 0,2 0))", "LINESTRING(1 1,10 3)", 4, 8,
             // Pieces are 1 x 2/9:
             4.0 * sqrt(1.0 + 4.0/81.0));
- test_one<LineString, Polygon, LineString>("case7", poly_simplex, "LINESTRING(1.5 1.5,2.5 2.5)", 1, 2, sqrt(2.0));
- test_one<LineString, Polygon, LineString>("case8", poly_simplex, "LINESTRING(1 0,2 0)", 0, 0, 0.0);
+ test_one_lp<LineString, Polygon, LineString>("case7", poly_simplex, "LINESTRING(1.5 1.5,2.5 2.5)", 1, 2, sqrt(2.0));
+ test_one_lp<LineString, Polygon, LineString>("case8", poly_simplex, "LINESTRING(1 0,2 0)", 0, 0, 0.0);
+
+ test_one_lp<LineString, Polygon, LineString>("case9", poly_9, "LINESTRING(0 1,1 2,2 2)", 1, 2, 1.0);
+ test_one_lp<LineString, Polygon, LineString>("case10", poly_9, "LINESTRING(0 1,1 2,0 2)", 0, 0, 0.0);
+ test_one_lp<LineString, Polygon, LineString>("case11", poly_9, "LINESTRING(2 2,4 2,3 3)", 1, 3, 2.0 + sqrt(2.0));
+ test_one_lp<LineString, Polygon, LineString>("case12", poly_9, "LINESTRING(2 3,4 4,5 6)", 1, 2, sqrt(5.0));
+
+ test_one_lp<LineString, Polygon, LineString>("case13", poly_9, "LINESTRING(3 2,4 4,2 3)", 1, 3, 2.0 * sqrt(5.0));
+ test_one_lp<LineString, Polygon, LineString>("case14", poly_9, "LINESTRING(5 6,4 4,6 5)", 0, 0, 0.0);
+ //test_one_lp<LineString, Polygon, LineString>("case15", poly_9, "LINESTRING(0 2,1 2,1 3,0 3)", 1, 2, 1.0);
+ //test_one_lp<LineString, Polygon, LineString>("case16", poly_9, "LINESTRING(2 2,1 2,1 3,2 3)", 1, 4, 3.0);
+
+ // Compile test - arguments in any order:
+ test_one<LineString, Polygon, LineString>("simplex", poly_simplex, "LINESTRING(0 2,4 2)", 1, 2, 2.0);
+ test_one<LineString, LineString, Polygon>("simplex", "LINESTRING(0 2,4 2)", poly_simplex, 1, 2, 2.0);
 }
 
 
@@ -315,6 +334,8 @@
 
     std::string clip = "box(2 2,8 8)";
 
+ test_polygon_linestring<polygon, linestring>();
+
     // Test polygons clockwise and counter clockwise
     test_areal<polygon>();
 
@@ -322,7 +343,6 @@
     test_areal<polygon_open>();
     test_areal<polygon_ccw_open>();
 
- test_polygon_linestring<polygon, linestring>();
 
     test_areal_clip<polygon, box>();
     test_areal_clip<polygon_ccw, box>();

Modified: trunk/libs/geometry/test/algorithms/test_intersection.hpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/test_intersection.hpp (original)
+++ trunk/libs/geometry/test/algorithms/test_intersection.hpp 2011-11-19 11:39:56 EST (Sat, 19 Nov 2011)
@@ -39,11 +39,15 @@
         G1 const& g1, G2 const& g2,
         std::size_t expected_count = 0, std::size_t expected_point_count = 0,
         double expected_length_or_area = 0,
- double percentage = 0.0001)
+ double percentage = 0.0001,
+ bool debug = false)
 {
     static const bool is_line = bg::geometry_id<OutputType>::type::value == 2;
 
- //std::cout << caseid << std::endl;
+ if (debug)
+ {
+ std::cout << std::endl << "case " << caseid << std::endl;
+ }
 
 
     typedef typename bg::coordinate_type<G1>::type coordinate_type;
@@ -83,12 +87,10 @@
             ? bg::length(*it)
             : bg::area(*it);
 
- /*
- std::cout << std::endl << "case " << caseid << " ";
- std::cout
- << std::setprecision(20)
- << bg::dsv(*it) << std::endl;
- */
+ if (debug)
+ {
+ std::cout << std::setprecision(20) << bg::wkt(*it) << std::endl;
+ }
     }
 
 
@@ -159,6 +161,11 @@
     }
 #endif
 
+ if (debug)
+ {
+ std::cout << "end case " << caseid << std::endl;
+ }
+
     return length_or_area;
 }
 
@@ -167,7 +174,8 @@
         std::string const& wkt1, std::string const& wkt2,
         std::size_t expected_count = 0, std::size_t expected_point_count = 0,
         double expected_length_or_area = 0,
- double percentage = 0.0001)
+ double percentage = 0.0001,
+ bool debug = false)
 {
     G1 g1;
     bg::read_wkt(wkt1, g1);
@@ -181,7 +189,35 @@
 
     return test_intersection<OutputType, void>(caseid, g1, g2,
         expected_count, expected_point_count,
- expected_length_or_area, percentage);
+ expected_length_or_area, percentage,
+ debug);
+}
+
+template <typename OutputType, typename Areal, typename Linear>
+void test_one_lp(std::string const& caseid,
+ std::string const& wkt_areal, std::string const& wkt_linear,
+ std::size_t expected_count = 0, std::size_t expected_point_count = 0,
+ double expected_length = 0,
+ double percentage = 0.0001,
+ bool debug1 = false, bool debug2 = false)
+{
+ Areal areal;
+ bg::read_wkt(wkt_areal, areal);
+ bg::correct(areal);
+
+ Linear linear;
+ bg::read_wkt(wkt_linear, linear);
+
+ test_intersection<OutputType, void>(caseid, areal, linear,
+ expected_count, expected_point_count,
+ expected_length, percentage, debug1);
+
+ // A linestring reversed should deliver exactly the same.
+ bg::reverse(linear);
+
+ test_intersection<OutputType, void>(caseid, areal, linear,
+ expected_count, expected_point_count,
+ expected_length, percentage, debug2);
 }
 
 template <typename Geometry1, typename Geometry2>


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