Imported Upstream version 1.63.0
[platform/upstream/boost.git] / libs / geometry / test / algorithms / test_area.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 #ifndef BOOST_GEOMETRY_TEST_AREA_HPP
11 #define BOOST_GEOMETRY_TEST_AREA_HPP
12
13
14 #include <geometry_test_common.hpp>
15
16 #include <boost/geometry/algorithms/area.hpp>
17 #include <boost/geometry/algorithms/correct.hpp>
18 #include <boost/geometry/strategies/strategies.hpp>
19
20 #include <boost/geometry/io/wkt/read.hpp>
21
22
23 template <typename Geometry>
24 void test_area(Geometry const& geometry,
25             typename bg::default_area_result<Geometry>::type expected_area)
26 {
27     typename bg::default_area_result<Geometry>::type area = bg::area(geometry);
28
29 #ifdef BOOST_GEOMETRY_TEST_DEBUG
30     std::ostringstream out;
31     out << typeid(typename bg::coordinate_type<Geometry>::type).name()
32         << " "
33         << typeid(typename bg::default_area_result<Geometry>::type).name()
34         << " "
35         << "area : " << bg::area(geometry)
36         << std::endl;
37     std::cout << out.str();
38 #endif
39
40     BOOST_CHECK_CLOSE(area, expected_area, 0.0001);
41
42     // Test with explicitly defined strategies
43     bg::strategy::area::surveyor
44         <
45             typename bg::point_type<Geometry>::type
46         > strategy1;
47
48     area = bg::area(geometry, strategy1);
49
50     bg::strategy::area::surveyor
51         <
52             typename bg::point_type<Geometry>::type,
53             typename bg::coordinate_type<Geometry>::type
54         > strategy2;
55
56     area = bg::area(geometry, strategy2);
57
58 }
59
60 template <typename Geometry>
61 void test_geometry(std::string const& wkt,
62             typename bg::default_area_result<Geometry>::type expected_area)
63 {
64     Geometry geometry;
65     bg::read_wkt(wkt, geometry);
66     test_area(geometry, expected_area);
67 }
68
69 template <typename Geometry>
70 void test_empty_input(Geometry const& geometry)
71 {
72     try
73     {
74         bg::area(geometry);
75     }
76     catch(bg::empty_input_exception const& )
77     {
78         return;
79     }
80     BOOST_CHECK_MESSAGE(false, "A empty_input_exception should have been thrown" );
81 }
82
83
84 #endif