Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71451 - trunk/libs/geometry/test/algorithms
From: bruno.lalande_at_[hidden]
Date: 2011-04-23 18:33:07


Author: bruno.lalande
Date: 2011-04-23 18:33:06 EDT (Sat, 23 Apr 2011)
New Revision: 71451
URL: http://svn.boost.org/trac/boost/changeset/71451

Log:
Added a test for 5D linestring centroid.
Text files modified:
   trunk/libs/geometry/test/algorithms/centroid.cpp | 18 ++++++++++++++++--
   trunk/libs/geometry/test/algorithms/test_centroid.hpp | 34 ++++++++++++----------------------
   2 files changed, 28 insertions(+), 24 deletions(-)

Modified: trunk/libs/geometry/test/algorithms/centroid.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/centroid.cpp (original)
+++ trunk/libs/geometry/test/algorithms/centroid.cpp 2011-04-23 18:33:06 EDT (Sat, 23 Apr 2011)
@@ -16,10 +16,13 @@
 
 #include <boost/geometry/geometries/geometries.hpp>
 #include <boost/geometry/geometries/adapted/c_array_cartesian.hpp>
-#include <boost/geometry/geometries/adapted/tuple_cartesian.hpp>
+#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
 
 #include <test_geometries/all_custom_polygon.hpp>
 
+BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian);
+
+
 template <typename Polygon>
 void test_polygon()
 {
@@ -78,12 +81,21 @@
 template <typename P>
 void test_3d()
 {
- test_centroid<bg::model::linestring<P> >("LINESTRING(1 2 3,4 5 -6,7 -8 9,-10 11 12,13 -14 -15, 16 17 18)", 5.6748865168734692, 0.31974938587214002, 1.9915270387763671);
+ test_centroid<bg::model::linestring<P> >("LINESTRING(1 2 3,4 5 -6,7 -8 9,-10 11 12,13 -14 -15, 16 17 18)",
+ 5.6748865168734692, 0.31974938587214002, 1.9915270387763671);
     test_centroid<bg::model::box<P> >("POLYGON((1 2 3,5 6 7))", 3, 4, 5);
     test_centroid<P>("POINT(1 2 3)", 1, 2, 3);
 }
 
 
+template <typename P>
+void test_5d()
+{
+ test_centroid<bg::model::linestring<P> >("LINESTRING(1 2 3 4 95,4 5 -6 24 40,7 -8 9 -5 -7,-10 11 12 -5 5,13 -14 -15 4 3, 16 17 18 5 12)",
+ 4.9202312983547678, 0.69590937869808345, 1.2632138719797417, 6.0468332057401986, 23.082402715244868);
+}
+
+
 int test_main(int, char* [])
 {
     test_2d<bg::model::d2::point_xy<double> >();
@@ -92,6 +104,8 @@
 
     test_3d<boost::tuple<double, double, double> >();
 
+ test_5d<boost::tuple<double, double, double, double, double> >();
+
 #if defined(HAVE_TTMATH)
     test_2d<bg::model::d2::point_xy<ttmath_big> >();
     test_3d<boost::tuple<ttmath_big, ttmath_big, ttmath_big> >();

Modified: trunk/libs/geometry/test/algorithms/test_centroid.hpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/test_centroid.hpp (original)
+++ trunk/libs/geometry/test/algorithms/test_centroid.hpp 2011-04-23 18:33:06 EDT (Sat, 23 Apr 2011)
@@ -16,41 +16,31 @@
 #include <boost/geometry/strategies/strategies.hpp>
 #include <boost/geometry/algorithms/centroid.hpp>
 #include <boost/geometry/algorithms/distance.hpp>
+#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
 
 #include <boost/geometry/domains/gis/io/wkt/read_wkt.hpp>
 
 
-template<std::size_t D>
+template <std::size_t D>
 struct check_result
 {
-};
-
-template <>
-struct check_result<2>
-{
- template <typename Point, typename T>
- static void apply(Point const& p, T const& x, T const& y, T const&)
+ template <typename Point1, typename Point2>
+ static void apply(Point1 const& actual, Point2 const& expected)
     {
- BOOST_CHECK_CLOSE(bg::get<0>(p), x, 0.001);
- BOOST_CHECK_CLOSE(bg::get<1>(p), y, 0.001);
+ check_result<D-1>::apply(actual, expected);
+ BOOST_CHECK_CLOSE(bg::get<D-1>(actual), bg::get<D-1>(expected), 0.001);
     }
 };
 
-
 template <>
-struct check_result<3>
+struct check_result<0>
 {
- template <typename Point, typename T>
- static void apply(Point const& p, T const& x, T const& y, T const& z)
- {
- BOOST_CHECK_CLOSE(bg::get<0>(p), x, 0.001);
- BOOST_CHECK_CLOSE(bg::get<1>(p), y, 0.001);
- BOOST_CHECK_CLOSE(bg::get<2>(p), z, 0.001);
- }
+ template <typename Point1, typename Point2>
+ static void apply(Point1 const&, Point2 const&)
+ {}
 };
 
 
-
 template <typename CalculationType, typename Geometry, typename Point>
 void test_with_other_calculation_type(Geometry const& geometry, Point& c1)
 {
@@ -67,14 +57,14 @@
 }
 
 template <typename Geometry, typename T>
-void test_centroid(std::string const& wkt, T const& x, T const& y, T const& z = T())
+void test_centroid(std::string const& wkt, T const& d1, T const& d2, T const& d3 = T(), T const& d4 = T(), T const& d5 = T())
 {
     Geometry geometry;
     bg::read_wkt(wkt, geometry);
     typedef typename bg::point_type<Geometry>::type point_type;
     point_type c1;
     bg::centroid(geometry, c1);
- check_result<bg::dimension<Geometry>::type::value>::apply(c1, x, y, z);
+ check_result<bg::dimension<Geometry>::type::value>::apply(c1, boost::make_tuple(d1, d2, d3, d4, d5));
 
 #ifdef REPORT_RESULTS
     std::cout << "normal: " << std::setprecision(20) << bg::get<0>(c1) << " " << bg::get<1>(c1) << std::endl;


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