1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // This file was modified by Oracle on 2013, 2014, 2015, 2017.
6 // Modifications copyright (c) 2013-2017 Oracle and/or its affiliates.
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
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)
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_POINT_GEOMETRY_HPP
15 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_POINT_GEOMETRY_HPP
17 #include <boost/geometry/algorithms/detail/within/point_in_geometry.hpp>
18 //#include <boost/geometry/algorithms/within.hpp>
19 //#include <boost/geometry/algorithms/covered_by.hpp>
21 #include <boost/geometry/algorithms/detail/relate/result.hpp>
22 #include <boost/geometry/algorithms/detail/relate/topology_check.hpp>
24 #include <boost/geometry/util/condition.hpp>
26 namespace boost { namespace geometry
29 #ifndef DOXYGEN_NO_DETAIL
30 namespace detail { namespace relate {
33 template <typename Point, typename Geometry, bool Transpose = false>
36 // TODO: interrupt only if the topology check is complex
38 static const bool interruption_enabled = true;
40 template <typename Result, typename Strategy>
41 static inline void apply(Point const& point, Geometry const& geometry, Result & result, Strategy const& strategy)
43 int pig = detail::within::point_in_geometry(point, geometry, strategy);
45 if ( pig > 0 ) // within
47 relate::set<interior, interior, '0', Transpose>(result);
51 relate::set<interior, boundary, '0', Transpose>(result);
53 else // pig < 0 - not within
55 relate::set<interior, exterior, '0', Transpose>(result);
58 relate::set<exterior, exterior, result_dimension<Point>::value, Transpose>(result);
60 if ( BOOST_GEOMETRY_CONDITION(result.interrupt) )
63 typedef detail::relate::topology_check<Geometry> tc_t;
64 if ( relate::may_update<exterior, interior, tc_t::interior, Transpose>(result)
65 || relate::may_update<exterior, boundary, tc_t::boundary, Transpose>(result) )
67 // the point is on the boundary
70 // NOTE: even for MLs, if there is at least one boundary point,
71 // somewhere there must be another one
72 relate::set<exterior, interior, tc_t::interior, Transpose>(result);
73 relate::set<exterior, boundary, tc_t::boundary, Transpose>(result);
77 // check if there is a boundary in Geometry
79 if ( tc.has_interior() )
80 relate::set<exterior, interior, tc_t::interior, Transpose>(result);
81 if ( tc.has_boundary() )
82 relate::set<exterior, boundary, tc_t::boundary, Transpose>(result);
88 // transposed result of point_geometry
89 template <typename Geometry, typename Point>
92 // TODO: interrupt only if the topology check is complex
94 static const bool interruption_enabled = true;
96 template <typename Result, typename Strategy>
97 static inline void apply(Geometry const& geometry, Point const& point, Result & result, Strategy const& strategy)
99 point_geometry<Point, Geometry, true>::apply(point, geometry, result, strategy);
103 // TODO: rewrite the folowing:
105 //// NOTE: Those tests should be consistent with within(Point, Box) and covered_by(Point, Box)
106 //// There is no EPS used in those functions, values are compared using < or <=
107 //// so comparing MIN and MAX in the same way should be fine
109 //template <typename Box, std::size_t I = 0, std::size_t D = geometry::dimension<Box>::value>
110 //struct box_has_interior
112 // static inline bool apply(Box const& box)
114 // return geometry::get<min_corner, I>(box) < geometry::get<max_corner, I>(box)
115 // && box_has_interior<Box, I + 1, D>::apply(box);
119 //template <typename Box, std::size_t D>
120 //struct box_has_interior<Box, D, D>
122 // static inline bool apply(Box const&) { return true; }
125 //// NOTE: especially important here (see the NOTE above).
127 //template <typename Box, std::size_t I = 0, std::size_t D = geometry::dimension<Box>::value>
128 //struct box_has_equal_min_max
130 // static inline bool apply(Box const& box)
132 // return geometry::get<min_corner, I>(box) == geometry::get<max_corner, I>(box)
133 // && box_has_equal_min_max<Box, I + 1, D>::apply(box);
137 //template <typename Box, std::size_t D>
138 //struct box_has_equal_min_max<Box, D, D>
140 // static inline bool apply(Box const&) { return true; }
143 //template <typename Point, typename Box>
146 // static inline result apply(Point const& point, Box const& box)
150 // if ( geometry::within(point, box) ) // this also means that the box has interior
152 // return result("0FFFFFTTT");
154 // else if ( geometry::covered_by(point, box) ) // point is on the boundary
156 // //if ( box_has_interior<Box>::apply(box) )
158 // // return result("F0FFFFTTT");
160 // //else if ( box_has_equal_min_max<Box>::apply(box) ) // no boundary outside point
162 // // return result("F0FFFFFFT");
164 // //else // no interior outside point
166 // // return result("F0FFFFFTT");
168 // return result("F0FFFF**T");
172 // /*if ( box_has_interior<Box>::apply(box) )
174 // return result("FF0FFFTTT");
178 // return result("FF0FFFFTT");
180 // return result("FF0FFF*TT");
187 //template <typename Box, typename Point>
190 // static inline result apply(Box const& box, Point const& point)
192 // if ( geometry::within(point, box) )
193 // return result("0FTFFTFFT");
194 // else if ( geometry::covered_by(point, box) )
195 // return result("FF*0F*FFT");
197 // return result("FF*FFT0FT");
201 }} // namespace detail::relate
202 #endif // DOXYGEN_NO_DETAIL
204 }} // namespace boost::geometry
206 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_POINT_GEOMETRY_HPP