intersection_result.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Use, modification and distribution is subject to the Boost Software License,
  4. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_GEOMETRY_STRATEGIES_INTERSECTION_RESULT_HPP
  7. #define BOOST_GEOMETRY_STRATEGIES_INTERSECTION_RESULT_HPP
  8. #if defined(HAVE_MATRIX_AS_STRING)
  9. #include <string>
  10. #endif
  11. #include <cstddef>
  12. namespace boost { namespace geometry
  13. {
  14. /*!
  15. \brief Dimensionally Extended 9 Intersection Matrix
  16. \details
  17. \ingroup overlay
  18. \see http://gis.hsr.ch/wiki/images/3/3d/9dem_springer.pdf
  19. */
  20. struct de9im
  21. {
  22. int ii, ib, ie,
  23. bi, bb, be,
  24. ei, eb, ee;
  25. inline de9im()
  26. : ii(-1), ib(-1), ie(-1)
  27. , bi(-1), bb(-1), be(-1)
  28. , ei(-1), eb(-1), ee(-1)
  29. {
  30. }
  31. inline de9im(int ii0, int ib0, int ie0,
  32. int bi0, int bb0, int be0,
  33. int ei0, int eb0, int ee0)
  34. : ii(ii0), ib(ib0), ie(ie0)
  35. , bi(bi0), bb(bb0), be(be0)
  36. , ei(ei0), eb(eb0), ee(ee0)
  37. {}
  38. inline bool equals() const
  39. {
  40. return ii >= 0 && ie < 0 && be < 0 && ei < 0 && eb < 0;
  41. }
  42. inline bool disjoint() const
  43. {
  44. return ii < 0 && ib < 0 && bi < 0 && bb < 0;
  45. }
  46. inline bool intersects() const
  47. {
  48. return ii >= 0 || bb >= 0 || bi >= 0 || ib >= 0;
  49. }
  50. inline bool touches() const
  51. {
  52. return ii < 0 && (bb >= 0 || bi >= 0 || ib >= 0);
  53. }
  54. inline bool crosses() const
  55. {
  56. return (ii >= 0 && ie >= 0) || (ii == 0);
  57. }
  58. inline bool overlaps() const
  59. {
  60. return ii >= 0 && ie >= 0 && ei >= 0;
  61. }
  62. inline bool within() const
  63. {
  64. return ii >= 0 && ie < 0 && be < 0;
  65. }
  66. inline bool contains() const
  67. {
  68. return ii >= 0 && ei < 0 && eb < 0;
  69. }
  70. static inline char as_char(int v)
  71. {
  72. return v >= 0 && v < 10 ? ('0' + char(v)) : '-';
  73. }
  74. #if defined(HAVE_MATRIX_AS_STRING)
  75. inline std::string matrix_as_string(std::string const& tab, std::string const& nl) const
  76. {
  77. std::string ret;
  78. ret.reserve(9 + tab.length() * 3 + nl.length() * 3);
  79. ret += tab; ret += as_char(ii); ret += as_char(ib); ret += as_char(ie); ret += nl;
  80. ret += tab; ret += as_char(bi); ret += as_char(bb); ret += as_char(be); ret += nl;
  81. ret += tab; ret += as_char(ei); ret += as_char(eb); ret += as_char(ee);
  82. return ret;
  83. }
  84. inline std::string matrix_as_string() const
  85. {
  86. return matrix_as_string("", "");
  87. }
  88. #endif
  89. };
  90. struct de9im_segment : public de9im
  91. {
  92. bool collinear; // true if segments are aligned (for equal,overlap,touch)
  93. bool opposite; // true if direction is reversed (for equal,overlap,touch)
  94. bool parallel; // true if disjoint but parallel
  95. bool degenerate; // true for segment(s) of zero length
  96. double ra, rb; // temp
  97. inline de9im_segment()
  98. : de9im()
  99. , collinear(false)
  100. , opposite(false)
  101. , parallel(false)
  102. , degenerate(false)
  103. {}
  104. inline de9im_segment(double a, double b,
  105. int ii0, int ib0, int ie0,
  106. int bi0, int bb0, int be0,
  107. int ei0, int eb0, int ee0,
  108. bool c = false, bool o = false, bool p = false, bool d = false)
  109. : de9im(ii0, ib0, ie0, bi0, bb0, be0, ei0, eb0, ee0)
  110. , collinear(c)
  111. , opposite(o)
  112. , parallel(p)
  113. , degenerate(d)
  114. , ra(a), rb(b)
  115. {}
  116. #if defined(HAVE_MATRIX_AS_STRING)
  117. inline std::string as_string() const
  118. {
  119. std::string ret = matrix_as_string();
  120. ret += collinear ? "c" : "-";
  121. ret += opposite ? "o" : "-";
  122. return ret;
  123. }
  124. #endif
  125. };
  126. template <typename Point>
  127. struct segment_intersection_points
  128. {
  129. std::size_t count;
  130. Point intersections[2];
  131. typedef Point point_type;
  132. segment_intersection_points()
  133. : count(0)
  134. {}
  135. };
  136. }} // namespace boost::geometry
  137. #endif // BOOST_GEOMETRY_STRATEGIES_INTERSECTION_RESULT_HPP