123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- #ifndef BOOST_GEOMETRY_STRATEGY_GEOGRAPHIC_AREA_BOX_HPP
- #define BOOST_GEOMETRY_STRATEGY_GEOGRAPHIC_AREA_BOX_HPP
- #include <boost/geometry/core/radian_access.hpp>
- #include <boost/geometry/srs/spheroid.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 Spheroid = srs::spheroid<double>,
- typename CalculationType = void
- >
- class geographic_box
- {
- public:
- template <typename Box>
- struct result_type
- : strategy::area::detail::result_type
- <
- Box,
- CalculationType
- >
- {};
- geographic_box() = default;
- explicit geographic_box(Spheroid const& spheroid)
- : m_spheroid(spheroid)
- {}
- template <typename Box>
- inline auto apply(Box const& box) const
- {
- typedef typename result_type<Box>::type return_type;
- return_type const c0 = 0;
- 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);
- math::normalize_spheroidal_box_coordinates<radian>(x_min, y_min, x_max, y_max);
- if (x_min == x_max || y_max == y_min)
- {
- return c0;
- }
- return_type const e2 = formula::eccentricity_sqr<return_type>(m_spheroid);
- return_type const x_diff = x_max - x_min;
- return_type const sin_y_min = sin(y_min);
- return_type const sin_y_max = sin(y_max);
- if (math::equals(e2, c0))
- {
-
- return_type const a = get_radius<0>(m_spheroid);
- return x_diff * (sin_y_max - sin_y_min) * a * a;
- }
- return_type const c1 = 1;
- return_type const c2 = 2;
- return_type const b = get_radius<2>(m_spheroid);
-
- return_type const comp0_min = c1 / (c1 - e2 * sin_y_min * sin_y_min);
- return_type const comp0_max = c1 / (c1 - e2 * sin_y_max * sin_y_max);
-
- return_type comp1_min = 0, comp1_max = 0;
- if (e2 > c0)
- {
- return_type const e = math::sqrt(e2);
- return_type const e_sin_y_min = e * sin_y_min;
- return_type const e_sin_y_max = e * sin_y_max;
- comp1_min = e_sin_y_min == c0 ? c1 : atanh(e_sin_y_min) / e_sin_y_min;
- comp1_max = e_sin_y_max == c0 ? c1 : atanh(e_sin_y_max) / e_sin_y_max;
- }
- else
- {
- return_type const ea = math::sqrt(-e2);
- return_type const ea_sin_y_min = ea * sin_y_min;
- return_type const ea_sin_y_max = ea * sin_y_max;
- comp1_min = ea_sin_y_min == c0 ? c1 : atan(ea_sin_y_min) / ea_sin_y_min;
- comp1_max = ea_sin_y_max == c0 ? c1 : atan(ea_sin_y_max) / ea_sin_y_max;
- }
- return_type const comp01_min = sin_y_min * (comp0_min + comp1_min);
- return_type const comp01_max = sin_y_max * (comp0_max + comp1_max);
- return b * b * x_diff * (comp01_max - comp01_min) / c2;
- }
- Spheroid model() const
- {
- return m_spheroid;
- }
- private:
- Spheroid m_spheroid;
- };
- }}
- }}
- #endif
|