Chris@102: // Boost.Geometry (aka GGL, Generic Geometry Library) Chris@102: Chris@102: // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands. Chris@102: Chris@102: // This file was modified by Oracle on 2014. Chris@102: // Modifications copyright (c) 2014 Oracle and/or its affiliates. Chris@102: Chris@102: // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle Chris@102: Chris@102: // Use, modification and distribution is subject to the Boost Software License, Chris@102: // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@102: // http://www.boost.org/LICENSE_1_0.txt) Chris@102: Chris@102: #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_MAPPING_SSF_HPP Chris@102: #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_MAPPING_SSF_HPP Chris@102: Chris@102: Chris@102: #include Chris@102: Chris@102: #include Chris@102: Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: Chris@102: #include Chris@102: #include Chris@102: Chris@102: Chris@102: namespace boost { namespace geometry Chris@102: { Chris@102: Chris@102: namespace strategy { namespace side Chris@102: { Chris@102: Chris@102: Chris@102: // An enumeration type defining types of mapping of geographical Chris@102: // latitude to spherical latitude. Chris@102: // See: http://en.wikipedia.org/wiki/Great_ellipse Chris@102: // http://en.wikipedia.org/wiki/Latitude#Auxiliary_latitudes Chris@102: enum mapping_type { mapping_geodetic, mapping_reduced, mapping_geocentric }; Chris@102: Chris@102: Chris@102: #ifndef DOXYGEN_NO_DETAIL Chris@102: namespace detail Chris@102: { Chris@102: Chris@102: template Chris@102: struct mapper Chris@102: { Chris@102: explicit inline mapper(Spheroid const& /*spheroid*/) {} Chris@102: Chris@102: template Chris@102: static inline CalculationType const& apply(CalculationType const& lat) Chris@102: { Chris@102: return lat; Chris@102: } Chris@102: }; Chris@102: Chris@102: template Chris@102: struct mapper Chris@102: { Chris@102: typedef typename promote_floating_point Chris@102: < Chris@102: typename radius_type::type Chris@102: >::type fraction_type; Chris@102: Chris@102: explicit inline mapper(Spheroid const& spheroid) Chris@102: { Chris@102: fraction_type const a = geometry::get_radius<0>(spheroid); Chris@102: fraction_type const b = geometry::get_radius<2>(spheroid); Chris@102: b_div_a = b / a; Chris@102: } Chris@102: Chris@102: template Chris@102: inline CalculationType apply(CalculationType const& lat) const Chris@102: { Chris@102: return atan(static_cast(b_div_a) * tan(lat)); Chris@102: } Chris@102: Chris@102: fraction_type b_div_a; Chris@102: }; Chris@102: Chris@102: template Chris@102: struct mapper Chris@102: { Chris@102: typedef typename promote_floating_point Chris@102: < Chris@102: typename radius_type::type Chris@102: >::type fraction_type; Chris@102: Chris@102: explicit inline mapper(Spheroid const& spheroid) Chris@102: { Chris@102: fraction_type const a = geometry::get_radius<0>(spheroid); Chris@102: fraction_type const b = geometry::get_radius<2>(spheroid); Chris@102: sqr_b_div_a = b / a; Chris@102: sqr_b_div_a *= sqr_b_div_a; Chris@102: } Chris@102: Chris@102: template Chris@102: inline CalculationType apply(CalculationType const& lat) const Chris@102: { Chris@102: return atan(static_cast(sqr_b_div_a) * tan(lat)); Chris@102: } Chris@102: Chris@102: fraction_type sqr_b_div_a; Chris@102: }; Chris@102: Chris@102: } Chris@102: #endif // DOXYGEN_NO_DETAIL Chris@102: Chris@102: Chris@102: /*! Chris@102: \brief Check at which side of a geographical segment a point lies Chris@102: left of segment (> 0), right of segment (< 0), on segment (0). Chris@102: The check is performed by mapping the geographical coordinates Chris@102: to spherical coordinates and using spherical_side_formula. Chris@102: \ingroup strategies Chris@102: \tparam Spheroid The reference spheroid model Chris@102: \tparam Mapping The type of mapping of geographical to spherical latitude Chris@102: \tparam CalculationType \tparam_calculation Chris@102: */ Chris@102: template Chris@102: class mapping_spherical_side_formula Chris@102: { Chris@102: Chris@102: public : Chris@102: inline mapping_spherical_side_formula() Chris@102: : m_mapper(Spheroid()) Chris@102: {} Chris@102: Chris@102: explicit inline mapping_spherical_side_formula(Spheroid const& spheroid) Chris@102: : m_mapper(spheroid) Chris@102: {} Chris@102: Chris@102: template Chris@102: inline int apply(P1 const& p1, P2 const& p2, P const& p) Chris@102: { Chris@102: typedef typename promote_floating_point Chris@102: < Chris@102: typename select_calculation_type_alt Chris@102: < Chris@102: CalculationType, Chris@102: P1, P2, P Chris@102: >::type Chris@102: >::type calculation_type; Chris@102: Chris@102: calculation_type lon1 = get_as_radian<0>(p1); Chris@102: calculation_type lat1 = m_mapper.template apply(get_as_radian<1>(p1)); Chris@102: calculation_type lon2 = get_as_radian<0>(p2); Chris@102: calculation_type lat2 = m_mapper.template apply(get_as_radian<1>(p2)); Chris@102: calculation_type lon = get_as_radian<0>(p); Chris@102: calculation_type lat = m_mapper.template apply(get_as_radian<1>(p)); Chris@102: Chris@102: return detail::spherical_side_formula(lon1, lat1, lon2, lat2, lon, lat); Chris@102: } Chris@102: Chris@102: private: Chris@102: side::detail::mapper const m_mapper; Chris@102: }; Chris@102: Chris@102: // The specialization for geodetic latitude which can be used directly Chris@102: template Chris@102: class mapping_spherical_side_formula Chris@102: { Chris@102: Chris@102: public : Chris@102: inline mapping_spherical_side_formula() {} Chris@102: explicit inline mapping_spherical_side_formula(Spheroid const& /*spheroid*/) {} Chris@102: Chris@102: template Chris@102: static inline int apply(P1 const& p1, P2 const& p2, P const& p) Chris@102: { Chris@102: return spherical_side_formula::apply(p1, p2, p); Chris@102: } Chris@102: }; Chris@102: Chris@102: }} // namespace strategy::side Chris@102: Chris@102: }} // namespace boost::geometry Chris@102: Chris@102: #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_MAPPING_SSF_HPP