123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_MAPPING_SSF_HPP
- #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_MAPPING_SSF_HPP
- #include <boost/core/ignore_unused.hpp>
- #include <boost/geometry/core/coordinate_promotion.hpp>
- #include <boost/geometry/core/radius.hpp>
- #include <boost/geometry/util/math.hpp>
- #include <boost/geometry/util/select_calculation_type.hpp>
- #include <boost/geometry/strategies/side.hpp>
- #include <boost/geometry/strategies/spherical/ssf.hpp>
- namespace boost { namespace geometry
- {
- namespace strategy { namespace side
- {
- enum mapping_type { mapping_geodetic, mapping_reduced, mapping_geocentric };
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail
- {
- template <typename Spheroid, mapping_type Mapping>
- struct mapper
- {
- explicit inline mapper(Spheroid const& ) {}
- template <typename CalculationType>
- static inline CalculationType const& apply(CalculationType const& lat)
- {
- return lat;
- }
- };
- template <typename Spheroid>
- struct mapper<Spheroid, mapping_reduced>
- {
- typedef typename promote_floating_point
- <
- typename radius_type<Spheroid>::type
- >::type fraction_type;
- explicit inline mapper(Spheroid const& spheroid)
- {
- fraction_type const a = geometry::get_radius<0>(spheroid);
- fraction_type const b = geometry::get_radius<2>(spheroid);
- b_div_a = b / a;
- }
- template <typename CalculationType>
- inline CalculationType apply(CalculationType const& lat) const
- {
- return atan(static_cast<CalculationType>(b_div_a) * tan(lat));
- }
- fraction_type b_div_a;
- };
- template <typename Spheroid>
- struct mapper<Spheroid, mapping_geocentric>
- {
- typedef typename promote_floating_point
- <
- typename radius_type<Spheroid>::type
- >::type fraction_type;
- explicit inline mapper(Spheroid const& spheroid)
- {
- fraction_type const a = geometry::get_radius<0>(spheroid);
- fraction_type const b = geometry::get_radius<2>(spheroid);
- sqr_b_div_a = b / a;
- sqr_b_div_a *= sqr_b_div_a;
- }
- template <typename CalculationType>
- inline CalculationType apply(CalculationType const& lat) const
- {
- return atan(static_cast<CalculationType>(sqr_b_div_a) * tan(lat));
- }
- fraction_type sqr_b_div_a;
- };
- }
- #endif
- template <typename Spheroid,
- mapping_type Mapping = mapping_geodetic,
- typename CalculationType = void>
- class mapping_spherical_side_formula
- {
- public :
- inline mapping_spherical_side_formula()
- : m_mapper(Spheroid())
- {}
- explicit inline mapping_spherical_side_formula(Spheroid const& spheroid)
- : m_mapper(spheroid)
- {}
- template <typename P1, typename P2, typename P>
- inline int apply(P1 const& p1, P2 const& p2, P const& p) const
- {
- typedef typename promote_floating_point
- <
- typename select_calculation_type_alt
- <
- CalculationType,
- P1, P2, P
- >::type
- >::type calculation_type;
- calculation_type lon1 = get_as_radian<0>(p1);
- calculation_type lat1 = m_mapper.template apply<calculation_type>(get_as_radian<1>(p1));
- calculation_type lon2 = get_as_radian<0>(p2);
- calculation_type lat2 = m_mapper.template apply<calculation_type>(get_as_radian<1>(p2));
- calculation_type lon = get_as_radian<0>(p);
- calculation_type lat = m_mapper.template apply<calculation_type>(get_as_radian<1>(p));
- return detail::spherical_side_formula(lon1, lat1, lon2, lat2, lon, lat);
- }
- private:
- side::detail::mapper<Spheroid, Mapping> const m_mapper;
- };
- template <typename Spheroid,
- typename CalculationType>
- class mapping_spherical_side_formula<Spheroid, mapping_geodetic, CalculationType>
- {
- public :
- inline mapping_spherical_side_formula() {}
- explicit inline mapping_spherical_side_formula(Spheroid const& ) {}
- template <typename P1, typename P2, typename P>
- static inline int apply(P1 const& p1, P2 const& p2, P const& p)
- {
- return spherical_side_formula<CalculationType>::apply(p1, p2, p);
- }
- };
- }}
- }}
- #endif
|