Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / geometry / strategies / spherical / point_in_point.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
6 // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland
7
8 // This file was modified by Oracle on 2013, 2014, 2015, 2017, 2018, 2019.
9 // Modifications copyright (c) 2013-2019, Oracle and/or its affiliates.
10
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
13
14 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
15 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
16
17 // Use, modification and distribution is subject to the Boost Software License,
18 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
19 // http://www.boost.org/LICENSE_1_0.txt)
20
21
22 #ifndef BOOST_GEOMETRY_STRATEGY_SPHERICAL_POINT_IN_POINT_HPP
23 #define BOOST_GEOMETRY_STRATEGY_SPHERICAL_POINT_IN_POINT_HPP
24
25 #include <cstddef>
26
27 #include <boost/geometry/core/access.hpp>
28 #include <boost/geometry/core/radian_access.hpp>
29 #include <boost/geometry/core/coordinate_dimension.hpp>
30 #include <boost/geometry/core/coordinate_system.hpp>
31 #include <boost/geometry/core/coordinate_type.hpp>
32 #include <boost/geometry/core/cs.hpp>
33 #include <boost/geometry/core/tags.hpp>
34
35 #include <boost/geometry/algorithms/detail/normalize.hpp>
36 #include <boost/geometry/algorithms/dispatch/disjoint.hpp>
37 #include <boost/geometry/algorithms/transform.hpp>
38
39 #include <boost/geometry/geometries/helper_geometry.hpp>
40
41 #include <boost/geometry/strategies/cartesian/point_in_point.hpp>
42 #include <boost/geometry/strategies/covered_by.hpp>
43 #include <boost/geometry/strategies/strategy_transform.hpp>
44 #include <boost/geometry/strategies/within.hpp>
45
46 #include <boost/geometry/util/math.hpp>
47 #include <boost/geometry/util/select_most_precise.hpp>
48
49
50 namespace boost { namespace geometry
51 {
52
53 #ifndef DOXYGEN_NO_DETAIL
54 namespace detail { namespace within
55 {
56
57 class point_point_on_spheroid
58 {
59 public:
60     typedef spherical_tag cs_tag;
61
62 private:
63     template <typename Point1, typename Point2, bool SameUnits>
64     struct are_same_points
65     {
66         static inline bool apply(Point1 const& point1, Point2 const& point2)
67         {
68             typedef typename helper_geometry<Point1>::type helper_point_type1;
69             typedef typename helper_geometry<Point2>::type helper_point_type2;
70
71             helper_point_type1 point1_normalized;
72             strategy::normalize::spherical_point::apply(point1, point1_normalized);
73             helper_point_type2 point2_normalized;            
74             strategy::normalize::spherical_point::apply(point2, point2_normalized);
75
76             return point_point_generic
77                 <
78                     0, dimension<Point1>::value
79                 >::apply(point1_normalized, point2_normalized);
80         }
81     };
82
83     template <typename Point1, typename Point2>
84     struct are_same_points<Point1, Point2, false> // points have different units
85     {
86         static inline bool apply(Point1 const& point1, Point2 const& point2)
87         {
88             typedef typename geometry::select_most_precise
89                 <
90                     typename fp_coordinate_type<Point1>::type,
91                     typename fp_coordinate_type<Point2>::type
92                 >::type calculation_type;
93
94             typename helper_geometry
95                 <
96                     Point1, calculation_type, radian
97                 >::type helper_point1, helper_point2;
98
99             Point1 point1_normalized;
100             strategy::normalize::spherical_point::apply(point1, point1_normalized);
101             Point2 point2_normalized;
102             strategy::normalize::spherical_point::apply(point2, point2_normalized);
103
104             geometry::transform(point1_normalized, helper_point1);
105             geometry::transform(point2_normalized, helper_point2);
106
107             return point_point_generic
108                 <
109                     0, dimension<Point1>::value
110                 >::apply(helper_point1, helper_point2);
111         }
112     };
113
114 public:
115     template <typename Point1, typename Point2>
116     static inline bool apply(Point1 const& point1, Point2 const& point2)
117     {
118         return are_same_points
119             <
120                 Point1,
121                 Point2,
122                 boost::is_same
123                     <
124                         typename detail::cs_angular_units<Point1>::type,
125                         typename detail::cs_angular_units<Point2>::type
126                     >::value
127             >::apply(point1, point2);
128     }
129 };
130
131 }} // namespace detail::within
132 #endif // DOXYGEN_NO_DETAIL
133
134
135 namespace strategy { namespace within
136 {
137
138 struct spherical_point_point
139     : geometry::detail::within::point_point_on_spheroid
140 {};
141
142
143 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
144 namespace services
145 {
146
147 template <typename PointLike1, typename PointLike2, typename Tag1, typename Tag2>
148 struct default_strategy<PointLike1, PointLike2, Tag1, Tag2, pointlike_tag, pointlike_tag, spherical_tag, spherical_tag>
149 {
150     typedef strategy::within::spherical_point_point type;
151 };
152
153 } // namespace services
154 #endif
155
156
157 }} // namespace strategy::within
158
159
160 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
161 namespace strategy { namespace covered_by { namespace services
162 {
163
164 template <typename PointLike1, typename PointLike2, typename Tag1, typename Tag2>
165 struct default_strategy<PointLike1, PointLike2, Tag1, Tag2, pointlike_tag, pointlike_tag, spherical_tag, spherical_tag>
166 {
167     typedef strategy::within::spherical_point_point type;
168 };
169
170 }}} // namespace strategy::covered_by::services
171 #endif
172
173
174 }} // namespace boost::geometry
175
176
177 #endif // BOOST_GEOMETRY_STRATEGY_SPHERICAL_POINT_IN_POINT_HPP