123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #ifndef BOOST_GEOMETRY_STRATEGY_SPHERICAL_AREA_BOX_HPP
- #define BOOST_GEOMETRY_STRATEGY_SPHERICAL_AREA_BOX_HPP
- #include <boost/geometry/core/coordinate_type.hpp>
- #include <boost/geometry/core/coordinate_dimension.hpp>
- #include <boost/geometry/core/radian_access.hpp>
- #include <boost/geometry/srs/sphere.hpp>
- #include <boost/geometry/strategies/spherical/get_radius.hpp>
- #include <boost/geometry/strategy/area.hpp>
- #include <boost/geometry/util/normalize_spheroidal_box_coordinates.hpp>
- namespace boost { namespace geometry
- {
- namespace strategy { namespace area
- {
- template
- <
- typename RadiusTypeOrSphere = double,
- typename CalculationType = void
- >
- class spherical_box
- {
- typedef typename strategy_detail::get_radius
- <
- RadiusTypeOrSphere
- >::type radius_type;
- public:
- template <typename Box>
- struct result_type
- : strategy::area::detail::result_type
- <
- Box,
- CalculationType
- >
- {};
-
- inline spherical_box()
- : m_radius(1.0)
- {}
- template <typename RadiusOrSphere>
- explicit inline spherical_box(RadiusOrSphere const& radius_or_sphere)
- : m_radius(strategy_detail::get_radius
- <
- RadiusOrSphere
- >::apply(radius_or_sphere))
- {}
- template <typename Box>
- inline auto apply(Box const& box) const
- {
- typedef typename result_type<Box>::type return_type;
- return_type x_min = get_as_radian<min_corner, 0>(box);
- return_type y_min = get_as_radian<min_corner, 1>(box);
- return_type x_max = get_as_radian<max_corner, 0>(box);
- return_type y_max = get_as_radian<max_corner, 1>(box);
- if (x_min == x_max || y_max == y_min)
- {
- return return_type(0);
- }
- math::normalize_spheroidal_box_coordinates<radian>(x_min, y_min, x_max, y_max);
- return (x_max - x_min)
- * (sin(y_max) - sin(y_min))
- * return_type(m_radius * m_radius);
- }
- srs::sphere<radius_type> model() const
- {
- return srs::sphere<radius_type>(m_radius);
- }
- private:
- radius_type m_radius;
- };
- }}
- }}
- #endif
|