• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  // Boost.Geometry (aka GGL, Generic Geometry Library)
2  // Unit Test
3  
4  // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5  
6  // Copyright (c) 2016 Oracle and/or its affiliates.
7  // Contributed and/or modified by Vissarion Fisikopoulos, on behalf of Oracle
8  
9  // Use, modification and distribution is subject to the Boost Software License,
10  // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11  // http://www.boost.org/LICENSE_1_0.txt)
12  
13  #ifndef BOOST_GEOMETRY_TEST_LENGTH_HPP
14  #define BOOST_GEOMETRY_TEST_LENGTH_HPP
15  
16  #include <geometry_test_common.hpp>
17  
18  #include <boost/geometry/algorithms/length.hpp>
19  #include <boost/geometry/io/wkt/wkt.hpp>
20  #include <boost/geometry/strategies/strategies.hpp>
21  #include <boost/variant/variant.hpp>
22  
23  template <typename Geometry>
test_length(Geometry const & geometry,long double expected_length)24  void test_length(Geometry const& geometry, long double expected_length)
25  {
26      typename bg::default_length_result<Geometry>::type
27          length = bg::length(geometry);
28  
29  #ifdef BOOST_GEOMETRY_TEST_DEBUG
30      std::ostringstream out;
31      out << typeid(typename bg::coordinate_type<Geometry>::type).name()
32          << std::endl
33          << typeid(typename bg::default_length_result<Geometry>::type).name()
34          << std::endl
35          << "length : " << bg::length(geometry)
36          << std::endl;
37      std::cout << out.str();
38  #endif
39  
40      BOOST_CHECK_CLOSE(length, expected_length, 0.0001);
41  }
42  
43  template <typename Geometry, typename Strategy>
test_length(Geometry const & geometry,long double expected_length,Strategy strategy)44  void test_length(Geometry const& geometry, long double expected_length, Strategy strategy)
45  {
46      typename bg::default_length_result<Geometry>::type
47          length = bg::length(geometry, strategy);
48  
49  #ifdef BOOST_GEOMETRY_TEST_DEBUG
50      std::ostringstream out;
51      out << typeid(typename bg::coordinate_type<Geometry>::type).name()
52          << std::endl
53          << typeid(typename bg::default_length_result<Geometry>::type).name()
54          << std::endl
55          << "length : " << bg::length(geometry, strategy)
56          << std::endl;
57      std::cout << out.str();
58  #endif
59  
60      BOOST_CHECK_CLOSE(length, expected_length, 0.0001);
61  }
62  
63  template <typename Geometry>
test_geometry(std::string const & wkt,double expected_length)64  void test_geometry(std::string const& wkt, double expected_length)
65  {
66      Geometry geometry;
67      bg::read_wkt(wkt, geometry);
68      test_length(geometry, expected_length);
69  #if !defined(BOOST_GEOMETRY_TEST_DEBUG)
70      test_length(boost::variant<Geometry>(geometry), expected_length);
71  #endif
72  }
73  
74  template <typename Geometry, typename Strategy>
test_geometry(std::string const & wkt,double expected_length,Strategy strategy)75  void test_geometry(std::string const& wkt, double expected_length, Strategy strategy)
76  {
77      Geometry geometry;
78      bg::read_wkt(wkt, geometry);
79      test_length(geometry, expected_length, strategy);
80  #if !defined(BOOST_GEOMETRY_TEST_DEBUG)
81      test_length(boost::variant<Geometry>(geometry), expected_length, strategy);
82  #endif
83  }
84  
85  template <typename Geometry>
test_empty_input(Geometry const & geometry)86  void test_empty_input(Geometry const& geometry)
87  {
88      try
89      {
90          bg::length(geometry);
91      }
92      catch(bg::empty_input_exception const& )
93      {
94          return;
95      }
96      BOOST_CHECK_MESSAGE(false, "A empty_input_exception should have been thrown" );
97  }
98  
99  #endif
100