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