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