1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2016-2017 Oracle and/or its affiliates.
4 // Contributed and/or modified by Vissarion Fisikopoulos, on behalf of Oracle
5 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
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)
11 #ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_AREA_HPP
12 #define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_AREA_HPP
15 #include <boost/geometry/formulas/area_formulas.hpp>
16 #include <boost/geometry/core/radius.hpp>
17 #include <boost/geometry/core/srs.hpp>
18 #include <boost/geometry/strategies/area.hpp>
21 namespace boost { namespace geometry
24 namespace strategy { namespace area
28 \brief Spherical area calculation
30 \details Calculates area on the surface of a sphere using the trapezoidal rule
31 \tparam PointOfSegment \tparam_segment_point
32 \tparam CalculationType \tparam_calculation
36 [link geometry.reference.algorithms.area.area_2_with_strategy area (with strategy)]
41 typename PointOfSegment,
42 typename CalculationType = void
46 // Enables special handling of long segments
47 static const bool LongSegment = false;
49 typedef typename boost::mpl::if_c
51 boost::is_void<CalculationType>::type::value,
52 typename select_most_precise
54 typename coordinate_type<PointOfSegment>::type,
65 // Keep track if encircles some pole
66 size_t m_crosses_prime_meridian;
70 , m_crosses_prime_meridian(0)
72 template <typename SphereType>
73 inline CT area(SphereType sphere) const
76 CT radius = geometry::get_radius<0>(sphere);
79 if(m_crosses_prime_meridian % 2 == 1)
81 size_t times_crosses_prime_meridian
82 = 1 + (m_crosses_prime_meridian / 2);
85 * geometry::math::pi<CT>()
86 * times_crosses_prime_meridian
87 - geometry::math::abs(m_sum);
89 if(geometry::math::sign<CT>(m_sum) == 1)
98 result *= radius * radius;
105 typedef CT return_type;
106 typedef PointOfSegment segment_point_type;
107 typedef excess_sum state_type;
108 typedef geometry::srs::sphere<CT> sphere_type;
110 // For backward compatibility reasons the radius is set to 1
115 template <typename T>
116 explicit inline spherical(geometry::srs::sphere<T> const& sphere)
117 : m_sphere(geometry::get_radius<0>(sphere))
120 explicit inline spherical(CT const& radius)
124 inline void apply(PointOfSegment const& p1,
125 PointOfSegment const& p2,
126 excess_sum& state) const
128 if (! geometry::math::equals(get<0>(p1), get<0>(p2)))
130 typedef geometry::formula::area_formulas<CT> area_formulas;
132 state.m_sum += area_formulas::template spherical<LongSegment>(p1, p2);
134 // Keep track whenever a segment crosses the prime meridian
135 if (area_formulas::crosses_prime_meridian(p1, p2))
137 state.m_crosses_prime_meridian++;
142 inline return_type result(excess_sum const& state) const
144 return state.area(m_sphere);
149 sphere_type m_sphere;
152 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
158 template <typename Point>
159 struct default_strategy<spherical_equatorial_tag, Point>
161 typedef strategy::area::spherical<Point> type;
164 // Note: spherical polar coordinate system requires "get_as_radian_equatorial"
165 template <typename Point>
166 struct default_strategy<spherical_polar_tag, Point>
168 typedef strategy::area::spherical<Point> type;
171 } // namespace services
173 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
176 }} // namespace strategy::area
181 }} // namespace boost::geometry
183 #endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_AREA_HPP