]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/strategies/agnostic/point_in_box_by_side.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / geometry / strategies / agnostic / point_in_box_by_side.hpp
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 2018.
8 // Modifications copyright (c) 2018 Oracle and/or its affiliates.
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10
11 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
12 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
13
14 // Use, modification and distribution is subject to the Boost Software License,
15 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
16 // http://www.boost.org/LICENSE_1_0.txt)
17
18 #ifndef BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_POINT_IN_BOX_BY_SIDE_HPP
19 #define BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_POINT_IN_BOX_BY_SIDE_HPP
20
21 #include <boost/array.hpp>
22 #include <boost/core/ignore_unused.hpp>
23 #include <boost/geometry/core/access.hpp>
24 #include <boost/geometry/core/coordinate_dimension.hpp>
25 #include <boost/geometry/algorithms/assign.hpp>
26 #include <boost/geometry/strategies/covered_by.hpp>
27 #include <boost/geometry/strategies/side.hpp>
28 #include <boost/geometry/strategies/within.hpp>
29
30
31 namespace boost { namespace geometry { namespace strategy
32 {
33
34 namespace within
35 {
36
37 struct decide_within
38 {
39 static inline bool apply(int side, bool& result)
40 {
41 if (side != 1)
42 {
43 result = false;
44 return false;
45 }
46 return true; // continue
47 }
48 };
49
50 struct decide_covered_by
51 {
52 static inline bool apply(int side, bool& result)
53 {
54 if (side != 1)
55 {
56 result = side >= 0;
57 return false;
58 }
59 return true; // continue
60 }
61 };
62
63
64 // WARNING
65 // This strategy is not suitable for boxes in non-cartesian CSes having edges
66 // longer than 180deg because e.g. the SSF formula picks the side of the closer
67 // longitude, so for long edges the side is the opposite.
68 template <typename Decide = decide_within>
69 struct point_in_box_by_side
70 {
71 template <typename Point, typename Box>
72 static inline bool apply(Point const& point, Box const& box)
73 {
74 typedef typename strategy::side::services::default_strategy
75 <
76 typename cs_tag<Box>::type
77 >::type side_strategy_type;
78
79 // Create (counterclockwise) array of points, the fifth one closes it
80 // Every point should be on the LEFT side (=1), or ON the border (=0),
81 // So >= 1 or >= 0
82 boost::array<typename point_type<Box>::type, 5> bp;
83 geometry::detail::assign_box_corners_oriented<true>(box, bp);
84 bp[4] = bp[0];
85
86 bool result = true;
87 side_strategy_type strategy;
88 boost::ignore_unused(strategy);
89
90 for (int i = 1; i < 5; i++)
91 {
92 int const side = strategy.apply(point, bp[i - 1], bp[i]);
93 if (! Decide::apply(side, result))
94 {
95 return result;
96 }
97 }
98
99 return result;
100 }
101 };
102
103
104 } // namespace within
105
106
107 }}} // namespace boost::geometry::strategy
108
109
110 #endif // BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_POINT_IN_BOX_BY_SIDE_HPP