Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72030 - trunk/libs/geometry/test/algorithms
From: barend.gehrels_at_[hidden]
Date: 2011-05-18 14:09:21


Author: barendgehrels
Date: 2011-05-18 14:09:20 EDT (Wed, 18 May 2011)
New Revision: 72030
URL: http://svn.boost.org/trac/boost/changeset/72030

Log:
Fixed geometry::equals for high precision - testcase
(in this fix also the case that very first point is redundant is fixed)
Text files modified:
   trunk/libs/geometry/test/algorithms/equals.cpp | 57 +++++++++++++++++++++++++++++++++++++--
   1 files changed, 53 insertions(+), 4 deletions(-)

Modified: trunk/libs/geometry/test/algorithms/equals.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/equals.cpp (original)
+++ trunk/libs/geometry/test/algorithms/equals.cpp 2011-05-18 14:09:20 EDT (Wed, 18 May 2011)
@@ -21,15 +21,13 @@
     typedef bg::model::polygon<P> polygon;
     typedef bg::model::linestring<P> linestring;
 
+ std::string case_p1 = "POLYGON((0 0,0 2,2 2,0 0))";
 
     test_geometry<P, P>("p1", "POINT(1 1)", "POINT(1 1)", true);
     test_geometry<P, P>("p2", "POINT(1 1)", "POINT(1 2)", false);
     test_geometry<box, box>("b1", "BOX(1 1,2 2)", "BOX(1 2,2 2)", false);
     test_geometry<box, box>("b1", "BOX(1 2,3 4)", "BOX(1 2,3 4)", true);
 
-
- std::string case_p1 = "POLYGON((0 0,0 2,2 2,0 0))";
-
     // Completely equal
     test_geometry<ring, ring>("poly_eq", case_p1, case_p1, true);
 
@@ -39,7 +37,14 @@
 
     // Extra coordinate
     test_geometry<ring, ring>("poly_extra", case_p1, "POLYGON((0 0,0 2,2 2,1 1,0 0))", true);
- // Degenerate points
+
+ // Shifted + extra (redundant) coordinate
+ test_geometry<ring, ring>("poly_shifted_extra1", "POLYGON((2 2,1 1,0 0,0 2,2 2))", case_p1, true);
+
+ // Shifted + extra (redundant) coordinate being first/last point
+ test_geometry<ring, ring>("poly_shifted_extra2", "POLYGON((1 1,0 0,0 2,2 2,1 1))", case_p1, true);
+
+ // Degenerate (duplicate) points
     test_geometry<ring, ring>("poly_degenerate", "POLYGON((0 0,0 2,2 2,2 2,0 0))", "POLYGON((0 0,0 2,0 2,2 2,0 0))", true);
 
     // Two different bends, same area, unequal
@@ -96,10 +101,54 @@
 }
 
 
+template <typename T>
+void verify()
+{
+ T dxn1, dyn1, dxn2, dyn2;
+
+ {
+ T x1 = "0", y1 = "0", x2 = "3", y2 = "3";
+ T dx = x2 - x1, dy = y2 - y1;
+ T mag = sqrt(dx * dx + dy * dy);
+ dxn1 = dx / mag;
+ dyn1 = dy / mag;
+ }
+
+ {
+ T x1 = "0", y1 = "0", x2 = "1", y2 = "1";
+ T dx = x2 - x1, dy = y2 - y1;
+ T mag = sqrt(dx * dx + dy * dy);
+ dxn2 = dx / mag;
+ dyn2 = dy / mag;
+ }
+
+ if (dxn1 == dxn2 && dyn1 == dyn2)
+ {
+ //std::cout << "vectors are equal, using ==" << std::endl;
+ }
+ if (boost::geometry::math::equals(dxn1, dxn2)
+ && boost::geometry::math::equals(dyn1, dyn2))
+ {
+ //std::cout << "vectors are equal, using bg::math::equals" << std::endl;
+ }
+
+ bool equals = boost::geometry::math::equals_with_epsilon(dxn1, dxn2)
+ && boost::geometry::math::equals_with_epsilon(dyn1, dyn2);
+
+ if (equals)
+ {
+ //std::cout << "vectors are equal, using bg::math::equals_with_epsilon" << std::endl;
+ }
+
+ BOOST_CHECK_EQUAL(equals, true);
+}
 
 
 int test_main( int , char* [] )
 {
+ //verify<double>();
+ verify<ttmath_big>();
+
     test_all<bg::model::d2::point_xy<int> >();
     test_all<bg::model::d2::point_xy<double> >();
 


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