1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
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
11 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
12 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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)
18 #ifndef BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_POINT_IN_BOX_BY_SIDE_HPP
19 #define BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_POINT_IN_BOX_BY_SIDE_HPP
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>
31 namespace boost { namespace geometry { namespace strategy
39 static inline bool apply(int side, bool& result)
46 return true; // continue
50 struct decide_covered_by
52 static inline bool apply(int side, bool& result)
59 return true; // continue
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
71 template <typename Point, typename Box>
72 static inline bool apply(Point const& point, Box const& box)
74 typedef typename strategy::side::services::default_strategy
76 typename cs_tag<Box>::type
77 >::type side_strategy_type;
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),
82 boost::array<typename point_type<Box>::type, 5> bp;
83 geometry::detail::assign_box_corners_oriented<true>(box, bp);
87 side_strategy_type strategy;
88 boost::ignore_unused(strategy);
90 for (int i = 1; i < 5; i++)
92 int const side = strategy.apply(point, bp[i - 1], bp[i]);
93 if (! Decide::apply(side, result))
104 } // namespace within
107 }}} // namespace boost::geometry::strategy
110 #endif // BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_POINT_IN_BOX_BY_SIDE_HPP