$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r85361 - in trunk: boost/geometry/extensions/gis/geographic/strategies boost/geometry/strategies/spherical libs/geometry/extensions/test/gis/latlong
From: barend.gehrels_at_[hidden]
Date: 2013-08-15 18:01:17
Author: barendgehrels
Date: 2013-08-15 18:01:16 EDT (Thu, 15 Aug 2013)
New Revision: 85361
URL: http://svn.boost.org/trac/boost/changeset/85361
Log:
[geometry] fixed cross-track (missed comparable_type), vincenty (missed radius), cross-track-course (now supports different point-types), distance_mixed unit test which uses all these things
Text files modified: 
   trunk/boost/geometry/extensions/gis/geographic/strategies/vincenty.hpp |     7 +++++                                   
   trunk/boost/geometry/strategies/spherical/distance_cross_track.hpp     |    34 +++++++++++++++++----------             
   trunk/libs/geometry/extensions/test/gis/latlong/distance_mixed.cpp     |    48 ++++++++++++++++++++++----------------- 
   3 files changed, 54 insertions(+), 35 deletions(-)
Modified: trunk/boost/geometry/extensions/gis/geographic/strategies/vincenty.hpp
==============================================================================
--- trunk/boost/geometry/extensions/gis/geographic/strategies/vincenty.hpp	Thu Aug 15 17:03:59 2013	(r85360)
+++ trunk/boost/geometry/extensions/gis/geographic/strategies/vincenty.hpp	2013-08-15 18:01:16 EDT (Thu, 15 Aug 2013)	(r85361)
@@ -89,6 +89,11 @@
         return m_ellipsoid;
     }
 
+    inline RadiusType radius() const
+    {
+        // For now return the major axis. It is used in distance_cross_track, from point-to-line
+        return m_ellipsoid.a();
+    }
 
 private :
     geometry::detail::ellipsoid<RadiusType> m_ellipsoid;
@@ -227,7 +232,7 @@
 struct result_from_distance<vincenty<RadiusType, CalculationType>, P1, P2 >
 {
     template <typename T>
-    static inline typename return_type<vincenty<RadiusType, CalculationType>, P1, P2>::type 
+    static inline typename return_type<vincenty<RadiusType, CalculationType>, P1, P2>::type
         apply(vincenty<RadiusType, CalculationType> const& , T const& value)
     {
         return value;
Modified: trunk/boost/geometry/strategies/spherical/distance_cross_track.hpp
==============================================================================
--- trunk/boost/geometry/strategies/spherical/distance_cross_track.hpp	Thu Aug 15 17:03:59 2013	(r85360)
+++ trunk/boost/geometry/strategies/spherical/distance_cross_track.hpp	2013-08-15 18:01:16 EDT (Thu, 15 Aug 2013)	(r85361)
@@ -169,11 +169,11 @@
     Strategy m_strategy;
 
     /// Calculate course (bearing) between two points. Might be moved to a "course formula" ...
-    template <typename Point>
-    inline typename return_type<Point, Point>::type
-    course(Point const& p1, Point const& p2) const
+    template <typename Point1, typename Point2>
+    inline typename return_type<Point1, Point2>::type
+    course(Point1 const& p1, Point2 const& p2) const
     {
-        typedef typename return_type<Point, Point>::type return_type;
+        typedef typename return_type<Point1, Point2>::type return_type;
 
         // http://williams.best.vwh.net/avform.htm#Crs
         return_type dlon = get_as_radian<0>(p2) - get_as_radian<0>(p1);
@@ -206,9 +206,17 @@
 {};
 
 
-template 
+template <typename CalculationType, typename Strategy>
+struct comparable_type<cross_track<CalculationType, Strategy> >
+{
+    // There is no shortcut, so the strategy itself is its comparable type
+    typedef cross_track<CalculationType, Strategy>  type;
+};
+
+
+template
 <
-    typename CalculationType, 
+    typename CalculationType,
     typename Strategy
 >
 struct get_comparable<cross_track<CalculationType, Strategy> >
@@ -225,9 +233,9 @@
 };
 
 
-template 
+template
 <
-    typename CalculationType, 
+    typename CalculationType,
     typename Strategy,
     typename P, typename PS
 >
@@ -246,7 +254,7 @@
 
 template
 <
-    typename CalculationType, 
+    typename CalculationType,
     typename Strategy
 >
 struct strategy_point_point<cross_track<CalculationType, Strategy> >
@@ -263,8 +271,8 @@
 template <typename Point, typename PointOfSegment, typename Strategy>
 struct default_strategy
     <
-        segment_tag, Point, PointOfSegment, 
-        spherical_polar_tag, spherical_polar_tag, 
+        segment_tag, Point, PointOfSegment,
+        spherical_polar_tag, spherical_polar_tag,
         Strategy
     >
 {
@@ -288,8 +296,8 @@
 template <typename Point, typename PointOfSegment, typename Strategy>
 struct default_strategy
     <
-        segment_tag, Point, PointOfSegment, 
-        spherical_equatorial_tag, spherical_equatorial_tag, 
+        segment_tag, Point, PointOfSegment,
+        spherical_equatorial_tag, spherical_equatorial_tag,
         Strategy
     >
 {
Modified: trunk/libs/geometry/extensions/test/gis/latlong/distance_mixed.cpp
==============================================================================
--- trunk/libs/geometry/extensions/test/gis/latlong/distance_mixed.cpp	Thu Aug 15 17:03:59 2013	(r85360)
+++ trunk/libs/geometry/extensions/test/gis/latlong/distance_mixed.cpp	2013-08-15 18:01:16 EDT (Thu, 15 Aug 2013)	(r85361)
@@ -41,38 +41,44 @@
     transform(amsterdam, amsterdam_rad);
     transform(paris, paris_rad);
 
-    double d1 = 0.001 * distance(paris, amsterdam);
-    double d2 = 0.001 * distance(paris_rad, amsterdam_rad);
+    // Distance paris-amsterdam is about 430 km
+    double expected = 429.984 * 1000.0;
+    double tolerance = 0.001;
+
+    // Combinations deg-deg, rad-rad, deg-rad, rad-de
+    BOOST_CHECK_CLOSE(distance(paris, amsterdam), expected, tolerance);
+    BOOST_CHECK_CLOSE(distance(paris_rad, amsterdam_rad), expected, tolerance);
+    BOOST_CHECK_CLOSE(distance(paris, amsterdam_rad), expected, tolerance);
+    BOOST_CHECK_CLOSE(distance(paris_rad, amsterdam), expected, tolerance);
+
+    // With specified strategy
+    vincenty<double> the_strategy;
+    BOOST_CHECK_CLOSE(distance(paris, amsterdam, the_strategy), expected, tolerance);
+    BOOST_CHECK_CLOSE(distance(paris_rad, amsterdam_rad, the_strategy), expected, tolerance);
+    BOOST_CHECK_CLOSE(distance(paris, amsterdam_rad, the_strategy), expected, tolerance);
+    BOOST_CHECK_CLOSE(bg::distance(paris_rad, amsterdam, the_strategy), expected, tolerance);
 
-    double d3 = 0.001 * distance(paris, amsterdam_rad);
-    double d4 = 0.001 * distance(paris_rad, amsterdam);
-    std::cout << "Distances: " << d1 << " == " << d2 << " == " << d3 << " == " << d4 << std::endl;
-
-    double d5 = 0.001 * distance(paris, amsterdam, vincenty<bg::model::ll::point<bg::degree>, bg::model::ll::point<bg::degree> >());
-    double d6 = 0.001 * distance(paris_rad, amsterdam_rad, vincenty<bg::model::ll::point<bg::radian>, bg::model::ll::point<bg::radian> >());
-    double d7 = 0.001 * distance(paris, amsterdam_rad, vincenty<bg::model::ll::point<bg::degree>, bg::model::ll::point<bg::radian> >());
-    double d8 = 0.001 * bg::distance(paris_rad, amsterdam, vincenty<bg::model::ll::point<bg::radian>, bg::model::ll::point<bg::degree> >());
-    std::cout << "Distances: " << d5 << " == " << d6 << " == " << d7 << " == " << d8 << std::endl;
 
+    // Distance point-linestring, linestring-point...
     bg::model::ll::point<bg::degree> barcelona(
         bg::latitude<>(bg::dms<bg::north>(41, 23)),
         bg::longitude<>(bg::dms<bg::east>(2, 11))
         );
 
-    // Now declare a line in latlong and calculate the distance, this MUST reverse...
     bg::model::linestring<bg::model::ll::point<bg::degree> > ab;
     ab.push_back(amsterdam);
     ab.push_back(barcelona);
 
-    double d9 = 0.001 * distance(ab, paris);
-    double d10 = 0.001 * distance(paris, ab);
-    double d11 = 0.001 * distance(paris, ab, vincenty<bg::model::ll::point<bg::degree>, bg::model::ll::point<bg::degree> >());
-    double d12 = 0.001 * distance(ab, paris, vincenty<bg::model::ll::point<bg::degree>, bg::model::ll::point<bg::degree> >());
-    std::cout << "Distances: " << d9 << " == " << d10 << " == " << d11 << " == " << d12 << std::endl;
-
-    // TODO: solve this case, it is reversed -> strategy should be reversed as well
-    // For this, first implement that linestring can have other coor.sys then point type...
-    //double d13 = 0.001 * distance(ab, paris_rad, vincenty<ll::point<bg::degree>, ll::point<bg::radian> >());
+    // Distance paris to line amsteram-barcelona is about 113 km
+    expected = 113.168 * 1000.0;
+
+    BOOST_CHECK_CLOSE(distance(ab, paris), expected, tolerance);
+    BOOST_CHECK_CLOSE(distance(paris, ab), expected, tolerance);
+    BOOST_CHECK_CLOSE(distance(paris, ab, the_strategy), expected, tolerance);
+    BOOST_CHECK_CLOSE(distance(ab, paris, the_strategy), expected, tolerance);
+
+    // line-type in degrees, point-type in radians (supported since new distance-strategy approach)
+    BOOST_CHECK_CLOSE(distance(ab, paris_rad, the_strategy), expected, tolerance);
 
     return 0;
 }