PageRenderTime 22ms CodeModel.GetById 2ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/geometry/test/strategies/cross_track.cpp

http://hadesmem.googlecode.com/
C++ | 114 lines | 63 code | 32 blank | 19 comment | 0 complexity | 97d71657a5f92af4e61f181192b879b5 MD5 | raw file
  1// Boost.Geometry (aka GGL, Generic Geometry Library)
  2// Unit Test
  3
  4// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
  5// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
  6// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
  7
  8// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
 10
 11// Use, modification and distribution is subject to the Boost Software License,
 12// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 13// http://www.boost.org/LICENSE_1_0.txt)
 14
 15
 16#include <geometry_test_common.hpp>
 17
 18
 19#include <boost/geometry/algorithms/assign.hpp>
 20#include <boost/geometry/algorithms/distance.hpp>
 21
 22#include <boost/geometry/strategies/spherical/distance_haversine.hpp>
 23#include <boost/geometry/strategies/spherical/distance_cross_track.hpp>
 24
 25#include <boost/geometry/strategies/concepts/distance_concept.hpp>
 26
 27#include <boost/geometry/geometries/point.hpp>
 28#include <boost/geometry/geometries/segment.hpp>
 29
 30
 31// This test is GIS oriented. 
 32
 33
 34template <typename Point, typename LatitudePolicy>
 35void test_distance(
 36            typename bg::coordinate_type<Point>::type const& lon1, 
 37            typename bg::coordinate_type<Point>::type const& lat1,
 38            typename bg::coordinate_type<Point>::type const& lon2, 
 39            typename bg::coordinate_type<Point>::type const& lat2,
 40            typename bg::coordinate_type<Point>::type const& lon3, 
 41            typename bg::coordinate_type<Point>::type const& lat3,
 42            typename bg::coordinate_type<Point>::type const& radius, 
 43            typename bg::coordinate_type<Point>::type const& expected, 
 44            typename bg::coordinate_type<Point>::type const& tolerance)
 45{
 46    typedef bg::strategy::distance::cross_track
 47        <
 48            Point,
 49            Point
 50        > strategy_type;
 51    typedef typename bg::strategy::distance::services::return_type
 52        <
 53            strategy_type
 54        >::type return_type;
 55
 56
 57    BOOST_CONCEPT_ASSERT
 58        (
 59            (bg::concept::PointSegmentDistanceStrategy<strategy_type>)
 60        );
 61
 62
 63    Point p1, p2, p3;
 64    bg::assign_values(p1, lon1, LatitudePolicy::apply(lat1));
 65    bg::assign_values(p2, lon2, LatitudePolicy::apply(lat2));
 66    bg::assign_values(p3, lon3, LatitudePolicy::apply(lat3));
 67
 68
 69    strategy_type strategy;
 70    return_type d = strategy.apply(p1, p2, p3);
 71
 72    BOOST_CHECK_CLOSE(radius * d, expected, tolerance);
 73
 74    // Test specifying radius explicitly
 75    strategy_type strategy_radius(radius);
 76    d = strategy_radius.apply(p1, p2, p3);
 77    BOOST_CHECK_CLOSE(d, expected, tolerance);
 78
 79
 80    // Test the "default strategy" registration
 81    bg::model::referring_segment<Point const> segment(p2, p3);
 82    d = bg::distance(p1, segment);
 83    BOOST_CHECK_CLOSE(radius * d, expected, tolerance);
 84}
 85
 86
 87template <typename Point, typename LatitudePolicy>
 88void test_all()
 89{
 90    typename bg::coordinate_type<Point>::type const average_earth_radius = 6372795.0;
 91
 92    // distance (Paris <-> Amsterdam/Barcelona), 
 93    // with coordinates rounded as below ~87 km
 94    // is equal to distance (Paris <-> Barcelona/Amsterdam)
 95    typename bg::coordinate_type<Point>::type const p_to_ab = 86.798321 * 1000.0;
 96    test_distance<Point, LatitudePolicy>(2, 48, 4, 52, 2, 41, average_earth_radius, p_to_ab, 0.1);
 97    test_distance<Point, LatitudePolicy>(2, 48, 2, 41, 4, 52, average_earth_radius, p_to_ab, 0.1);
 98}
 99
100
101int test_main(int, char* [])
102{
103    test_all<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> >, geographic_policy >();
104
105    // NYI: haversine for mathematical spherical coordinate systems
106    // test_all<bg::model::point<double, 2, bg::cs::spherical<bg::degree> >, mathematical_policya >();
107
108#if defined(HAVE_TTMATH)
109    typedef ttmath::Big<1,4> tt;
110    //test_all<bg::model::point<tt, 2, bg::cs::geographic<bg::degree> >, geographic_policy>();
111#endif
112
113    return 0;
114}