annotate DEPENDENCIES/generic/include/boost/geometry/strategies/geographic/mapping_ssf.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents f46d142149f5
children
rev   line source
Chris@102 1 // Boost.Geometry (aka GGL, Generic Geometry Library)
Chris@102 2
Chris@102 3 // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
Chris@102 4
Chris@102 5 // This file was modified by Oracle on 2014.
Chris@102 6 // Modifications copyright (c) 2014 Oracle and/or its affiliates.
Chris@102 7
Chris@102 8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
Chris@102 9
Chris@102 10 // Use, modification and distribution is subject to the Boost Software License,
Chris@102 11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@102 12 // http://www.boost.org/LICENSE_1_0.txt)
Chris@102 13
Chris@102 14 #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_MAPPING_SSF_HPP
Chris@102 15 #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_MAPPING_SSF_HPP
Chris@102 16
Chris@102 17
Chris@102 18 #include <boost/core/ignore_unused.hpp>
Chris@102 19
Chris@102 20 #include <boost/geometry/core/radius.hpp>
Chris@102 21
Chris@102 22 #include <boost/geometry/util/math.hpp>
Chris@102 23 #include <boost/geometry/util/promote_floating_point.hpp>
Chris@102 24 #include <boost/geometry/util/select_calculation_type.hpp>
Chris@102 25
Chris@102 26 #include <boost/geometry/strategies/side.hpp>
Chris@102 27 #include <boost/geometry/strategies/spherical/ssf.hpp>
Chris@102 28
Chris@102 29
Chris@102 30 namespace boost { namespace geometry
Chris@102 31 {
Chris@102 32
Chris@102 33 namespace strategy { namespace side
Chris@102 34 {
Chris@102 35
Chris@102 36
Chris@102 37 // An enumeration type defining types of mapping of geographical
Chris@102 38 // latitude to spherical latitude.
Chris@102 39 // See: http://en.wikipedia.org/wiki/Great_ellipse
Chris@102 40 // http://en.wikipedia.org/wiki/Latitude#Auxiliary_latitudes
Chris@102 41 enum mapping_type { mapping_geodetic, mapping_reduced, mapping_geocentric };
Chris@102 42
Chris@102 43
Chris@102 44 #ifndef DOXYGEN_NO_DETAIL
Chris@102 45 namespace detail
Chris@102 46 {
Chris@102 47
Chris@102 48 template <typename Spheroid, mapping_type Mapping>
Chris@102 49 struct mapper
Chris@102 50 {
Chris@102 51 explicit inline mapper(Spheroid const& /*spheroid*/) {}
Chris@102 52
Chris@102 53 template <typename CalculationType>
Chris@102 54 static inline CalculationType const& apply(CalculationType const& lat)
Chris@102 55 {
Chris@102 56 return lat;
Chris@102 57 }
Chris@102 58 };
Chris@102 59
Chris@102 60 template <typename Spheroid>
Chris@102 61 struct mapper<Spheroid, mapping_reduced>
Chris@102 62 {
Chris@102 63 typedef typename promote_floating_point
Chris@102 64 <
Chris@102 65 typename radius_type<Spheroid>::type
Chris@102 66 >::type fraction_type;
Chris@102 67
Chris@102 68 explicit inline mapper(Spheroid const& spheroid)
Chris@102 69 {
Chris@102 70 fraction_type const a = geometry::get_radius<0>(spheroid);
Chris@102 71 fraction_type const b = geometry::get_radius<2>(spheroid);
Chris@102 72 b_div_a = b / a;
Chris@102 73 }
Chris@102 74
Chris@102 75 template <typename CalculationType>
Chris@102 76 inline CalculationType apply(CalculationType const& lat) const
Chris@102 77 {
Chris@102 78 return atan(static_cast<CalculationType>(b_div_a) * tan(lat));
Chris@102 79 }
Chris@102 80
Chris@102 81 fraction_type b_div_a;
Chris@102 82 };
Chris@102 83
Chris@102 84 template <typename Spheroid>
Chris@102 85 struct mapper<Spheroid, mapping_geocentric>
Chris@102 86 {
Chris@102 87 typedef typename promote_floating_point
Chris@102 88 <
Chris@102 89 typename radius_type<Spheroid>::type
Chris@102 90 >::type fraction_type;
Chris@102 91
Chris@102 92 explicit inline mapper(Spheroid const& spheroid)
Chris@102 93 {
Chris@102 94 fraction_type const a = geometry::get_radius<0>(spheroid);
Chris@102 95 fraction_type const b = geometry::get_radius<2>(spheroid);
Chris@102 96 sqr_b_div_a = b / a;
Chris@102 97 sqr_b_div_a *= sqr_b_div_a;
Chris@102 98 }
Chris@102 99
Chris@102 100 template <typename CalculationType>
Chris@102 101 inline CalculationType apply(CalculationType const& lat) const
Chris@102 102 {
Chris@102 103 return atan(static_cast<CalculationType>(sqr_b_div_a) * tan(lat));
Chris@102 104 }
Chris@102 105
Chris@102 106 fraction_type sqr_b_div_a;
Chris@102 107 };
Chris@102 108
Chris@102 109 }
Chris@102 110 #endif // DOXYGEN_NO_DETAIL
Chris@102 111
Chris@102 112
Chris@102 113 /*!
Chris@102 114 \brief Check at which side of a geographical segment a point lies
Chris@102 115 left of segment (> 0), right of segment (< 0), on segment (0).
Chris@102 116 The check is performed by mapping the geographical coordinates
Chris@102 117 to spherical coordinates and using spherical_side_formula.
Chris@102 118 \ingroup strategies
Chris@102 119 \tparam Spheroid The reference spheroid model
Chris@102 120 \tparam Mapping The type of mapping of geographical to spherical latitude
Chris@102 121 \tparam CalculationType \tparam_calculation
Chris@102 122 */
Chris@102 123 template <typename Spheroid,
Chris@102 124 mapping_type Mapping = mapping_geodetic,
Chris@102 125 typename CalculationType = void>
Chris@102 126 class mapping_spherical_side_formula
Chris@102 127 {
Chris@102 128
Chris@102 129 public :
Chris@102 130 inline mapping_spherical_side_formula()
Chris@102 131 : m_mapper(Spheroid())
Chris@102 132 {}
Chris@102 133
Chris@102 134 explicit inline mapping_spherical_side_formula(Spheroid const& spheroid)
Chris@102 135 : m_mapper(spheroid)
Chris@102 136 {}
Chris@102 137
Chris@102 138 template <typename P1, typename P2, typename P>
Chris@102 139 inline int apply(P1 const& p1, P2 const& p2, P const& p)
Chris@102 140 {
Chris@102 141 typedef typename promote_floating_point
Chris@102 142 <
Chris@102 143 typename select_calculation_type_alt
Chris@102 144 <
Chris@102 145 CalculationType,
Chris@102 146 P1, P2, P
Chris@102 147 >::type
Chris@102 148 >::type calculation_type;
Chris@102 149
Chris@102 150 calculation_type lon1 = get_as_radian<0>(p1);
Chris@102 151 calculation_type lat1 = m_mapper.template apply<calculation_type>(get_as_radian<1>(p1));
Chris@102 152 calculation_type lon2 = get_as_radian<0>(p2);
Chris@102 153 calculation_type lat2 = m_mapper.template apply<calculation_type>(get_as_radian<1>(p2));
Chris@102 154 calculation_type lon = get_as_radian<0>(p);
Chris@102 155 calculation_type lat = m_mapper.template apply<calculation_type>(get_as_radian<1>(p));
Chris@102 156
Chris@102 157 return detail::spherical_side_formula(lon1, lat1, lon2, lat2, lon, lat);
Chris@102 158 }
Chris@102 159
Chris@102 160 private:
Chris@102 161 side::detail::mapper<Spheroid, Mapping> const m_mapper;
Chris@102 162 };
Chris@102 163
Chris@102 164 // The specialization for geodetic latitude which can be used directly
Chris@102 165 template <typename Spheroid,
Chris@102 166 typename CalculationType>
Chris@102 167 class mapping_spherical_side_formula<Spheroid, mapping_geodetic, CalculationType>
Chris@102 168 {
Chris@102 169
Chris@102 170 public :
Chris@102 171 inline mapping_spherical_side_formula() {}
Chris@102 172 explicit inline mapping_spherical_side_formula(Spheroid const& /*spheroid*/) {}
Chris@102 173
Chris@102 174 template <typename P1, typename P2, typename P>
Chris@102 175 static inline int apply(P1 const& p1, P2 const& p2, P const& p)
Chris@102 176 {
Chris@102 177 return spherical_side_formula<CalculationType>::apply(p1, p2, p);
Chris@102 178 }
Chris@102 179 };
Chris@102 180
Chris@102 181 }} // namespace strategy::side
Chris@102 182
Chris@102 183 }} // namespace boost::geometry
Chris@102 184
Chris@102 185 #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_MAPPING_SSF_HPP