point_geometry.hpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2013, 2014, 2015, 2017, 2018.
  4. // Modifications copyright (c) 2013-2018 Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_POINT_GEOMETRY_HPP
  10. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_POINT_GEOMETRY_HPP
  11. #include <boost/geometry/algorithms/detail/within/point_in_geometry.hpp>
  12. //#include <boost/geometry/algorithms/within.hpp>
  13. //#include <boost/geometry/algorithms/covered_by.hpp>
  14. #include <boost/geometry/algorithms/detail/relate/result.hpp>
  15. #include <boost/geometry/algorithms/detail/relate/topology_check.hpp>
  16. #include <boost/geometry/util/condition.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. #ifndef DOXYGEN_NO_DETAIL
  20. namespace detail { namespace relate {
  21. // non-point geometry
  22. template <typename Point, typename Geometry, bool Transpose = false>
  23. struct point_geometry
  24. {
  25. // TODO: interrupt only if the topology check is complex
  26. static const bool interruption_enabled = true;
  27. template <typename Result, typename Strategy>
  28. static inline void apply(Point const& point, Geometry const& geometry, Result & result, Strategy const& strategy)
  29. {
  30. int pig = detail::within::point_in_geometry(point, geometry, strategy);
  31. if ( pig > 0 ) // within
  32. {
  33. relate::set<interior, interior, '0', Transpose>(result);
  34. }
  35. else if ( pig == 0 )
  36. {
  37. relate::set<interior, boundary, '0', Transpose>(result);
  38. }
  39. else // pig < 0 - not within
  40. {
  41. relate::set<interior, exterior, '0', Transpose>(result);
  42. }
  43. relate::set<exterior, exterior, result_dimension<Point>::value, Transpose>(result);
  44. if ( BOOST_GEOMETRY_CONDITION(result.interrupt) )
  45. return;
  46. typedef detail::relate::topology_check
  47. <
  48. Geometry,
  49. typename Strategy::equals_point_point_strategy_type
  50. > tc_t;
  51. if ( relate::may_update<exterior, interior, tc_t::interior, Transpose>(result)
  52. || relate::may_update<exterior, boundary, tc_t::boundary, Transpose>(result) )
  53. {
  54. // the point is on the boundary
  55. if ( pig == 0 )
  56. {
  57. // NOTE: even for MLs, if there is at least one boundary point,
  58. // somewhere there must be another one
  59. relate::set<exterior, interior, tc_t::interior, Transpose>(result);
  60. relate::set<exterior, boundary, tc_t::boundary, Transpose>(result);
  61. }
  62. else
  63. {
  64. // check if there is a boundary in Geometry
  65. tc_t tc(geometry);
  66. if ( tc.has_interior() )
  67. relate::set<exterior, interior, tc_t::interior, Transpose>(result);
  68. if ( tc.has_boundary() )
  69. relate::set<exterior, boundary, tc_t::boundary, Transpose>(result);
  70. }
  71. }
  72. }
  73. };
  74. // transposed result of point_geometry
  75. template <typename Geometry, typename Point>
  76. struct geometry_point
  77. {
  78. // TODO: interrupt only if the topology check is complex
  79. static const bool interruption_enabled = true;
  80. template <typename Result, typename Strategy>
  81. static inline void apply(Geometry const& geometry, Point const& point, Result & result, Strategy const& strategy)
  82. {
  83. point_geometry<Point, Geometry, true>::apply(point, geometry, result, strategy);
  84. }
  85. };
  86. // TODO: rewrite the folowing:
  87. //// NOTE: Those tests should be consistent with within(Point, Box) and covered_by(Point, Box)
  88. //// There is no EPS used in those functions, values are compared using < or <=
  89. //// so comparing MIN and MAX in the same way should be fine
  90. //
  91. //template <typename Box, std::size_t I = 0, std::size_t D = geometry::dimension<Box>::value>
  92. //struct box_has_interior
  93. //{
  94. // static inline bool apply(Box const& box)
  95. // {
  96. // return geometry::get<min_corner, I>(box) < geometry::get<max_corner, I>(box)
  97. // && box_has_interior<Box, I + 1, D>::apply(box);
  98. // }
  99. //};
  100. //
  101. //template <typename Box, std::size_t D>
  102. //struct box_has_interior<Box, D, D>
  103. //{
  104. // static inline bool apply(Box const&) { return true; }
  105. //};
  106. //
  107. //// NOTE: especially important here (see the NOTE above).
  108. //
  109. //template <typename Box, std::size_t I = 0, std::size_t D = geometry::dimension<Box>::value>
  110. //struct box_has_equal_min_max
  111. //{
  112. // static inline bool apply(Box const& box)
  113. // {
  114. // return geometry::get<min_corner, I>(box) == geometry::get<max_corner, I>(box)
  115. // && box_has_equal_min_max<Box, I + 1, D>::apply(box);
  116. // }
  117. //};
  118. //
  119. //template <typename Box, std::size_t D>
  120. //struct box_has_equal_min_max<Box, D, D>
  121. //{
  122. // static inline bool apply(Box const&) { return true; }
  123. //};
  124. //
  125. //template <typename Point, typename Box>
  126. //struct point_box
  127. //{
  128. // static inline result apply(Point const& point, Box const& box)
  129. // {
  130. // result res;
  131. //
  132. // if ( geometry::within(point, box) ) // this also means that the box has interior
  133. // {
  134. // return result("0FFFFFTTT");
  135. // }
  136. // else if ( geometry::covered_by(point, box) ) // point is on the boundary
  137. // {
  138. // //if ( box_has_interior<Box>::apply(box) )
  139. // //{
  140. // // return result("F0FFFFTTT");
  141. // //}
  142. // //else if ( box_has_equal_min_max<Box>::apply(box) ) // no boundary outside point
  143. // //{
  144. // // return result("F0FFFFFFT");
  145. // //}
  146. // //else // no interior outside point
  147. // //{
  148. // // return result("F0FFFFFTT");
  149. // //}
  150. // return result("F0FFFF**T");
  151. // }
  152. // else
  153. // {
  154. // /*if ( box_has_interior<Box>::apply(box) )
  155. // {
  156. // return result("FF0FFFTTT");
  157. // }
  158. // else
  159. // {
  160. // return result("FF0FFFFTT");
  161. // }*/
  162. // return result("FF0FFF*TT");
  163. // }
  164. //
  165. // return res;
  166. // }
  167. //};
  168. //
  169. //template <typename Box, typename Point>
  170. //struct box_point
  171. //{
  172. // static inline result apply(Box const& box, Point const& point)
  173. // {
  174. // if ( geometry::within(point, box) )
  175. // return result("0FTFFTFFT");
  176. // else if ( geometry::covered_by(point, box) )
  177. // return result("FF*0F*FFT");
  178. // else
  179. // return result("FF*FFT0FT");
  180. // }
  181. //};
  182. }} // namespace detail::relate
  183. #endif // DOXYGEN_NO_DETAIL
  184. }} // namespace boost::geometry
  185. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_POINT_GEOMETRY_HPP