1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // This file was modified by Oracle on 2014.
6 // Modifications copyright (c) 2014 Oracle and/or its affiliates.
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
14 #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_MAPPING_SSF_HPP
15 #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_MAPPING_SSF_HPP
18 #include <boost/core/ignore_unused.hpp>
20 #include <boost/geometry/core/radius.hpp>
22 #include <boost/geometry/util/math.hpp>
23 #include <boost/geometry/util/promote_floating_point.hpp>
24 #include <boost/geometry/util/select_calculation_type.hpp>
26 #include <boost/geometry/strategies/side.hpp>
27 #include <boost/geometry/strategies/spherical/ssf.hpp>
30 namespace boost { namespace geometry
33 namespace strategy { namespace side
37 // An enumeration type defining types of mapping of geographical
38 // latitude to spherical latitude.
39 // See: http://en.wikipedia.org/wiki/Great_ellipse
40 // http://en.wikipedia.org/wiki/Latitude#Auxiliary_latitudes
41 enum mapping_type { mapping_geodetic, mapping_reduced, mapping_geocentric };
44 #ifndef DOXYGEN_NO_DETAIL
48 template <typename Spheroid, mapping_type Mapping>
51 explicit inline mapper(Spheroid const& /*spheroid*/) {}
53 template <typename CalculationType>
54 static inline CalculationType const& apply(CalculationType const& lat)
60 template <typename Spheroid>
61 struct mapper<Spheroid, mapping_reduced>
63 typedef typename promote_floating_point
65 typename radius_type<Spheroid>::type
66 >::type fraction_type;
68 explicit inline mapper(Spheroid const& spheroid)
70 fraction_type const a = geometry::get_radius<0>(spheroid);
71 fraction_type const b = geometry::get_radius<2>(spheroid);
75 template <typename CalculationType>
76 inline CalculationType apply(CalculationType const& lat) const
78 return atan(static_cast<CalculationType>(b_div_a) * tan(lat));
81 fraction_type b_div_a;
84 template <typename Spheroid>
85 struct mapper<Spheroid, mapping_geocentric>
87 typedef typename promote_floating_point
89 typename radius_type<Spheroid>::type
90 >::type fraction_type;
92 explicit inline mapper(Spheroid const& spheroid)
94 fraction_type const a = geometry::get_radius<0>(spheroid);
95 fraction_type const b = geometry::get_radius<2>(spheroid);
97 sqr_b_div_a *= sqr_b_div_a;
100 template <typename CalculationType>
101 inline CalculationType apply(CalculationType const& lat) const
103 return atan(static_cast<CalculationType>(sqr_b_div_a) * tan(lat));
106 fraction_type sqr_b_div_a;
110 #endif // DOXYGEN_NO_DETAIL
114 \brief Check at which side of a geographical segment a point lies
115 left of segment (> 0), right of segment (< 0), on segment (0).
116 The check is performed by mapping the geographical coordinates
117 to spherical coordinates and using spherical_side_formula.
119 \tparam Spheroid The reference spheroid model
120 \tparam Mapping The type of mapping of geographical to spherical latitude
121 \tparam CalculationType \tparam_calculation
123 template <typename Spheroid,
124 mapping_type Mapping = mapping_geodetic,
125 typename CalculationType = void>
126 class mapping_spherical_side_formula
130 inline mapping_spherical_side_formula()
131 : m_mapper(Spheroid())
134 explicit inline mapping_spherical_side_formula(Spheroid const& spheroid)
138 template <typename P1, typename P2, typename P>
139 inline int apply(P1 const& p1, P2 const& p2, P const& p)
141 typedef typename promote_floating_point
143 typename select_calculation_type_alt
148 >::type calculation_type;
150 calculation_type lon1 = get_as_radian<0>(p1);
151 calculation_type lat1 = m_mapper.template apply<calculation_type>(get_as_radian<1>(p1));
152 calculation_type lon2 = get_as_radian<0>(p2);
153 calculation_type lat2 = m_mapper.template apply<calculation_type>(get_as_radian<1>(p2));
154 calculation_type lon = get_as_radian<0>(p);
155 calculation_type lat = m_mapper.template apply<calculation_type>(get_as_radian<1>(p));
157 return detail::spherical_side_formula(lon1, lat1, lon2, lat2, lon, lat);
161 side::detail::mapper<Spheroid, Mapping> const m_mapper;
164 // The specialization for geodetic latitude which can be used directly
165 template <typename Spheroid,
166 typename CalculationType>
167 class mapping_spherical_side_formula<Spheroid, mapping_geodetic, CalculationType>
171 inline mapping_spherical_side_formula() {}
172 explicit inline mapping_spherical_side_formula(Spheroid const& /*spheroid*/) {}
174 template <typename P1, typename P2, typename P>
175 static inline int apply(P1 const& p1, P2 const& p2, P const& p)
177 return spherical_side_formula<CalculationType>::apply(p1, p2, p);
181 }} // namespace strategy::side
183 }} // namespace boost::geometry
185 #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_MAPPING_SSF_HPP