1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
5 // This file was modified by Oracle on 2013, 2014, 2015, 2019.
6 // Modifications copyright (c) 2013-2019 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_DE9IM_HPP
15 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_DE9IM_HPP
17 #include <boost/mpl/is_sequence.hpp>
18 #include <boost/mpl/push_back.hpp>
19 #include <boost/mpl/vector.hpp>
20 #include <boost/mpl/vector_c.hpp>
21 #include <boost/static_assert.hpp>
22 #include <boost/tuple/tuple.hpp>
24 #include <boost/geometry/algorithms/detail/relate/result.hpp>
25 #include <boost/geometry/core/topological_dimension.hpp>
26 #include <boost/geometry/core/tag.hpp>
28 // TEMP - move this header to geometry/detail
29 #include <boost/geometry/index/detail/tuples.hpp>
31 namespace boost { namespace geometry
38 \brief DE-9IM model intersection matrix.
40 \details This matrix can be used to express spatial relations as defined in
41 Dimensionally Extended 9-Intersection Model.
43 \qbk{[heading See also]}
44 \qbk{* [link geometry.reference.algorithms.relation relation]}
47 : public detail::relate::matrix<3, 3>
49 #ifdef DOXYGEN_INVOKED
52 \brief Initializes all of the matrix elements to F
56 \brief Subscript operator
57 \param index The index of the element
60 char operator[](std::size_t index) const;
62 \brief Returns the iterator to the first element
63 \return const RandomAccessIterator
65 const_iterator begin() const;
67 \brief Returns the iterator past the last element
68 \return const RandomAccessIterator
70 const_iterator end() const;
72 \brief Returns the number of elements
75 static std::size_t size();
77 \brief Returns raw pointer to elements
78 \return const pointer to array of elements
80 inline const char * data() const;
82 \brief Returns std::string containing elements
83 \return string containing elements
85 inline std::string str() const;
90 \brief DE-9IM model intersection mask.
92 \details This mask can be used to check spatial relations as defined in
93 Dimensionally Extended 9-Intersection Model.
95 \qbk{[heading See also]}
96 \qbk{* [link geometry.reference.algorithms.relate relate]}
99 : public detail::relate::mask<3, 3>
101 typedef detail::relate::mask<3, 3> base_type;
105 \brief The constructor.
106 \param code The mask pattern.
108 inline explicit mask(const char* code)
113 \brief The constructor.
114 \param code The mask pattern.
116 inline explicit mask(std::string const& code)
117 : base_type(code.c_str(), code.size())
124 \brief DE-9IM model intersection mask (static version).
126 \details This mask can be used to check spatial relations as defined in
127 Dimensionally Extended 9-Intersection Model.
128 \tparam II Interior/Interior intersection mask element
129 \tparam IB Interior/Boundary intersection mask element
130 \tparam IE Interior/Exterior intersection mask element
131 \tparam BI Boundary/Interior intersection mask element
132 \tparam BB Boundary/Boundary intersection mask element
133 \tparam BE Boundary/Exterior intersection mask element
134 \tparam EI Exterior/Interior intersection mask element
135 \tparam EB Exterior/Boundary intersection mask element
136 \tparam EE Exterior/Exterior intersection mask element
138 \qbk{[heading See also]}
139 \qbk{* [link geometry.reference.algorithms.relate relate]}
143 char II = '*', char IB = '*', char IE = '*',
144 char BI = '*', char BB = '*', char BE = '*',
145 char EI = '*', char EB = '*', char EE = '*'
148 : public detail::relate::static_mask
152 char, II, IB, IE, BI, BB, BE, EI, EB, EE
160 namespace detail { namespace de9im
163 // a small helper util for ORing static masks
169 bool IsSeq = boost::mpl::is_sequence<Seq>::value
173 typedef typename boost::mpl::push_back
180 template <typename Seq, typename T>
181 struct push_back<Seq, T, false>
184 }} // namespace detail::de9im
193 boost::tuples::cons<mask, boost::tuples::null_type>
195 operator||(mask const& m1, mask const& m2)
197 namespace bt = boost::tuples;
199 return bt::cons<mask, bt::cons<mask, bt::null_type> >
200 ( m1, bt::cons<mask, bt::null_type>(m2, bt::null_type()) );
203 template <typename Tail>
205 typename index::detail::tuples::push_back
207 boost::tuples::cons<mask, Tail>,
210 operator||(boost::tuples::cons<mask, Tail> const& t, mask const& m)
212 namespace bt = boost::tuples;
214 return index::detail::tuples::push_back
216 bt::cons<mask, Tail>,
223 char II1, char IB1, char IE1,
224 char BI1, char BB1, char BE1,
225 char EI1, char EB1, char EE1,
226 char II2, char IB2, char IE2,
227 char BI2, char BB2, char BE2,
228 char EI2, char EB2, char EE2
232 static_mask<II1, IB1, IE1, BI1, BB1, BE1, EI1, EB1, EE1>,
233 static_mask<II2, IB2, IE2, BI2, BB2, BE2, EI2, EB2, EE2>
235 operator||(static_mask<II1, IB1, IE1, BI1, BB1, BE1, EI1, EB1, EE1> const& ,
236 static_mask<II2, IB2, IE2, BI2, BB2, BE2, EI2, EB2, EE2> const& )
238 return boost::mpl::vector
240 static_mask<II1, IB1, IE1, BI1, BB1, BE1, EI1, EB1, EE1>,
241 static_mask<II2, IB2, IE2, BI2, BB2, BE2, EI2, EB2, EE2>
248 char II, char IB, char IE,
249 char BI, char BB, char BE,
250 char EI, char EB, char EE
253 typename detail::de9im::push_back
256 static_mask<II, IB, IE, BI, BB, BE, EI, EB, EE>
258 operator||(Seq const& ,
259 static_mask<II, IB, IE, BI, BB, BE, EI, EB, EE> const& )
261 return typename detail::de9im::push_back
264 static_mask<II, IB, IE, BI, BB, BE, EI, EB, EE>
271 #ifndef DOXYGEN_NO_DETAIL
272 namespace detail { namespace de9im
278 // 1. specialize for simplified masks if available
279 // e.g. for TOUCHES use 1 mask for A/A
280 // 2. Think about dimensions > 2 e.g. should TOUCHES be true
281 // if the interior of the Areal overlaps the boundary of the Volumetric
282 // like it's true for Linear/Areal
285 template <typename Geometry1, typename Geometry2>
286 struct static_mask_equals_type
288 typedef geometry::de9im::static_mask<'T', '*', 'F', '*', '*', 'F', 'F', 'F', '*'> type; // wikipedia
289 //typedef geometry::de9im::static_mask<'T', 'F', 'F', 'F', 'T', 'F', 'F', 'F', 'T'> type; // OGC
293 template <typename Geometry1, typename Geometry2>
294 struct static_mask_disjoint_type
296 typedef geometry::de9im::static_mask<'F', 'F', '*', 'F', 'F', '*', '*', '*', '*'> type;
304 std::size_t Dim1 = geometry::topological_dimension<Geometry1>::value,
305 std::size_t Dim2 = geometry::topological_dimension<Geometry2>::value
307 struct static_mask_touches_impl
309 typedef boost::mpl::vector
311 geometry::de9im::static_mask<'F', 'T', '*', '*', '*', '*', '*', '*', '*'>,
312 geometry::de9im::static_mask<'F', '*', '*', 'T', '*', '*', '*', '*', '*'>,
313 geometry::de9im::static_mask<'F', '*', '*', '*', 'T', '*', '*', '*', '*'>
316 // According to OGC, doesn't apply to P/P
317 // Using the above mask the result would be always false
318 template <typename Geometry1, typename Geometry2>
319 struct static_mask_touches_impl<Geometry1, Geometry2, 0, 0>
321 typedef geometry::detail::relate::false_mask type;
324 template <typename Geometry1, typename Geometry2>
325 struct static_mask_touches_type
326 : static_mask_touches_impl<Geometry1, Geometry2>
330 template <typename Geometry1, typename Geometry2>
331 struct static_mask_within_type
333 typedef geometry::de9im::static_mask<'T', '*', 'F', '*', '*', 'F', '*', '*', '*'> type;
336 // COVERED_BY (non OGC)
337 template <typename Geometry1, typename Geometry2>
338 struct static_mask_covered_by_type
340 typedef boost::mpl::vector
342 geometry::de9im::static_mask<'T', '*', 'F', '*', '*', 'F', '*', '*', '*'>,
343 geometry::de9im::static_mask<'*', 'T', 'F', '*', '*', 'F', '*', '*', '*'>,
344 geometry::de9im::static_mask<'*', '*', 'F', 'T', '*', 'F', '*', '*', '*'>,
345 geometry::de9im::static_mask<'*', '*', 'F', '*', 'T', 'F', '*', '*', '*'>
350 // dim(G1) < dim(G2) - P/L P/A L/A
355 std::size_t Dim1 = geometry::topological_dimension<Geometry1>::value,
356 std::size_t Dim2 = geometry::topological_dimension<Geometry2>::value,
357 bool D1LessD2 = (Dim1 < Dim2)
359 struct static_mask_crosses_impl
361 typedef geometry::de9im::static_mask<'T', '*', 'T', '*', '*', '*', '*', '*', '*'> type;
363 // TODO: I'm not sure if this one below should be available!
364 // dim(G1) > dim(G2) - L/P A/P A/L
367 typename Geometry1, typename Geometry2, std::size_t Dim1, std::size_t Dim2
369 struct static_mask_crosses_impl<Geometry1, Geometry2, Dim1, Dim2, false>
371 typedef geometry::de9im::static_mask<'T', '*', '*', '*', '*', '*', 'T', '*', '*'> type;
373 // dim(G1) == dim(G2) - P/P A/A
376 typename Geometry1, typename Geometry2, std::size_t Dim
378 struct static_mask_crosses_impl<Geometry1, Geometry2, Dim, Dim, false>
380 typedef geometry::detail::relate::false_mask type;
382 // dim(G1) == 1 && dim(G2) == 1 - L/L
383 template <typename Geometry1, typename Geometry2>
384 struct static_mask_crosses_impl<Geometry1, Geometry2, 1, 1, false>
386 typedef geometry::de9im::static_mask<'0', '*', '*', '*', '*', '*', '*', '*', '*'> type;
389 template <typename Geometry1, typename Geometry2>
390 struct static_mask_crosses_type
391 : static_mask_crosses_impl<Geometry1, Geometry2>
396 // dim(G1) != dim(G2) - NOT P/P, L/L, A/A
401 std::size_t Dim1 = geometry::topological_dimension<Geometry1>::value,
402 std::size_t Dim2 = geometry::topological_dimension<Geometry2>::value
404 struct static_mask_overlaps_impl
406 typedef geometry::detail::relate::false_mask type;
408 // dim(G1) == D && dim(G2) == D - P/P A/A
409 template <typename Geometry1, typename Geometry2, std::size_t Dim>
410 struct static_mask_overlaps_impl<Geometry1, Geometry2, Dim, Dim>
412 typedef geometry::de9im::static_mask<'T', '*', 'T', '*', '*', '*', 'T', '*', '*'> type;
414 // dim(G1) == 1 && dim(G2) == 1 - L/L
415 template <typename Geometry1, typename Geometry2>
416 struct static_mask_overlaps_impl<Geometry1, Geometry2, 1, 1>
418 typedef geometry::de9im::static_mask<'1', '*', 'T', '*', '*', '*', 'T', '*', '*'> type;
421 template <typename Geometry1, typename Geometry2>
422 struct static_mask_overlaps_type
423 : static_mask_overlaps_impl<Geometry1, Geometry2>
426 }} // namespace detail::de9im
427 #endif // DOXYGEN_NO_DETAIL
430 }} // namespace boost::geometry
432 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_DE9IM_HPP