perimeter.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  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. #ifndef BOOST_GEOMETRY_ALGORITHMS_PERIMETER_HPP
  11. #define BOOST_GEOMETRY_ALGORITHMS_PERIMETER_HPP
  12. #include <boost/geometry/core/cs.hpp>
  13. #include <boost/geometry/core/closure.hpp>
  14. #include <boost/geometry/geometries/concepts/check.hpp>
  15. #include <boost/geometry/strategies/default_length_result.hpp>
  16. #include <boost/geometry/algorithms/length.hpp>
  17. #include <boost/geometry/algorithms/detail/calculate_null.hpp>
  18. #include <boost/geometry/algorithms/detail/calculate_sum.hpp>
  19. // #include <boost/geometry/algorithms/detail/throw_on_empty_input.hpp>
  20. namespace boost { namespace geometry
  21. {
  22. #ifndef DOXYGEN_NO_DISPATCH
  23. namespace dispatch
  24. {
  25. // Default perimeter is 0.0, specializations implement calculated values
  26. template <typename Geometry, typename Tag = typename tag<Geometry>::type>
  27. struct perimeter : detail::calculate_null
  28. {
  29. typedef typename default_length_result<Geometry>::type return_type;
  30. template <typename Strategy>
  31. static inline return_type apply(Geometry const& geometry, Strategy const& strategy)
  32. {
  33. return calculate_null::apply<return_type>(geometry, strategy);
  34. }
  35. };
  36. template <typename Geometry>
  37. struct perimeter<Geometry, ring_tag>
  38. : detail::length::range_length
  39. <
  40. Geometry,
  41. closure<Geometry>::value
  42. >
  43. {};
  44. template <typename Polygon>
  45. struct perimeter<Polygon, polygon_tag> : detail::calculate_polygon_sum
  46. {
  47. typedef typename default_length_result<Polygon>::type return_type;
  48. typedef detail::length::range_length
  49. <
  50. typename ring_type<Polygon>::type,
  51. closure<Polygon>::value
  52. > policy;
  53. template <typename Strategy>
  54. static inline return_type apply(Polygon const& polygon, Strategy const& strategy)
  55. {
  56. return calculate_polygon_sum::apply<return_type, policy>(polygon, strategy);
  57. }
  58. };
  59. // box,n-sphere: to be implemented
  60. } // namespace dispatch
  61. #endif // DOXYGEN_NO_DISPATCH
  62. /*!
  63. \brief \brief_calc{perimeter}
  64. \ingroup perimeter
  65. \details The function perimeter returns the perimeter of a geometry,
  66. using the default distance-calculation-strategy
  67. \tparam Geometry \tparam_geometry
  68. \param geometry \param_geometry
  69. \return \return_calc{perimeter}
  70. \qbk{[include reference/algorithms/perimeter.qbk]}
  71. */
  72. template<typename Geometry>
  73. inline typename default_length_result<Geometry>::type perimeter(
  74. Geometry const& geometry)
  75. {
  76. concept::check<Geometry const>();
  77. typedef typename point_type<Geometry>::type point_type;
  78. typedef typename strategy::distance::services::default_strategy
  79. <
  80. point_tag, point_type
  81. >::type strategy_type;
  82. // detail::throw_on_empty_input(geometry);
  83. return dispatch::perimeter<Geometry>::apply(geometry, strategy_type());
  84. }
  85. /*!
  86. \brief \brief_calc{perimeter} \brief_strategy
  87. \ingroup perimeter
  88. \details The function perimeter returns the perimeter of a geometry,
  89. using specified strategy
  90. \tparam Geometry \tparam_geometry
  91. \tparam Strategy \tparam_strategy{distance}
  92. \param geometry \param_geometry
  93. \param strategy strategy to be used for distance calculations.
  94. \return \return_calc{perimeter}
  95. \qbk{distinguish,with strategy}
  96. \qbk{[include reference/algorithms/perimeter.qbk]}
  97. */
  98. template<typename Geometry, typename Strategy>
  99. inline typename default_length_result<Geometry>::type perimeter(
  100. Geometry const& geometry, Strategy const& strategy)
  101. {
  102. concept::check<Geometry const>();
  103. // detail::throw_on_empty_input(geometry);
  104. return dispatch::perimeter<Geometry>::apply(geometry, strategy);
  105. }
  106. }} // namespace boost::geometry
  107. #endif // BOOST_GEOMETRY_ALGORITHMS_PERIMETER_HPP