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