1 // Boost.Geometry (aka GGL, Generic Geometry Library) 2 3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. 4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. 5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. 6 7 // This file was modified by Oracle on 2014, 2016, 2018. 8 // Modifications copyright (c) 2014-2018 Oracle and/or its affiliates. 9 10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle 11 12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library 13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. 14 15 // Use, modification and distribution is subject to the Boost Software License, 16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 17 // http://www.boost.org/LICENSE_1_0.txt) 18 19 #ifndef BOOST_GEOMETRY_SRS_SPHERE_HPP 20 #define BOOST_GEOMETRY_SRS_SPHERE_HPP 21 22 23 #include <cstddef> 24 25 #include <boost/static_assert.hpp> 26 27 #include <boost/geometry/core/radius.hpp> 28 #include <boost/geometry/core/tag.hpp> 29 #include <boost/geometry/core/tags.hpp> 30 31 32 namespace boost { namespace geometry 33 { 34 35 namespace srs 36 { 37 38 /*! 39 \brief Defines sphere radius value for use in spherical CS calculations 40 \ingroup srs 41 \tparam RadiusType tparam_radius 42 */ 43 template <typename RadiusType> 44 class sphere 45 { 46 public: sphere(RadiusType const & r)47 explicit sphere(RadiusType const& r) 48 : m_r(r) 49 {} 50 sphere()51 sphere() 52 : m_r(RadiusType((2.0 * 6378137.0 + 6356752.3142451793) / 3.0)) 53 {} 54 55 template <std::size_t I> get_radius() const56 RadiusType get_radius() const 57 { 58 BOOST_STATIC_ASSERT(I < 3); 59 60 return m_r; 61 } 62 63 template <std::size_t I> set_radius(RadiusType const & radius)64 void set_radius(RadiusType const& radius) 65 { 66 BOOST_STATIC_ASSERT(I < 3); 67 68 m_r = radius; 69 } 70 71 private: 72 RadiusType m_r; // radius 73 }; 74 75 } // namespace srs 76 77 // Traits specializations for sphere 78 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS 79 namespace traits 80 { 81 82 template <typename RadiusType> 83 struct tag< srs::sphere<RadiusType> > 84 { 85 typedef srs_sphere_tag type; 86 }; 87 88 template <typename RadiusType> 89 struct radius_type< srs::sphere<RadiusType> > 90 { 91 typedef RadiusType type; 92 }; 93 94 template <typename RadiusType, std::size_t Dimension> 95 struct radius_access<srs::sphere<RadiusType>, Dimension> 96 { 97 typedef srs::sphere<RadiusType> sphere_type; 98 getboost::geometry::traits::radius_access99 static inline RadiusType get(sphere_type const& s) 100 { 101 return s.template get_radius<Dimension>(); 102 } 103 setboost::geometry::traits::radius_access104 static inline void set(sphere_type& s, RadiusType const& value) 105 { 106 s.template set_radius<Dimension>(value); 107 } 108 }; 109 110 } // namespace traits 111 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS 112 113 114 }} // namespace boost::geometry 115 116 117 #endif // BOOST_GEOMETRY_SRS_SPHERE_HPP 118