test_area.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
  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. #ifndef BOOST_GEOMETRY_TEST_AREA_HPP
  9. #define BOOST_GEOMETRY_TEST_AREA_HPP
  10. #include <geometry_test_common.hpp>
  11. #include <boost/geometry/algorithms/area.hpp>
  12. #include <boost/geometry/algorithms/correct.hpp>
  13. #include <boost/geometry/strategies/strategies.hpp>
  14. #include <boost/geometry/io/wkt/read.hpp>
  15. template <typename Geometry>
  16. void test_area(Geometry const& geometry,
  17. typename bg::default_area_result<Geometry>::type expected_area)
  18. {
  19. typename bg::default_area_result<Geometry>::type area = bg::area(geometry);
  20. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  21. std::ostringstream out;
  22. out << typeid(typename bg::coordinate_type<Geometry>::type).name()
  23. << " "
  24. << typeid(typename bg::default_area_result<Geometry>::type).name()
  25. << " "
  26. << "area : " << bg::area(geometry)
  27. << std::endl;
  28. std::cout << out.str();
  29. #endif
  30. BOOST_CHECK_CLOSE(area, expected_area, 0.0001);
  31. // Test with explicitly defined strategies
  32. bg::strategy::area::cartesian<> strategy1;
  33. area = bg::area(geometry, strategy1);
  34. bg::strategy::area::cartesian
  35. <
  36. typename bg::coordinate_type<Geometry>::type
  37. > strategy2;
  38. area = bg::area(geometry, strategy2);
  39. }
  40. template <typename Geometry>
  41. void test_geometry(std::string const& wkt,
  42. typename bg::default_area_result<Geometry>::type expected_area)
  43. {
  44. Geometry geometry;
  45. bg::read_wkt(wkt, geometry);
  46. test_area(geometry, expected_area);
  47. }
  48. template <typename Geometry>
  49. void test_empty_input(Geometry const& geometry)
  50. {
  51. try
  52. {
  53. bg::area(geometry);
  54. }
  55. catch(bg::empty_input_exception const& )
  56. {
  57. return;
  58. }
  59. BOOST_CHECK_MESSAGE(false, "A empty_input_exception should have been thrown" );
  60. }
  61. #endif